当前位置:网站首页>29.輪廓發現
29.輪廓發現
2021-11-25 17:03:01 【羅伊卡】
1.輪廓發現(find contour in your image)
- 輪廓發現(find contour)
- 代碼演示
輪廓發現是基於圖像邊緣提取的基礎尋找對象輪廓的方法,所以邊緣提取的閾值選定會影響最終輪廓發現結果
3.API介紹- 在二值圖像上發現輪廓使用API
cv::findContours(
InputOutputArray binImg, // 輸入圖像,非0的像素被看成1,0的像素值保持不變,8-bit
OutputArrayOfArrays contours, // 全部發現的輪廓對象
OutputArray, hierachy // 圖該的拓撲結構,可選,該輪廓發現算法正是基於圖像拓撲結構實現。
int mode, // 輪廓返回的模式,一般返回一個輪廓樹
int method, // 發現方法
Point offset = Point() // 輪廓像素的比特移,默認(0, 0)沒有比特移
)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- cv::findContours之後對發現的輪廓數據進行繪制顯示
drawContours(
InputOutputArray binImg, // 輸出圖像
OutputArrayOfArrays contours, // 全部發現的輪廓對象
Int contourIdx // 輪廓索引號
const Scalar & color, // 繪制時候顏色
int thickness, // 繪制線寬
int lineType , // 線的類型LINE_8
InputArray hierarchy, // 拓撲結構圖
int maxlevel, // 最大層數, 0只繪制當前的,1錶示繪制繪制當前及其內嵌的輪廓
Point offset = Point() // 輪廓比特移,可選
)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
4.演示代碼
大致步驟:
1.輸入圖像轉為灰度圖像cvtColor
2.使用Canny進行邊緣提取,得到二值圖像
3.使用findContours尋找輪廓
4.使用drawContours繪制輪廓
void Demo_Contours( int, void *){
vector < vector < Point >> contours;
vector < Vec4i > hierarchy;
Canny( src, dst, threshold_value, threshold_value * 2, 3, false);
findContours( dst, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMOPLE, POint( 0, 0));
Mat drawImg = Mat::zeros( dst, size(), CV_8UC3);
for( size_t i = 0; i < contours. size(); i ++){
Scalar color = Scalar ( rng. uniform( 0, 255), rng. uniform( 0, 255), rng. uniform( 0, 255))
drawContours( drawImg, contours, i, color, 2, LINE_8, hierarchy, 0, Point( 0, 0));
}
imshow( output_win, drawImg);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
5.舉例做項目時:一定要使用數組,不要用vector,速度會很慢
圖像的拓撲結構
findContours()函數
drawContours()函
版权声明
本文为[羅伊卡]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/11/20211125165934095y.html
边栏推荐
猜你喜欢
随机推荐
- 底层网工、0基础、记性差,学习CCIE/HCIE,到底是啥体验?
- Compréhension approfondie de l'optimisation des performances des serveurs hautement simultanés
- 创业孵化基地的概念
- 远程办公或常态化,“小城房”or“大城床”你会怎么选?
- 如何用LOTO示波器TDR方法测试电线长度?
- 云安全日报211125:红帽Mailman电子邮件软件发现跨站请求伪造漏洞,需要尽快升级
- 腾讯回应“腾讯云数据库泄露”传闻:系谣言
- 腾讯回应“腾讯云数据库泄露”传闻:谣言
- Les salaires de toutes les industries sont - ils publiés et les TI sont - elles les plus rentables?
- 构建“元宇宙”,有哪些3D建模方式?
- 构建“元宇宙”,有哪些3D建模方式?
- Complexité du temps et de l'espace dans le tri des bulles
- 业界评价钻石级!阿里自研高并发核心编程笔记太香了
- 如何用LOTO示波器TDR方法测试电线长度?
- Interviewer: tell me about the commonly used sorting algorithms
- 如何开发出一个成功的移动BI?掌握这五大因素就够了
- autogen.sh could not find libtool
- @Scheduled的使用
- 直播预告|11.27(周六) 观测云 & 思否联合举办的开发者线上沙龙巡演第 3 站来啦
- Autogen.sh could not find libtool
- Azure Virtual Desktop-3-配置Azure文件共享及配置用户配置文件漫游
- 传输层协议介绍
- C# VS生成后事件命令行
- Le métacosme manque le plus de contenu, et l'informatique en nuage peut aider
- 构建“元宇宙”,有哪些3D建模方式?
- WPF 多语言实现
- 掌握这些程序员“潜规则”,少走5年弯路
- 构建“元宇宙”,有哪些3D建模方式?
- 智驾科技MAXIEYE完成3亿元B轮融资!爆款L2官宣即量产
- 矿山无人驾驶公司「路凯智行」获顺为领投Pre-A轮融资
- Extension tecdat | R Language Linear Discriminant Analysis (LDA), Quadratic Discriminant Analysis (qda) and regular Discriminant Analysis (RDA)
- Tungsten fabric SDN - basic use of VMX - connect to physical / external network
- “开放包容”创未来:2021 Google 开发者大会亮点回顾
- 工具分享:DataPie .Net 6版本(通用的数据库导入,导出,数据查询工具)
- 极光笔记丨搭建UMS私有云文件服务器
- 業界評價鑽石級!阿裏自研高並發核心編程筆記太香了
- L'industrie évalue la qualité des diamants! Les notes de programmation de base simultanées d'Ali Self - Research High sont trop parfumées
- 微信ClickHouse实时数仓的最佳实践
- LR审批流程设计,一站式解决办公难题
- Quelles sont les méthodes de modélisation 3D pour construire le "métaunivers"?