2017-06-25 8 views
1

私はfindContours()drawContours()メソッドを使用して、私のバイナリイメージの輪郭を探しています。ネストされた輪郭が見つかりません

my output

矩形がぼやけますなどのIさらなる閾値私の画像は、次いで、内側が表示されている場合(外側および内側曲線が左下にマージされる注意):

しかしながら、これは私の出力であります

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の代わりに任意の正の整数を使用できます。

関連する問題