OpenCV支持大量的轮廓、边缘、边界的相关函数,相应的函数有moments、HuMoments、findContours、 drawContours、approxPolyDP、arcLength、boundingRect、contourArea、convexHull、 fitEllipse、fitLine、isContourConvex、minAreaRect、minEnclosingCircle、 mathcShapes、pointPolygonTest。还有一些c版本的针对老版本的数据结构的函数比如cvApproxChains、 cvConvexityDefects。
OpenCV里支持很多边缘提取的办法,可是如何在一幅图像里得到轮廓区域的参数呢,这就需要用到findContours函数,这个函数的原型为:
- //C++:
- void findContours(InputOutputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
- void findContours(InputOutputArray image, OutputArrayOfArrays contours, int mode, int method, Point offset=Point())
输入图像image必须为一个2值单通道图像
contours参数为检测的轮廓数组,每一个轮廓用一个point类型的vector表示