c++ - OpenCv 凸性缺陷

标签 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]);
        }
    }
}

最佳答案

std::vector<Vec4i> defects;   

应该是

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

(每个轮廓/船体一个)

关于c++ - OpenCv 凸性缺陷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15238862/

相关文章:

c++ - binutils和gcc有什么关系?

c++ - 添加调试输出时循环结果不同(Heisenbug?)

c++ - opencv中自适应阈值和正常阈值之间的区别

opencv - 无法从树莓派上的相机捕获帧

c++ - 如何定义和平滑 3D cv::Mat

c++ - 如何更改禁用按钮的外观和编辑控件?

c++ - 当试图生成指向带有 decltype 的重载函数的函数指针时,为什么无法指定适当的重载?

c++ - C++提取和计数文本文件中的单词数

c++ - OpenCV、Dlib - Mat 对象输出为黑色图像

opencv - 如何在OpenCvSharp中从InputOutputArray创建对象?