Search code examples
opencvimage-recognitionsquarebaduk

OpenCV detect square with difficult background


i am working on an Android app that will recognize a GO board and create a SGF file of it.

i need to detect the whole board in order to warp it and to be able to find the correct lines and stones like below.

filledboard
(source: eightytwo.axc.nl)

right now i use an Opencv RGB Mat and do the following:

  • separate the channels
  • canny the separate channels

    Imgproc.Canny(channel, temp_canny, 30, 100);
    
  • combine (bitwise OR) all channels.

    Core.bitwise_or(temp_canny, canny, canny);
    
  • find the board contour

Still i am not able to detect the board consistently as some lines tend to disappear as you can see in the picture below, black lines on the board and stones are clearly visible but the board edge is missing at some places.

filledboard
(source: eightytwo.axc.nl)

how can i improve this detection? or should i implement multiple ways of detecting it and switching between them when one fails..

* Important to keep in mind *

  • go boards vary in color
  • go boards can be empty or completely filled with stones
    this implies i can't rely on detecting the outer black line on the board
  • backgrounds are not always plain white

this is a small collection of pictures with go boards i would like to detect

* Update * 23-05-2016

I kinda ran out of inspiration using opencv to solve this, so new inspiration is much appreciated!!! In the meantime i started using machine learning, first results are nice and i'll keep you posted but still having high hopes creating a opencv implementation.


Solution

  • I'm working on the same problem!

    My approach is to assume two things:

    1. The camera is steady
    2. The board is steady

    That allows me to deduce the warping parameters from a single frame when the board is still empty (before playing). Use these parameters to warp every frame, no matter how many stones are occluding the board edges.