2017-06-25 110 views
1

我使用findContours()drawContours()方法來查找我的二進制圖像中的輪廓。然而,這是我的輸出:找不到嵌套的輪廓

my output

如果我進一步閾我的圖像,如矩形變得模糊,則內是可見的(注意外部和內部曲線在底部合併左):

notice the outer and inner curves are merged at the bottom left

請問您能解釋一下以及如何解決?

以下是我的代碼片段:

void cb_thresh(int,void*) 
{vector< vector<Point> > contours; 

vector<Vec4i> hierarchy; 
threshold(src, thr,threshval, 255,THRESH_BINARY); 
namedWindow("threshold",CV_WINDOW_NORMAL); 
imshow("threshold",thr); 
findContours(thr, contours, hierarchy,CV_RETR_LIST, CV_CHAIN_APPROX_NONE); // Find the contours in the image 

Scalar color(255,255,255); 

for(int i = 0; i< contours.size(); i++) // iterate through each contour 

{ 
drawContours(thr, contours,i, color, CV_FILLED, 8, hierarchy); 
} 
namedWindow("dst",CV_WINDOW_NORMAL); 
imshow("dst",thr); 
} 

做,我已經刪除了輪廓的層次通知。

+0

我曾嘗試改變輪廓提取方法,但在所有4種檢索方法中獲得相同的輸出。 –

+1

你想要的輸出是什麼? – Micka

回答

0

問題是在行drawContours(thr, contours,i, color, CV_FILLED, 8, hierarchy);。傳遞參數CV_FILLED將填充輪廓內的整個區域。因此矩形被填滿了。可以用任何正整數代替CV_FILLED