Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error in Detecting Card Suit

Hi guys!

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

I'm following the algorith 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

Error in Detecting Card Suit

Hi guys!

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

I'm following the algorith 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