I've prepared a piece of code in python using OpenCV that extracts the foreground in the image. My program is getting a stream of images and I need to extract the object from those images.
The images include products like shoes, bags or clothing. Most of the images have white background but sometimes I get a grey gradient background as well. I've used thresholding to separate the foreground from the background and extract the object.
But the problem is that even if I assume that the background will be white and set a fixed upper and lower thresholding values, I sometimes get whites in the object and thresholding doesn't render the correct output.
I wanted to know what might be some good approaches in Computer Vision that I can utilize to get the best results here?
You can get this result:
using the canny edge detector, dilation and erosion:
Explanation of the
process
function: