OpenCV:图像轮廓

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/mars_xiaolei/article/details/91417741

查找轮廓的基本流程 

查找和绘制轮廓

查找轮廓函数原型1:

void findContours( InputOutputArray image, OutputArrayOfArrays contours,
                              OutputArray hierarchy, int mode,
                              int method, Point offset = Point());

查找轮廓函数原型2:

void findContours( InputOutputArray image, OutputArrayOfArrays contours,
                              int mode, int method, Point offset = Point());

 绘制轮廓函数原型:

void drawContours( InputOutputArray image, InputArrayOfArrays contours,
                              int contourIdx, const Scalar& color,
                              int thickness = 1, int lineType = LINE_8,
                              InputArray hierarchy = noArray(),
                              int maxLevel = INT_MAX, Point offset = Point() );

轮廓矩

Moments类构造函数:

Moments(double m00, double m10, double m01, double m20, double m11,
            double m02, double m30, double m21, double m12, double m03 );

moments函数原型:获取轮廓矩 

Moments moments( InputArray array, bool binaryImage = false );

重心点

body_mc = cv::Point(static_cast<int>(body_mu.m10 / body_mu.m00), static_cast<int>(body_mu.m01 / body_mu.m00));

轮廓的面积

contourArea函数原型:获取轮廓面积

double contourArea( InputArray contour, bool oriented = false );

轮廓周长

arcLength函数原型:获取轮廓周长

double arcLength( InputArray curve, bool closed );

最小(up-right)正矩形边界

计算并返回指定点集的最小(up-right)矩形边界

Rect boundingRect( InputArray points );

最小包围旋转矩形

RotatedRect minAreaRect( InputArray points );

最小包围圆

void minEnclosingCircle( InputArray points,
                                      CV_OUT Point2f& center, CV_OUT float& radius );

用椭圆拟合二维点集

RotatedRect fitEllipse( InputArray points );

包围三角形

double cv::minEnclosingTriangle(InputArray points,
OutputArray triangle 
);

包围多边形

void approxPolyDP( InputArray curve,
                                OutputArray approxCurve,
                                double epsilon, bool closed );

判断点是否在轮廓

double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist );

凸包和凸缺陷

convexHull函数功能:查找包围点集的凸包,convexHull函数使用Sklansky算法[169]找到2D点集的凸包,该算法在当前实现中具有O(N logN)复杂度。

void convexHull( InputArray points, 
OutputArray hull,
bool clockwise = false, 
bool returnPoints = true 
);
  • points:2D点集,存储在std :: vector或Mat中。
  • hull :hull 是整数向量或点向量,在第一种情况下,hull是凸包从0开始的索引(因为凸包点集是原始点集的子集),用于查找凸缺陷,在第二种情况下,hull本身就是凸包,用于查找凸包。
  • clockwise:如果clockwise=true,则按顺时针方向输出凸包;否则,按逆时针方向输出凸包。假定坐标系的X轴指向右侧,Y轴指向上方。
  • returnPoints:操作标志,在矩阵的情况下,当returnPoints=true时,该函数返回凸包外壳点;否则,它返回凸包点的索引。当输出数组是std :: vector时,标志被忽略,输出取决于向量的类型:std :: vector <int>表示returnPoints = false,std :: vector <Point>表示returnPoints = true。

 convexityDefects函数功能:查找轮廓的凸缺陷 

void convexityDefects( InputArray contour, InputArray convexhull, OutputArray convexityDefects );
  • contour:输入的轮廓。
  • convexHull:凸包索引,int类型向量。
  • convexityDefects:凸缺陷的输出向量。 在C ++和新的Python / Java接口中,每个凸性缺陷表示为4元素整数向量(又名Vec4i):( start_index,end_index,farthest_pt_index,fixpt_depth),其中索引是凸缺陷的原始轮廓中的基于0的索引开始,结束和最远点,fixpt_depth是最远轮廓点和凸包之间距离的定点近似(具有8个小数位),也就是说,获取深度的浮点值将是fixpt_depth / 256.0。 

查找两个旋转矩形是否有交点

int cv::rotatedRectangleIntersection(const RotatedRect & rect1,
const RotatedRect & rect2,
OutputArray intersectingRegion 
);

 

展开阅读全文

图像轮廓计算

05-27

<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;">基于</span><span style="color:#424242;">OpenCV</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">最新版本</span><span style="color:#424242;">OpenCV4</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">开始,从基础开始,详解</span><span style="color:#424242;">OpenCV</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">核心模块</span><span style="color:#424242;">Core</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">、</span><span style="color:#424242;">Imgproc</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">、</span><span style="color:#424242;">video analysis</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">核心</span><span style="color:#424242;">API</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">与相关知识点,讲解从图像组成,像素操作开始,一步一步教你如何写代码,如何用</span><span style="color:#424242;">API</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">解决实际问题,从图像处理到视频分析,涵盖了计算机视觉与</span><span style="color:#424242;">OpenCV4</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">中主要模块的相关知识点,穿插大量工程编程技巧与知识点与案例,全部课程的</span><span style="color:#424242;">PPT</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">课件与源码均可以下载。部分课程内容运行截图:</span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270151327319.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270151199926.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270143028023.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270143153426.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270143373800.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270143508281.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270147189339.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270147595785.png" alt="" /><br /></span>n</p>

图像轮廓发现

05-27

<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;">基于</span><span style="color:#424242;">OpenCV</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">最新版本</span><span style="color:#424242;">OpenCV4</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">开始,从基础开始,详解</span><span style="color:#424242;">OpenCV</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">核心模块</span><span style="color:#424242;">Core</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">、</span><span style="color:#424242;">Imgproc</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">、</span><span style="color:#424242;">video analysis</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">核心</span><span style="color:#424242;">API</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">与相关知识点,讲解从图像组成,像素操作开始,一步一步教你如何写代码,如何用</span><span style="color:#424242;">API</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">解决实际问题,从图像处理到视频分析,涵盖了计算机视觉与</span><span style="color:#424242;">OpenCV4</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">中主要模块的相关知识点,穿插大量工程编程技巧与知识点与案例,全部课程的</span><span style="color:#424242;">PPT</span><span style="color:#424242;font-size:14px;background-color:#FFFFFF;">课件与源码均可以下载。部分课程内容运行截图:</span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270151327319.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270151199926.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270143028023.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270143153426.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270143373800.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270143508281.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270147189339.png" alt="" /><br /></span>n</p>n<p>n <span style="color:#424242;font-size:14px;background-color:#FFFFFF;"><img src="https://img-bss.csdn.net/201905270147595785.png" alt="" /><br /></span>n</p>

没有更多推荐了,返回首页