geaxgx / playing-card-detection Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
@geaxgx - first off, thanks for sharing this great work on building a dataset. It's really the key to a good model.
I have a trained model that detects suit and rank with excellent accuracy. Here is a sample image:
https://s3.amazonaws.com/chris-misc/predictions.jpg
After seeing this image I realize that when I create an application to determine the cards in a black jack hand the application may not know if I have two 9's - each card having one corner obscured, or if I have a single 9 with both corners visible.
Is it possible to use some type of instance segmentation with Yolo or is this an instance where I train multiple models, one to extract the entire card and a second to extract the suit and rank?
TIA
Dear Geaxgx,
When generating the 3 card scene I get the error: ValueError: could not broadcast input array from shape (726,500,4) into shape (0,250,4)
However the 2 card scene is working just fine and I was able to make my own 1 card scene using similar code to yours. I noticed that you said in the comments that the decal values have to be different for the 3 card scene. What do I need to change in order to make the 3 card scene work?
specifically the error occurs with this line of code:
self.img3[decalY3:decalY3 + cardH, decalX3:decalX3 + cardW, :] = img3
img3 shape = 726,500,4
self.img3[decalY3:decalY3 + cardH, decalX3:decalX3 + cardW, :] shape = 0,250,4
Should I try to resize img3 to make this work?
Thank you
Hi, i was wondering that i wanted to generate a scene with just the card, without the hulls and my bounding box encloses the card. I have been trying to modify your code to do this but always run into errors. Could you take a look and advise what i am doing wrong. My code is:
`
# Scenario with 1 card:
# The original image of a cover has the shape (cardH,cardW,4)
# We first paste it in a zero image of shape (imgH,imgW,4) at position decalX, decalY
# so that the original image is centerd in the zero image
decalX=int((imgW-cardW)/2)
decalY=int((imgH-cardH)/2)
# imgaug keypoints of the bounding box of a whole card
def card_to_kps(decalX=decalX, decalY=decalY):
kps = ia.KeypointsOnImage([ia.Keypoint(x=decalX,y=decalY),
ia.Keypoint(x=decalX+length,y=decalY),
ia.Keypoint(x=decalX+length,y=decalY+breadth),
ia.Keypoint(x=decalX,y=decalY+breadth)], shape=(imgH,imgW,3))
return kps
def kps_to_polygon(kps):
#Convert imgaug keypoints to shapely polygon
pts=[(kp.x,kp.y) for kp in kps]
return Polygon(pts)
def kps_to_BB(kps):
"""
Determine imgaug bounding box from imgaug keypoints
"""
extend=3 # To make the bounding box a little bit bigger
kpsx=[kp.x for kp in kps.keypoints]
minx=max(0,int(min(kpsx)-extend))
maxx=min(imgW,int(max(kpsx)+extend))
kpsy=[kp.y for kp in kps.keypoints]
miny=max(0,int(min(kpsy)-extend))
maxy=min(imgH,int(max(kpsy)+extend))
if minx==maxx or miny==maxy:
return None
else:
return ia.BoundingBox(x1=minx,y1=miny,x2=maxx,y2=maxy
# imgaug transformation for card
transform_1card = iaa.Sequential([
iaa.Affine(scale=[0.65,1]),
iaa.Affine(rotate=(-180,180)),
iaa.Affine(translate_percent={"x":(-0.25,0.25),"y":(-0.25,0.25)}),
])
# imgaug transformation for the background
scaleBg=iaa.Resize({"height": imgH, "width": imgW})
def augment(img,list_kps,seq, restart=True):
"""
Apply augmentation 'seq' to image 'img' and keypoints 'list_kps'
If restart is False, the augmentation has been made deterministic outside the function
"""
# Make sequence deterministic
while True:
if restart:
myseq=seq.to_deterministic()
else:
myseq=seq
# Augment image, keypoints and bbs
img_aug = myseq.augment_images([img])[0]
list_kps_aug = [myseq.augment_keypoints([kp])[0] for kp in list_kps]
list_bbs = [kps_to_BB(list_kps_aug[1]),kps_to_BB(list_kps_aug[2])]
valid=True
# Check the cover bounding box stays inside the image
for bb in list_bbs:
if bb is None or int(round(bb.x2)) >= imgW or int(round(bb.y2)) >= imgH or int(bb.x1)<=0 or int(bb.y1)<=0:
valid=False
break
if valid: break
elif not restart:
img_aug=None
break
return img_aug,list_kps_aug,list_bbs
class BBA: # Bounding box + annotations
def __init__(self,bb,classname):
self.x1=int(round(bb.x1))
self.y1=int(round(bb.y1))
self.x2=int(round(bb.x2))
self.y2=int(round(bb.y2))
self.classname=card
class Scene:
def __init__(self,bg,img1):
self.createCardsScene(bg,img1)
def createCardsScene(self,bg,img1):
# Randomly transform 1st card
self.img1=np.zeros((imgH,imgW,4),dtype=np.uint8)
self.img1[decalY:decalY+cardH,decalX:decalX+cardW,:]=img1
self.img1, self.bbs1=augment(self.img1, transform_1cover)
#self.class1=class1
def display(self):
fig,ax=plt.subplots(1,figsize=(8,8))
ax.imshow(self.final)
for bb in self.listbba:
rect=patches.Rectangle((bb.x1,bb.y1),bb.x2-bb.x1,bb.y2-bb.y1,linewidth=1,edgecolor='b',facecolor='none')
ax.add_patch(rect)
def res(self):
return self.final
def write_files(self,save_dir,display=False):
jpg_fn, xml_fn=give_me_filename(save_dir, ["jpg","xml"])
plt.imsave(jpg_fn,self.final)
if display: print("New image saved in",jpg_fn)
create_voc_xml(xml_fn,jpg_fn, self.listbba,display=display)`
Excuse me, could you elaborate on the installation process of this project? Thanks !
I am having an issue with face cards (strangely enough only the King) where the interior boarder between the corner letter and suit image and the king itself is being mistaken as the border of the card and crops there. This only happens with the King (in every suit) so I am confused why this is occurring? Did you run into any similar issues when you originally created this program? Thanks.
Hey,
I think this is a really cool project and have learned a lot from reading through it. One thing I wanted to point out was that depending on if the user has openCV 2 or 3 installed, the find contours method will return 2 or 3 values. I was going to make a branch and make a PR for a change to that so, if you don't mind?
As the title says, I want to use the camera for real-time recognition. How can I do this?
In the video, i can see jokers, but in this script, i didn't see jokers.
Whether I can add jokers in this script, could you please comment? Many thanks.
Can you provide the video you used?
If you can get it to me, then I'l find a place it can have a more permanent home - or just the meta data that creates the training data. I'm looking into using this to help a friend of mine who is losing their eyesight and playing cards with their friends is their favourite hobby.
Hello.
I just want to understand bettter how you created the game at the end of the video.
Is it possible for you to share the source code of the game you created and how you made the refree board and all that.
Thanks!
I want to try it on mobile project, and this would use tiny yolo to make it work. So is it possible to transfer the weights you trained to tiny weights?
hi, i want to know can it apply this training model to an AI camera
http://www.hornedsungem.org/index_en.html
which is an Intel Movidius NCS integrated camera, that i want to attach it on Raspberry Pi3?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.