急急急!opencv231 “convexityDefects”: 找不到标识符
使用openCV231+VS2010,在控制台下开发,想用convexityDefects检测手部凸包特征,可提示找不到标识符,这怎么办啊,急死了!请大家给帮帮忙。我的opencv是在工程里配置的,其他的编译opencv函数使用都正确。代码如下:
vector<vector<cv::Point>> contours ;
vector<Vec4i> hierarchy;
// cv::findContours(retImage,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE);
/// Find contours
findContours( retImage, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
/// Find the convex hull object for each contour
vector<vector<Point> >hull( contours.size() );
// Int type hull
vector<vector<int>> hullsI( contours.size() );
// Convexity defects
vector<vector<Vec4i>> defects( contours.size() );
for( size_t i = 0; i < contours.size(); i++ )
{
convexHull( Mat(contours[i]), hull[i], false );
// find int type hull
convexHull( Mat(contours[i]), hullsI[i], false );
// get convexity defects
// convexityDefects(Mat(contours[i]),hullsI[i], defects[i]);
}
RNG rng(12345);
/// Draw contours + hull results
Mat drawing = Mat::zeros( drawing.size(), CV_8UC3 );
for( size_t i = 0; i< contours.size(); i++ )
{
vector<Point>& c=contours[i];
double area = contourArea( c );
if( area< 30 )
{ continue; } //filter remaining noise
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
drawContours( drawing, contours, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
drawContours( drawing, hull, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
// draw defects
size_t count = contours[i].size();
std::cout<<"Count : "<<count<<std::endl;
if( count < 300 )
continue;
vector<Vec4i>::iterator d =defects[i].begin();
while( d!=defects[i].end() ) {
Vec4i& v=(*d);
//if(IndexOfBiggestContour == i)
{
int startidx=v[0];
Point ptStart( contours[i][startidx] ); // point of the contour where the defect begins
int endidx=v[1];
Point ptEnd( contours[i][endidx] ); // point of the contour where the defect ends
int faridx=v[2];
Point ptFar( contours[i][faridx] );// the farthest from the convex hull point within the defect
int depth = v[3] / 256; // distance between the farthest point and the convex hull
if(depth > 20 && depth < 80)
{
line( drawing, ptStart, ptFar, CV_RGB(0,255,0), 2 );
line( drawing, ptEnd, ptFar, CV_RGB(0,255,0), 2 );
circle( drawing, ptStart, 4, Scalar(255,0,100), 2 );
circle( drawing, ptEnd, 4, Scalar(255,0,100), 2 );
circle( drawing, ptFar, 4, Scalar(100,0,255), 2 );
}
printf("start(%d,%d) end(%d,%d), far(%d,%d)\n",ptStart.x, ptStart.y, ptEnd.x, ptEnd.y, ptFar.x, ptFar.y);
}
d++;
}
}
/// Show in a window
namedWindow( "Hull demo", CV_WINDOW_AUTOSIZE );
imshow( "Hull demo", drawing );