Giter VIP home page Giter VIP logo

playing-card-detection's Introduction

playing-card-detection

Generating a dataset of playing cards to train a neural net.

The notebook creating_playing_cards_dataset.ipynb is a guide through the creation of a dataset of playing cards. The cards are labeled with their name (ex: "2s" for "2 of spades", "Kh" for King for hearts) and with the bounding boxes delimiting their printed corners.

This dataset can be used for the training of a neural net intended to detect/localize playing cards. It was used on the project Playing card detection with YOLO v3

Example of generated image

playing-card-detection's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

playing-card-detection's Issues

How to determine number of instances of cards?

@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

Don't see the jokers?

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.

installation process

Excuse me, could you elaborate on the installation process of this project? Thanks !

Problem with face cards with interior boarder

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.

Videos

Can you provide the video you used?

Source code for the game you created?

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!

3 card scene generation

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

Transform just 1 card without hull and enclose entire card in bounding box and generate new scene

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)`

cv2-versions

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?

Please upload the training data

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.