I am trying to compare images using OpenCV and Python.
Consider these images:
Both feature an identical pair of shoes, set to a white background. The only difference being that the first has a taller background than the second.
I want to know how to programmatically crop the white backgrounds of both so that I'm left with only the pair of shoes.
I must add that it won't be possible for me to manually crop the backgrounds.
This link worked perfectly for me for a similar problem, although it uses PIL. Note that it will result in a rectangular image, bounded by the top/right/bottom/left-most pixels that are not white. In your case, it should give identical images with the same size.
I am guessing the code could be easily adapted to work with OpenCV functions only.
You requirement in the comment:
The shoes are on a white background. I would like to completely get rid of the border; as in be left with a rectangular box with either a white or a transparent background, having the length and width of the shoes in the picture.
Then my steps to crop the target regions:
Result: