我正在尝试从以下代码获取Convexity缺陷,但继续得到未处理的异常。 我做错了什么?
vector<Vec4i> defects;
ContourPoly = vector<Point>(contour.size());
approxPolyDP( Mat(contour), ContourPoly,20, false );
convexHull(Mat(ContourPoly), HullPoints, false, true);
// The following line wont work
convexityDefects(Mat(ContourPoly),HullPoints,defects);
虽然HullPoints的类型为vector<Point>
例外情况如下
OpenCV Error: Assertion Failed (ptnum >3) is unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1969
但vector<Point> defects;
或vector<Vec4i> defects
我得到以下异常
OpenCV Error: Assertion Failed (hull.checkVector(1,CV_32S) is unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1971
答案 0 :(得分:0)
defects
应为vector<Vec4i>
来自文档:
每个凸性缺陷表示为4元素整数向量(又名
cv::Vec4i
):(start_index, end_index, farthest_pt_index, fixpt_depth)
,其中索引是凸起缺陷开始,结束和最远的原始轮廓中基于0的索引点,fixpt_depth
是最远轮廓点和船体之间距离的定点近似(具有8个小数位)。也就是说,获取深度的浮点值将为fixpt_depth/256.0
答案 1 :(得分:0)
首先
vector<vector<Vec4i> > defects;
应该是:
vector<vector<Vec4i> > defects( contour.size() );
此外,在调用convexityDefects
函数之前,请检查HullPoints
的大小是否大于3.