急急急!opencv231 “convexityDefects”: 找不到标识符

夫人的泡泡鱼 2017-04-08 11:05:01
使用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 );
...全文
269 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
夫人的泡泡鱼 2017-04-14
  • 打赏
  • 举报
回复
解决了,这个在2.4版本以后才有的函数,谢谢大家!
Mr_Zhouzl 2017-04-09
  • 打赏
  • 举报
回复
法错误的截图啊
夫人的泡泡鱼 2017-04-08
  • 打赏
  • 举报
回复
大家帮忙啊,拜谢拜谢!

4,242

社区成员

发帖
与我相关
我的任务
社区描述
OpenCV相关技术交流专区
计算机视觉人工智能opencv 技术论坛(原bbs) 广东省·深圳市
社区管理员
  • OpenCV
  • 幻灰龙
  • OpenCV中国团队
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

OpenCV中国团队官方博客:https://blog.csdn.net/opencvchina

试试用AI创作助手写篇文章吧