OpenCV findContour给出了奇怪的结果

OpenCV findContour giving weird results

本文关键字:结果 findContour OpenCV      更新时间:2023-10-16

我试图在深度图像上放置一个简单的边界框:

void cropAndResize(const cv::Mat &input, cv::Mat &output) {
    std::vector<std::vector<cv::Point> > contours;
    cv::Rect croppedHand;
    cv::findContours(input, contours,CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);


    int maxCont = -1;
        if (contours.size() != 0) {
            maxCont = 0;
        }
        for (int i = 0; i < contours.size(); i++) {
            int currSize = contours.at(i).size();
            if (contours.at(maxCont).size() < currSize)
                maxCont = i;
        }

        if (maxCont > -1) {
            croppedHand = cv::boundingRect(contours.at(maxCont));
        }
}

boundingRect给了我一个断言失败(points.checkVector(2)>=0&amp;(points.depth()==CV_23F||points.depth()==CV_32S))。

这很奇怪,因为我很确定这个代码以前工作过。所以我检查了contours的内容,结果令人困惑。一些元素是大小为452126096252493236或更大的向量。检查向量,我主要有这样的点{x=??,y=???}。

findCountours有什么问题吗?我使用的是Visual Studio 2013、Windows 8 Pro、OpenCV 2.4.8。

编辑:输入图像为CV_8UC1。

因此,对于其他有此问题的人,我通过返回VS2010来解决它。OpenCV似乎无法跟上当前的技术。