Ask Your Question

inverting the background and object colors

asked 2015-02-27 06:58:50 -0600

begueradj gravatar image

I read in documentation that:

In OpenCV, finding contours is like finding white object from black background. So remember, object to be found should be white and background should be black.

In my case, all the images I am dealing with are colorful but their background is always white. Is there any solution in OpenCV to make the background of these images black and the objects white in order to apply cv2.findCountours() function ?

edit retag flag offensive close merge delete



check this tutorial here

theodore gravatar imagetheodore ( 2015-02-27 07:19:10 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-02-27 20:29:16 -0600

If you provide a sample of the images you have, it'd help me to answer your question.

Do you mean and are you sure that every white pixel represents the background? If the answer is yes, then you can convert every not white pixel to be a white pixel and every white pixel to be a black pixel!

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-02-27 06:58:50 -0600

Seen: 364 times

Last updated: Feb 27 '15