从轮廓到cv::Mat

from contours to cv::Mat

本文关键字:Mat cv 轮廓      更新时间:2023-10-16

我有一个基于opencv的轮廓查找程序,现在我正试图使用Harris角点检测器来获取每个已创建轮廓中的角点数量,我的问题是我必须获得轮廓的一个元素

............................
std::vector<std::vector<cv::Point>> contours;
...........................
    for ( int i =0;i <contours.size(); i++){
            if(!contours[i].empty()){
                Harris.detect(cv::Mat(contours[i])); // here crashes the program because the dimensions don't fit ????
                Harris.getCorners(approx,0.4);
            std::cout <<"size n"<< approx.size()<<std::endl; 
            }
        }
.........................

更新

我再次检查了代码,程序在Harris类的这一部分崩溃了:

   void HarrisDetector::detect(const cv::Mat& image) {
        // Harris computation
        cv::cornerHarris(image,cornerStrength,  //  here crashs the program 
            neighbourhood,// neighborhood size
            aperture,     // aperture size
            k);           // Harris parameter
    // internal threshold computation
    double minStrength; // not used
    cv::minMaxLoc(cornerStrength,&minStrength,&maxStrength);
    //local maxima detection
    cv::Mat dilated;  // temporary image
    cv::dilate(cornerStrength,dilated,cv::Mat());
    cv::compare(cornerStrength,dilated,localMax,cv::CMP_EQ);
     }

任何ideaa

您可以在cv::findContours函数中使用method参数进行某种近似,然后使用contours[i].size()来获得多个角点。