OpenCv凹凸性缺陷

OpenCv Convexity Defects

本文关键字:缺陷 凹凸 OpenCv      更新时间:2023-10-16

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

我已经按照下面的链接,因为它是最类似于我的问题,但仍然没有运气。在c++中使用OpenCV 2.4计算凸性缺陷

我收到下面的错误。

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() );

(每个轮廓/船体各一个)