Seb*_*itz 8 c++ opencv image contour
在OpenCV中绘制单个轮廓的最佳方法是什么?据我所知,drawContours只能处理多个轮廓.
背景:我想将每个循环的代码更改为a.旧代码:
//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);
}
}
Run Code Online (Sandbox Code Playgroud)
呈现的方式在这个邮件列表是相当难看:
for (vector<Point> contour : contours){
if(iscorrect(contour)){
vector<vector<Point> > con = vector<vector<Point> >(1, contour);
drawContours(img, con, -1, color, 1, 8);
}
}
Run Code Online (Sandbox Code Playgroud)
是否有更简洁的方法来绘制单个轮廓(矢量<Point> Object)?
我有同样的问题,直到现在我找到的更好的方法是:
for (vector<Point> contour : contours){
if(iscorrect(contour)){
drawContours(img, vector<vector<Point> >(1,contour), -1, color, 1, 8);
}
}
Run Code Online (Sandbox Code Playgroud)
这与你的几乎相同,但少了一行.
我的第一个想法是使用,Mat(contour)但它没有用.
如果你找到了更好的方法,可以在这里发布并分享智慧.
使用 OpenCV 3.0 polylines() 更灵活,我们可以这样做,例如:
vector<Point> approx;
polylines(frame, approx, true, color, 1, 8);
Run Code Online (Sandbox Code Playgroud)
在你的循环中,这将是:
for (vector<Point> contour : contours) {
if (iscorrect(contour)) {
polylines(frame, approx, true, color, 1, 8);
}
}
Run Code Online (Sandbox Code Playgroud)
使用绘制轮廓,它并不完全漂亮,但你不需要循环。
std::vector<cv::Point> contour;
std::vector<std::vector<cv::Point> > contourVec;
contourVec.push_back(contour);
cv::drawContours(img,contourVec,0,color,1,8,hierarchy); //Replace i with 0 for index.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16261 次 |
| 最近记录: |