OpenCv Convexity缺陷

时间:2013-03-06 04:14:39

标签: c++ opencv

我正在研究一些我在网上找到的使用opencv c ++ 2.4.4创建凸包的例子。我正在研究使用凸性缺陷但是遇到了这些类的c ++实现的问题

我按照下面的链接,因为它与我的问题最相似,但仍然没有运气。 Calculating convexityDefects using OpenCV 2.4 in c++

我收到了以下错误。

openCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0)) in create

此外,我已粘贴下面的当前代码。

感谢您的帮助,

int c = 0;
VideoCapture cap(0);

Mat frame;
Mat edges;
Mat threshold_output;
cv::vector<cv::Vec4i> hierarchy;
std::vector<std::vector<cv::Point> > contours;
RNG rng(12345);

while( c != 27)
{
    cap >> frame;
    cvtColor(frame, edges, CV_BGR2GRAY);

    threshold(edges, threshold_output, 100, 255, CV_THRESH_OTSU );
    findContours( threshold_output, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));

    std::vector<Vec4i> defects;
    vector<cv::vector<int> >hull( contours.size() );

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

1 个答案:

答案 0 :(得分:3)

std::vector<Vec4i> defects;   

应该是

std::vector< std::vector<Vec4i> > defects( contours.size() );

(每个轮廓/船体一个)

相关问题