Please sign in to comment.
- Loading branch information...
Showing with 37 additions and 12 deletions.
|@@ -1 +1,9 @@|
|+Detect Square works by running adaptivethreshold(), findsquare() and rectify()|
|+adaptivethreshold takes an image taken under bad lighting conditions and turns it into a black white image. The threshold is set adaptively based on the current local window condition. This way we can get a uniform black white picture even if the lightning is different.|
|+findsquare works by detecting the largest boundingbox in the image. We assume that that box is the sudoku square. This will largely work but lead to incorrect results when there is a larger square, for example in 9.jpg. There is also some preprocessing done.|
|+rectify works by finding the 4 corners of the sudoku square and then transforming them to a rectangle. I’m finding the corners by moving the corner inward until I hit black pixels. After transforming I’m also cropping the image based on the original sudoku square size and the position of the corner points.|
|@@ -1 +1,7 @@|
|+Extract digits works by scanning through the sudoku square with a window approximately the size of one digit field. The main challenge lies in removing the border lines of the window. We achieve a clean extracted digit in 2 steps.|
|+First we shrink the window to an inner rectangle by looking for the largest bounding box inside the window and crop the window down to that size. The function for that is get_rectangle().|
|+We have a second step to clean up any possible remaining black border pixels. shrink_rectangle() accomplishes this by shrinking all 4 edges of the rectangle until the middle 1/3 strip doesn’t contain any black pixels. (Most of the time this works, unless the grid line goes through the middle of the image without touching the border.)|
|+Then we need to determine if the rectangle contains a digit inside. We achieve this by calculating the ratio of black pixels to the whole rectangle area size. For higher accuracy, we divide the window into a 3 x 3 grid and we weigh the center region of the window more.|