0
我有一個二進制圖像的輪廓,我得到最大的對象,並且我想要選擇這個對象來繪製它。我有這樣的代碼:如何從輪廓中選擇全部?
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
邊界外的一切,我怎麼可以選擇所有出輪廓?
看看我的回答[post](http://stackoverflow.com/questions/10176184/with-opencv-try-to-extract-a-region-of-a-picture-描述逐arrayofarrays/10186535#10186535)。它向您展示瞭如何使用drawContours()在一個蒙版上繪製一個給定的輪廓來掩蓋輪廓。相反,如果您希望忽略輪廓並將其保留在外,只需將遮罩的原始值設置爲正值,然後使用drawContours()將遮罩中輪廓的區域填充爲0.也就是說,將值在鏈接中給出的示例中。 – lightalchemist
謝謝!!!!,它工作我:D,只有顏色的問題,我想塗料灰色,什麼是必須改變? – user3779874
請參閱下面的答案。 – lightalchemist