2013-03-06 119 views
2

我正在通過一些我已經在網上找到的例子來使用opencv C++ 2.4.4創建凸包。我正在研究使用凸性缺陷,但遇到這些類的C++實現問題OpenCv凸性缺陷

我已經按照下面的鏈接,因爲它是最類似於我的問題,但仍然沒有運氣。 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]); 
     } 
    } 
} 

回答

3
std::vector<Vec4i> defects; 

應該

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

(每個輪廓/船體)

+1

哦男人對不起,我知道我應該來在發佈之前用新鮮的眼睛回到這一點。感謝您的高舉。 – user1874538 2013-03-08 12:54:49