【发布时间】:2016-12-21 13:29:58
【问题描述】:
我想为图片中的每个对象找到边界框,找到之后,我将边界框裁剪出来并用于接下来的步骤。Here is the input picture after preprocessing. 我有一个边界框代码,但它只适用于 1 个对象。如果有 2 个对象,则将两者相加并在它们周围绘制一个边界框。 Here is the first output.它的代码是:
vector<vector<Point>> contours;
vector<Point> points;
findContours(erod, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
for (size_t i = 0; i < contours.size(); i++) {
for (size_t j = 0; j < contours[i].size(); j++) {
Point p = contours[i][j];
points.push_back(p);
}
}
if (points.size() > 0) {
Rect brect = boundingRect(Mat(points).reshape(2));
cv::rectangle(erod, brect.tl(), brect.br(), Scalar(100,100,200), 2, CV_AA);
Mat ROI = frame(brect);
}
我尝试的第二件事是使用 OpenCV 文档的代码。在这里,我将 findContours 中的 CV_RETR_TREE 更改为 CV_RETR_EXTERNAL,但我仍然得到许多边界框,我不知道如何裁剪这些框。
非常感谢!
【问题讨论】:
标签: opencv image-segmentation object-detection bounding-box