So as a first step in my project, i need to recieve an image and detect all the game cards in it. I work with openCV in Python and it worked pretty well, but only on some of my samples :\
I know that given an image, i need to proccess it a little bit in order to make it easier for the computer to detect the cards, threshold to binary image and then find contours. Problem is that in each image the proccessing step may be different and i still can't find the "ultimate" way of doing that.
Here is how i find contours:
image = cv2.imread( <IMAGE_PATH> )
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3, 3), 0)
edged = cv2.Canny(blurred, 10, 250)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
dilate = cv2.dilate(edged, kernel, iterations=2)
contours, _ = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
in my first sample (the good one), here are the results of the 'dilate' image:
As you can you, in the "bad" example, the card's contours looks torn, acyclic. So the cv2.findContours
fails to find them all correctly.
Any ideas? The cards in the "bad" rgb image look pretty noticeable for a human eye, so i gotta believe that there's a pretty simple way of making it noticeable for the computer.