Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 人脸轮廓检测为具有相同图形的两个轮廓_C++_Opencv - Fatal编程技术网

C++ 人脸轮廓检测为具有相同图形的两个轮廓

C++ 人脸轮廓检测为具有相同图形的两个轮廓,c++,opencv,C++,Opencv,我正在做一个关于人脸检测的项目,到目前为止,我想将人脸检测为一个整体轮廓,但在这里情况并非如此 我有以下资料: std::vector<std::vector<cv::Point>> biggestcontours; Mat canny_output; vector<Vec4i> hierarchy; Rect bounding_rect; /// Detect edges using canny

我正在做一个关于人脸检测的项目,到目前为止,我想将人脸检测为一个整体轮廓,但在这里情况并非如此

我有以下资料:

std::vector<std::vector<cv::Point>> biggestcontours;
Mat canny_output;
        vector<Vec4i> hierarchy;
        Rect bounding_rect;

        /// Detect edges using canny
        Canny(src, canny_output, thresh, thresh * 2, 3);
        /// Find contours
        findContours(canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
for (int i = 0; i < contours.size(); i++)
        {
            approxPolyDP(contours[i], contours_poly[i], 3, true);
            boundRect[i] = boundingRect(contours_poly[i]);
            contour_sizes.push_back(contours[i].size());
            drawContours(drawing_all, contours, i, Scalar(255, 255, 255));
        }
std::sort(contour_sizes.begin(), contour_sizes.end());

        for (int i = 0; i < contours.size(); i++)
        {
            if (contours[i].size() == contour_sizes[contour_sizes.size() - 1] || contours[i].size() == contour_sizes[contour_sizes.size() - 2]
                || contours[i].size() == contour_sizes[contour_sizes.size() - 3])
            {
                if (contours[i].size() < 300) continue;
                biggestcontours.push_back(contours[i]);
                rectangles.push_back(boundRect[i]);
                drawContours(drawing_biggest_3, contours, i, Scalar(255, 255, 255));
                rectangle(drawing_biggest_3, boundRect[i].tl(), boundRect[i].br(), Scalar(150, 100, 255), 2);
            }
        }
nbcontours = biggestcontours.size();
        stringstream ss;
        ss << nbcontours;
        string str = ss.str();
        putText(drawing_biggest_3, str, cv::Point(30, 30),
            FONT_HERSHEY_COMPLEX_SMALL, 0.8, Scalar(200, 200, 250), 1, cv::LINE_AA);
std::向量等高线;
Mat-canny_输出;
向量层次;
矩形边界;
///使用canny算法检测边缘
Canny(src,Canny_输出,thresh,thresh*2,3);
///寻找轮廓
findContours(canny_输出、轮廓、层次、检索树、链近似、简单);
对于(int i=0;i这是因为您使用的检索模式。您选择了
RETR\u TREE
模式来查找轮廓。正如政府所说:

CV_RETR_树检索所有轮廓并重建完整轮廓 嵌套等高线的层次结构

它可以同时找到内部和外部轮廓,这就是为什么它可以检测到2个轮廓。在您的情况下,最好使用
RETR\u EXTERNAL
模式:

CV_RETR_EXTERNAL仅检索最外层轮廓