在 OpenCV 中绘制单个轮廓的最佳方法是什么?据我所知drawContours只能处理多个轮廓。
背景:我想将我的代码更改为 for each 循环。旧代码:
//vector<vector<Point> > contours = result of findContours(...)
for (int i = 0; i < contour.size; i++){
if(iscorrect(contours[i])){
drawContours(img, contours, i, color, 1, 8, hierarchy);
}
}
呈现方式in this mailing list非常丑陋:
for (vector<Point> contour : contours){
if(iscorrect(contour)){
vector<vector<Point> > con = vector<vector<Point> >(1, contour);
drawContours(img, con, -1, color, 1, 8);
}
}
有没有更简洁的方法来绘制单个轮廓(vector
最佳答案
我有同样的问题,到目前为止我发现的更好的方法是:
for (vector<Point> contour : contours){
if(iscorrect(contour)){
drawContours(img, vector<vector<Point> >(1,contour), -1, color, 1, 8);
}
}
这与您的几乎相同,但少了一行。
我的第一个想法是使用 Mat(contour)
但它没有用。
如果您找到更好的方法,请在此处发布并分享智慧。
关于c++ - 在图像上的 OpenCV 中绘制单个轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21887000/