0

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:

The "good" example: Good Original RGB Image Good dilate image

The "bad" example: Bad original RGB image Bad 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.

ryden
  • 189
  • 6
  • Does this answer your question? [Detecting edges of a card with rounded corners](https://stackoverflow.com/questions/17338488/detecting-edges-of-a-card-with-rounded-corners) – Christoph Rackwitz Jan 15 '23 at 13:37
  • have you varied the various scalar arguments in your code? – Christoph Rackwitz Jan 15 '23 at 13:38
  • @ChristophRackwitz yes, i tried modifying the ```cv2.Canny(blurred, x, y)``` with different ```x``` and ```y``` values, but i haven't found the best values that fits to my whole examples. – ryden Jan 15 '23 at 13:44
  • @ChristophRackwitz the link you sent may be useful, but it's in C++ i need it to be done via python. any ideas? – ryden Jan 15 '23 at 13:45
  • I'm saying there are several blog posts on the internet that showcase simple approaches to locating cards in a picture. it's a common exercise. results heavily depend on quality of input. – Christoph Rackwitz Jan 15 '23 at 13:48

0 Answers0