c语言通过opencv实现轮廓处理与切割

2025-05-27 0 26

c语言通过opencv实现轮廓处理与切割

注意在寻找轮廓时要选择中寻找外层轮廓

?

1
RETR_EXTERNAL

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34
#include "opencv/cv.h"

#include "opencv/highgui.h"

using namespace std;

using namespace cv;

int main()

{

Mat srcimg=imread("./22.jpg");

Mat dst;

cvtColor(srcimg,dst,CV_BGR2GRAY);

threshold(dst,dst,120,255,1);

vector<vector<Point> > edgepoint;

vector<Vec4i> lclass;

findContours(dst,edgepoint,lclass,RETR_EXTERNAL,CHAIN_APPROX_NONE,Point());

Mat mat[edgepoint.size()];

for(int i=0;i<edgepoint.size();i++)

{

Rect rec=boundingRect(Mat(edgepoint[i]));

mat[i]=dst(rec);

rectangle(dst,rec,Scalar(100,80,90),1,1,0);

drawContours(dst,edgepoint,i,Scalar(200),1,8,lclass);

string str=to_string(i);

imshow(str,mat[i]);

}

imshow("tt",dst);

cout<<edgepoint.size()<<endl;

waitKey(0);

}

结果如下:

c语言通过opencv实现轮廓处理与切割

总结

以上就是本文关于c语言通过opencv实现轮廓处理与切割的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 c语言通过opencv实现轮廓处理与切割 https://www.kuaiidc.com/73048.html

相关文章

发表评论
暂无评论