Ask Your Question
0

Can not show threshold imange after using findcontour function

asked 2016-09-23 04:56:13 -0600

greenworld gravatar image

updated 2020-10-10 13:06:49 -0600

Hi everyone, I want to dislay threshold image to window using imshow function, it worked if I dont use findcontour function (by commenting) Mat imgInContour, imgThresholded; findContours(imgThresholded, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));

After using findContours, a binary image with edge (due to findContours processed) not Threshold Image as my desired, so findContours function changed the imgThresholded variable. Please help me to find a way to show the thresholded image separate with the contours. Thank in advance!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-23 06:10:27 -0600

berak gravatar image

findContours() destroys the image, so you either need to show it before applying findContours(),

or pass a copy :

findContours(imgThresholded.clone(), contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
edit flag offensive delete link more

Comments

Dear berak, Before using findContours, I copy the imgThresholded to another one, used that as an input of findContours and after findContours process, I show the image by the imgThresholded but it seems affected by findCountours process before, can you help to explain ? Thank you!

greenworld gravatar imagegreenworld ( 2016-09-23 08:31:38 -0600 )edit

how do you copy that ? Mat a = b; only does a "shallow" copy.

berak gravatar imageberak ( 2016-09-23 08:52:55 -0600 )edit

Yep, a = b; so I take b to process, and keep a as an original version. Just want to imShow a in windows, because findContours change the input image.

greenworld gravatar imagegreenworld ( 2016-09-23 09:05:59 -0600 )edit

again, "shallow" copy means, that only the Mat header (width,height, etc) gets copied, but the 2 Mat''s share the data pointer (the pixels).

you need Mat a = b.clone(); to achieve a "deep" copy.

berak gravatar imageberak ( 2016-09-23 09:14:19 -0600 )edit

Thank you so much!

greenworld gravatar imagegreenworld ( 2016-09-24 01:31:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-23 04:56:13 -0600

Seen: 171 times

Last updated: Sep 23 '16