#NEWLINE# def _get_puzzle( self ) : #NEWLINE# #INDENT# 'Get the numbers in the puzzle in a 9x9 array.\n\n        Returns:\n            A numpy.ndarray filled with the numbers of the puzzle.\n        ' #NEWLINE# sudoku_matrix = np . zeros ( ( NUM_ROWS , NUM_ROWS ) , np . uint8 ) #NEWLINE# ( contours , image_copy ) = self . _get_major_contours ( self . resized_largest_square , sigma1 = 3 , threshold_type = cv2 . THRESH_BINARY_INV , dilate = False ) #NEWLINE# kernel = cv2 . getStructuringElement ( cv2 . MORPH_CROSS , ( 3 , 3 ) ) #NEWLINE# erode = cv2 . erode ( image_copy , kernel ) #NEWLINE# dilate = cv2 . dilate ( erode , kernel ) #NEWLINE# for contour in contours : #NEWLINE# #INDENT# area = cv2 . contourArea ( contour ) #NEWLINE# if ( 50 < area < 800 ) : #NEWLINE# #INDENT# ( bx , by , bw , bh ) = cv2 . boundingRect ( contour ) #NEWLINE# if ( ( 100 < ( bw * bh ) < 1200 ) and ( 5 < bw < 40 ) and ( 10 < bh < 45 ) ) : #NEWLINE# #INDENT# roi = dilate [ bh : ( by + bh ) , bx : ( bx + bw ) ] #NEWLINE# small_roi = cv2 . resize ( roi , ( 10 , 10 ) ) #NEWLINE# feature = small_roi . reshape ( ( 1 , 100 ) ) . astype ( np . float32 ) #NEWLINE# ( ret , results , neigh , dist ) = self . model . find_nearest ( feature , k = 1 ) #NEWLINE# integer = int ( results . ravel ( ) [ 0 ] ) #NEWLINE# gridy = ( ( bx + ( bw / 2 ) ) / ( SUDOKU_RESIZE / NUM_ROWS ) ) #NEWLINE# gridx = ( ( by + ( bh / 2 ) ) / ( SUDOKU_RESIZE / NUM_ROWS ) ) #NEWLINE# sudoku_matrix . itemset ( ( gridx , gridy ) , integer ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return sudoku_matrix