I think you do not need to use angular detection here. Just using the outlines, you can solve it (if your images are straightforward). Below is the code that prints the array for your image above. Codes commented on:
import numpy as np import cv2 img = cv2.imread('cross.jpg') gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV) thresh2 = cv2.bitwise_not(thresh) contours,hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, 1) max_area = -1
I have this output for your image above:
[[ 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] [ 1. 0. 1. 0. 1. 0. 1. 0. 0. 0. 1. 0. 1.] [ 1. 1. 1. 1. 1. 1. 1. 1. 0. 1. 1. 1. 1.] [ 1. 0. 1. 0. 1. 0. 1. 0. 1. 0. 1. 0. 1.] [ 1. 1. 1. 1. 1. 0. 1. 1. 1. 1. 1. 1. 1.] [ 1. 0. 0. 0. 1. 0. 1. 0. 1. 0. 1. 0. 1.] [ 1. 1. 1. 1. 0. 0. 0. 0. 0. 1. 1. 1. 1.] [ 1. 0. 1. 0. 1. 0. 1. 0. 1. 0. 0. 0. 1.] [ 1. 1. 1. 1. 1. 1. 1. 0. 1. 1. 1. 1. 1.] [ 1. 0. 1. 0. 1. 0. 1. 0. 1. 0. 1. 0. 1.] [ 1. 1. 1. 1. 0. 1. 1. 1. 1. 1. 1. 1. 1.] [ 1. 0. 1. 0. 0. 0. 1. 0. 1. 0. 1. 0. 1.] [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0.]]
I wrote code to extract sudoku from an image with a detailed explanation from the links below (the textbook is incomplete). You can contact them for more information:
http://opencvpython.blogspot.com/2012/06/sudoku-solver-part-1.html
http://opencvpython.blogspot.com/2012/06/sudoku-solver-part-2.html
http://opencvpython.blogspot.com/2012/06/some-common-questions.html
source share