如何选择出所有的轮廓
How to select all out of a contour?
我有一个二值图像的轮廓,我得到最大的对象,我想把这个对象全部选中来绘制它。我有这样的代码:
vector<vector<Point> > contours;
findContours( img.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
vector<Rect> boundSheet( contours.size() );
int largest_area=0;
for( int i = 0; i< contours.size(); i++ )
{
double a= contourArea( contours[i],false);
if(a>largest_area){
largest_area=a;
boundSheet[i] = boundingRect(contours[i]);
}
}
我想用drawContours
画出边界外的所有东西,我怎么选择所有的轮廓?
using namespace cv;
int main(void)
{
// 'contours' is the vector of contours returned from findContours
// 'image' is the image you are masking
// Create mask for region within contour
Mat maskInsideContour = Mat::zeros(image.size(), CV_8UC1);
int idxOfContour = 0; // Change to the index of the contour you wish to draw
drawContours(maskInsideContour, contours, idxOfContour,
Scalar(255), CV_FILLED); // This is a OpenCV function
// At this point, maskInsideContour has value of 255 for pixels
// within the contour and value of 0 for those not in contour.
Mat maskedImage = Mat(image.size(), CV_8UC3); // Assuming you have 3 channel image
// Do one of the two following lines:
maskedImage.setTo(Scalar(180, 180, 180)); // Set all pixels to (180, 180, 180)
image.copyTo(maskedImage, maskInsideContour); // Copy pixels within contour to maskedImage.
// Now regions outside the contour in maskedImage is set to (180, 180, 180) and region
// within it is set to the value of the pixels in the contour.
return 0;
}
相关文章:
- 如何使用默认参数等选择模板专业化
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 选择要调用的构造函数
- C++选择排序算法中的逻辑错误
- QTreeView幻灯片多选后无法使用单击选择
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 无法获取菜单选择以运行函数.C++
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- Python中的for循环与C++有何不同
- 在C++中,如何通过几种类型从元组中选择多个元素
- 讨论 - 创建矩阵时的数组与向量的向量 - 什么是最实用的选择
- 对可变参数使用声明.如何选择正确的功能
- 选择选举获胜者的程序
- 如何选择在 csv 文件中输出的位置
- 根据用户回答声明"Players"。用户选择玩家数量。播放器是结构体
- 程序在尝试猜测它选择的随机数时进入无限循环?
- 选择和修改嵌套向量中的条目的最佳实践
- OpenCV:在处理后的图像中选择轮廓
- 使用鼠标选择轮廓
- 如何选择出所有的轮廓