I have some images of butterflies. I've downloaded them from here. A sample is below:

enter image description here

In each image, the most prominent object is the butterfly (with flowers, leaf etc in background). I usually go for contour/edge detection to locate features in image, but in this case these algorithms are not working as I expected.

I want to locate butterfly and bound it with a box, or better, compute its contour. Is there a way to do this automatically using python-opencv or some other tool?


1 Answer 1


The butterflies are really different and the backgrounds as well, then it makes it really difficult. I would try one of these ideas:

  1. Train the Viola & Jones algorithm on your butterflies. It's a cascade of weak classifiers usually used for face detection (algorithm implemented in all the cameras), but it can be trained for other purposed.
  2. The background seems to be pretty different of the butterflies. I would try to apply the thresholding by histereis according to the values of the pixels on the borders. Like that you select all the similar pixels that touch the border, and it will reduced a lot the region of interest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.