0

I have to find a couple of objects on an image. For example find all black pawns on a chessboard:

enter image description here

How can I achieve that,using OpenCV ?

I think about cv::matchTemplate, however I'm not sure how would it proceed with different pawn backgrounds. I'm also not sure if I can easily get all matchings in that way.

8
  • so, you already found one of the flaws in the matchTemplate approach - it just does not deal with transparency Commented May 17, 2014 at 22:26
  • do you want a generic solution - like for every state of the board ? And for any kind of board - different styles, pieces and colors? I just wanted to clarify that :) Commented May 17, 2014 at 22:36
  • Yes, it should be a generic solution. For example - it could be also a checkers (with different image and template of course). Commented May 17, 2014 at 22:44
  • 1
    I think this can be solved using HOG. And for the colour, simply using gray intensity to identify it Commented May 18, 2014 at 6:21
  • 1
    Yep, hog + svm is yet another solution Commented May 18, 2014 at 8:07

1 Answer 1

2

Start with corner detection (well known shi tomasi method, or smt like line detection and intersection, since it should work better for your case) and collection of 64 subsamples of image -the squares. If the board is ideal - pure birds eye view -and you know the size (8x8 here), then just crop it into WxH pieces. You should save these samples with their coordinates (b6, h1 etc).

For every square, a low pass filter smt like gaussian, then otsu threshold and contour detection should give you at most one big contour. If there is none, that square is empty.

You can try to get the contours from the initial state of the board, and name them. This is your training data. Since pieces are not gonna differ much; 1 sample is enough :) Save a "white pawn"s (any square from 2nd row initially) area, hu moments and color (mean rgb value is OK). Then save a "black pawn". Then "white queen" and "black queen" (d4 d8). Do that area, moment, color table for all pieces.

Later, for any state of the board, you can try to match hu moments, color and area of your contour -output of those squares, using your identification table. Of course some statistical method like knn could help you there. You can also utilize matchShapes method.

At last you identify your contour smt like black knight, red checker piece, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.