我有以下代码来绘制最大的轮廓。但似乎我做错了什么。请指教
if(inputImage.data == NULL)
return HandInfo2();
Mat outputImage = Mat::zeros( inputImage.size(), CV_8UC1);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
vector<Point> largestContour;
int largestArea = -1;
findContours( inputImage, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
/// Approximate contours to polygons
vector<vector<Point> > polyContours( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{
approxPolyDP( Mat(contours[i]), polyContours[i], 3, true );
}
for( int i = 0; i < contours.size(); i++ )
{
int area = fabs(contourArea(polyContours[i],false));
if(area > largestArea && area > size)
{
largestArea = area;
largestContour = polyContours[i];
}
}
Scalar color = Scalar( 255 );
if(largestContour.size()>0)
drawContours( outputImage, largestContour, 0, color, 1, 8, vector<Vec4i>(), 0, Point() );
调用 drawContours() 时,出现以下错误
OpenCV 错误:未知函数中的断言失败 (i < 0),文件 ..\..\..\src\opencv\modules\core\src\matrix.cpp,第 957 行
我在这里做错了什么?