C++ 从等高线到cv::Mat

C++ 从等高线到cv::Mat,c++,opencv,C++,Opencv,我有一个基于opencv的轮廓查找程序,现在我正试图使用Harris角点检测器获取每个创建轮廓中的角点数量,我的问题是我必须获取轮廓的一个元素 ............................ std::vector<std::vector<cv::Point>> contours; ........................... for ( int i =0;i <contours.size(); i++){ if(

我有一个基于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; 
            }
        }
.........................

任何ideaa

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

您遇到的问题是,Harris corners对图片有效,而不是简单的Mat!但是用等高线做垫子[i]你的图片不完整,这导致了错误。@Khashayar谢谢你的评论,看看问题的更新。正如我所说的,用cornerHarris是不可能找到等高线的角的!检查这里的拐角Harris示例,告诉我您是否需要查找等高线拐角,因为有更好的方法!我已经使用了cv::findContours方法来获取等高线。我不想处理其中的每个点向量,所以每个向量都必须是cv::Mat类型
   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);
     }