【问题标题】:OpenCV C++ cv::convexityDefects errorOpenCV C++ cv::convexityDefects 错误
【发布时间】:2012-08-04 03:50:43
【问题描述】:
vector<Point> hull;
vector<Point> defects;
convexHull(Mat(largest),hull,false);
convexityDefects(largest,hull,defects);

*最大的是我在图片中最大的轮廓

但是,convexityDefects 给了我这个错误“断言失败 (hull.checkVector(1, CV_32S) > 2)”。有人请帮助我,我不想求助于使用 C 解决方案。

已编辑

vector<int> hull;
vector<Point> defects;
convexHull(Mat(largest),hull,false);

vector<vector<int>> testhull;
testhull.push_back(hull);
convexityDefects(largest,testhull,defects);

我尝试使用 vector&lt;vector&lt;int&gt;&gt; 类型将其传递给 convexityDefects 但convexityDefects 仍然给我错误“断言失败(ptnum > 3)..”。

【问题讨论】:

    标签: c++ opencv convex-hull


    【解决方案1】:

    对于船体,你应该使用这样的向量:

    vector<vector<Point>> hullsP( contours.size() );
    vector<vector<int> > hullsI(contours.size());
    

    并将“int”类型传递给 covexityDefects。像这样:

    vector<vector<Vec4i>> convdefect(contours.size());
    
    for( int i = 0; i < contours.size(); i++ )
    { 
        convexHull( Mat(contours[i]), hullsP[i], false );
        convexHull( Mat(contours[i]), hullsI[i], false );       
        if(hullsI[i].size() > 3 )
            convexityDefects(contours[i],hullsI[i],convdefect[i]);
    }
    

    【讨论】:

      【解决方案2】:

      convexityDefects 的第二个参数必须是 vector&lt;vector&lt;int&gt; 的类型,而你的类型是 vector&lt;Point&gt;

      【讨论】:

      • 我对我的代码做了一些更改,请在第一篇文章中再次检查。谢谢。
      • @user1434759 我很快就用谷歌搜索了你所有问题的答案。问之前你试过谷歌吗? stackoverflow.com/questions/10620981/…
      猜你喜欢
      • 2012-11-23
      • 2020-04-24
      • 2021-09-26
      • 2012-01-21
      • 2012-12-15
      • 1970-01-01
      • 2018-05-15
      • 2012-11-12
      • 1970-01-01
      相关资源
      最近更新 更多