【问题标题】:C++ OpenCv error in function ConvexityDefects函数 ConvexityDefects 中的 C++ OpenCv 错误
【发布时间】:2012-11-23 10:23:37
【问题描述】:

我已经阅读了herehere 的帖子,但它们并没有解决我遇到的错误。

我的代码

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

根据上面的帖子,这应该有效,但事实并非如此。我仍然收到错误
error: (-215) hull.checkVector(1, CV_32S) &gt; 2 in function convexityDefects
我真的看不出这里有什么问题。

【问题讨论】:

    标签: c++ opencv convex-hull


    【解决方案1】:

    好的,问题主要是由于一些奇怪的原因,我的轮廓非常小,以至于船体只是一条直线(意思是只包含 2 个点)。 所以错误是指船体矢量的大小,而不是在其他似乎与矢量类型有关的帖子中。

    所以,只需替换
    if(contours[i].size() &gt; 3 )if(hulls[i].size() &gt; 2 ) 工作正常。

    【讨论】:

      【解决方案2】:

      opencv references报道:

      ConvexityDefects(contour, convexhull, storage) → convexity_defects
        Finds the convexity defects of a contour.
      
      Parameters: 
        contour (CvArr or CvSeq) – Input contour
        convexhull (CvSeq) – Convex hull obtained using ConvexHull2 that should contain pointers or indices to the contour points, not the hull points themselves (the return_points parameter in ConvexHull2 should be 0)
        storage (CvMemStorage) – Container for the output sequence of convexity defects. If it is NULL, the contour or hull (in that order) storage is used
      

      特别看一下第二个参数:你确定是用ConvexHull2获得的吗?

      【讨论】:

      • 嗨,我没有使用 OpenCV 2.1,我使用的是 2.4。根据opencv references,我应该使用并且正在使用文档中提到的带有参数“returnPoints = false”的convexHull算法
      • 您是否尝试删除 if 语句?
      猜你喜欢
      • 2012-08-04
      • 2012-12-15
      • 2013-10-24
      • 2016-06-25
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      相关资源
      最近更新 更多