Ask Your Question
0

Error in Detecting Card Suit

asked 2012-10-03 01:33:22 -0500

Marco gravatar image

updated 2012-10-03 01:36:45 -0500

Hi guys!

I've been playing with Simple CV for a few days, and I really like it.

I'm following the algorithm on page 236 of Appendix C of the book, about the Toy blocks for shape comparison. I want to use it to detect card suits.

So far, I was able to detect the suits, but I got a few detection errors and I have no idea what to change to make it detect right!!

The code is very simple: it reads from command prompt a test image and returns its suit.

I included in the zip below a link with the source code and my templates. If someone can take a look, it's detecting wrong 2 of the images!! No idea why!

Thanks guys! Marco

Images link:  http://www.oboeh.com/download/suits.zip

import os, sys from SimpleCV import Image, np, MorphologyFeatureExtractor

def myBinaryFunc(input): return input.binarize ().erode ()

try: arg = str (sys.argv [1]) test = Image (arg) # test image except: sys.exit ("Usage: suits.py test.png")

mf = MorphologyFeatureExtractor () mf.setThresholdOperation (myBinaryFunc)

spades = Image ('spades.png') # template diamonds = Image ('diamonds.png') # template hearts = Image ('hearts.png') # template clubs = Image ('clubs.png') # template

patterntest = np.array (mf.extract (test)) spadestest = np.array (mf.extract (spades)) diamondstest = np.array (mf.extract (diamonds)) heartstest = np.array (mf.extract (hearts)) clubs_test = np.array (mf.extract (clubs))

sumspades = np.sum (np.square (abs (spadestest - patterntest))) sumdiamonds = np.sum (np.square (abs (diamondstest - patterntest))) sumhearts = np.sum (np.square (abs (heartstest - patterntest))) sumclubs = np.sum (np.square (abs (clubstest - patterntest)))

list1 = [sumspades, sumdiamonds, sumhearts, sumclubs] list2 = ['Spades', 'Diamonds', 'Hearts', 'Clubs']

print (list2 [list1.index (min (list1))]) # get name from list 2

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-10-03 09:30:27 -0500

kscottz gravatar image

updated 2012-10-03 09:46:55 -0500

I am not going to flat out debug this. I spent about a week working on something similar a two weeks ago. It isn't quite done yet, and requires a data for training but it does suits and ranks. You should take a look at it as it uses a more machine learning based approach. I need to collect more data and do another pass on the data extraction but sooner or later we will release it with SimpleCV. I will post the data set to github downloads page today.

Here is what the output looks like:

http://imgur.com/a/tYYJC

So the cards data should be up here for the code I posted: https://github.com/ingenuitas/SimpleCV/downloads

Getting back to your main problem, I noticed a "bug" in the morphology feature extractor the other day as I was working. Currently it uses the seven Hu moments which vary greatly in terms of the their size. Instead of calculating the distance between your samples and your test values is to compare the log magnitude of the Hu moment. A good way to see this is if you print out your feature vectors. A couple of the components of the Hu moment should be much much greater than the rest and they "eat up" the distance between the smaller components. A better way to compare two Hu moments is like this approach.

Feel free to ask more questions if this doesn't make sense.

edit flag offensive delete link more
0

answered 2012-10-09 01:47:39 -0500

Marco gravatar image

That's awesome! I'll take a look at your code to see how you did the detection! Thanks a lot!

Marco

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-10-03 01:33:22 -0500

Seen: 454 times

Last updated: Oct 09 '12