網(wǎng)站首頁 編程語言 正文
功能演示
實(shí)現(xiàn)模板:
1.檢測這板件面的凹坑 ,并把這些凹坑繪制出來
2.界面上可以選擇,標(biāo)注面積大于指定值 的凹坑
測試圖像
面積小于10個(gè)像素凹坑標(biāo)注
面積小于40個(gè)像素凹坑標(biāo)注
提示:以下是本篇文章正文內(nèi)容,下面案例可供參考
一、編程環(huán)境
C#2015+opencvsharp4.0
二、使用步驟
1.程序邏輯
1.先將圖像高斯雙邊濾波 ;
代碼如下(示例):
Cv2.BilateralFilter(imageorg, gs, 0, 20, 5); //高斯雙邊模糊
//imageorg為源圖 Mat;
//gs是濾波后 Mat;
高斯雙邊濾波后的圖像
2.圖像轉(zhuǎn)二值圖像
//先轉(zhuǎn)灰度圖像
Cv2.CvtColor(gs, image_gray,ColorConversionCodes.RGB2GRAY);
//在轉(zhuǎn)二值圖像
Cv2.Threshold(image_gray, bin, 100, 255, ThresholdTypes.BinaryInv);
二值圖像
3.二值圖像輪廓發(fā)現(xiàn)
//發(fā)現(xiàn)輪廓
OpenCvSharp.Point[][] contours2;
HierarchyIndex[] hierarchy2;
Cv2.FindContours(bin, out contours2, out hierarchy2, RetrievalModes.External, ContourApproximationModes.ApproxNone);
4.根據(jù)界面的設(shè)置,繪制符合標(biāo)準(zhǔn)的輪廓
//繪制輪廓
for (int i = 0; i < contours2.Length; i++)
{
double size = Cv2.ArcLength(contours2[i], true);
if(size > Double.Parse(textBox1.Text))
Cv2.DrawContours(imageorg, contours2,i, new Scalar(0, 0, 255), 3);
}
5.顯示最終圖像
//顯示
Bitmap bitmap = BitmapConverter.ToBitmap(gs);
pictureBox1.Image = bitmap;
Cv2.ImWrite("12.jpg", imageorg);
三 、完整代碼演示
private void button6_Click(object sender, EventArgs e)
{
Mat imageorg = Cv2.ImRead("E:\\CS學(xué)習(xí)\\opencvsharp2\\opencvsharp2\\data9.jpg");
Mat image_gray = new Mat();
Mat gs = new Mat();
Mat bin=new Mat();
Cv2.BilateralFilter(imageorg, gs, 0, 20, 5); //高斯雙邊模糊
//圖紙轉(zhuǎn)換
Cv2.CvtColor(gs, image_gray,ColorConversionCodes.RGB2GRAY);
Cv2.Threshold(image_gray, bin, 100, 255, ThresholdTypes.BinaryInv);
//發(fā)現(xiàn)輪廓
OpenCvSharp.Point[][] contours2;
HierarchyIndex[] hierarchy2;
Cv2.FindContours(bin, out contours2, out hierarchy2, RetrievalModes.External, ContourApproximationModes.ApproxNone);
//繪制指定輪廓
for (int i = 0; i < contours2.Length; i++)
{
double size = Cv2.ArcLength(contours2[i], true);
if(size > Double.Parse(textBox1.Text))
Cv2.DrawContours(imageorg, contours2,i, new Scalar(0, 0, 255), 3);
}
//顯示
Bitmap bitmap = BitmapConverter.ToBitmap(imageorg);
pictureBox1.Image = bitmap;
Cv2.ImWrite("12.jpg", bin);
}
原文鏈接:https://blog.csdn.net/qq_42756257/article/details/121884255
相關(guān)推薦
- 2022-04-15 利用Python實(shí)現(xiàn)數(shù)值積分的方法_python
- 2023-11-24 局部路由守衛(wèi)component守衛(wèi)
- 2022-07-18 Linux文件權(quán)限
- 2022-11-03 python回歸分析邏輯斯蒂模型之多分類任務(wù)詳解_python
- 2022-06-08 如何在springboot中使用Thymeleaf
- 2022-06-15 C#實(shí)現(xiàn)希爾排序_C#教程
- 2022-01-22 Redis學(xué)習(xí)之旅--與SpringBoot的結(jié)合
- 2022-04-25 C#使用NPOI實(shí)現(xiàn)Excel和DataTable的互轉(zhuǎn)_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支