【问题标题】:OpenCv Convexity DefectsOpenCv 凸缺陷
【发布时间】:2013-02-20 17:50:04
【问题描述】:

我正在研究我在网上找到的一些示例,以使用 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]);
        }
    }
}

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:
    std::vector<Vec4i> defects;   
    

    应该是

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

    (每个轮廓/船体一个)

    【讨论】:

    • 哦,对不起,我知道我应该在发帖之前以全新的眼光回到这个问题上。感谢您的提醒。
    猜你喜欢
    • 2011-10-12
    • 1970-01-01
    • 2012-06-13
    • 2015-09-29
    • 2012-10-10
    • 1970-01-01
    • 2012-01-05
    • 2019-02-28
    • 2013-09-03
    相关资源
    最近更新 更多