在opencv3.0 c++中擦除boundRect

Erase a boundRect in opencv 3.0 C++

本文关键字:擦除 boundRect c++ opencv3      更新时间:2023-10-16

我在使用contourns图像中找到一个对象。我在boundRects中附上了可能的候选人,以查看最终结果,我想删除高度>宽度的决赛矩形(将其括在黑色圆圈中)。有什么建议吗?谢谢你的帮助和回应。我的代码是:

enter vector<vector<Point> > contours_poly(contours.size());
            vector<Rect> boundRect(contours.size());
            for (size_t i = 0; i < contours.size(); i++)
            {
                approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
                boundRect[i] = boundingRect(Mat(contours_poly[i]));
            }
             for (int i = 0; i < contours.size(); i++)
            {
                Scalar color = Scalar(255, 0, 255);
                rectangle(result_white, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0);
                rectangle(imageLoad, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0);
            }
            imshow("white final", imageLoad);

,最终结果为:最终的图像

为什么要删除它们?

如果不符合您的要求,请不要将它们附加到矩形向量(使用push_back for vector)。