r_points = [ list(i) for i in zip(*c_points)] r_points = [x for sublist in r_points for x in sublist] ###OCR Stage print "7) OCR Stage: " result = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]] for row in range(9): print "\tRow: " + str(row+1) for column in range(9): ## top left corner = x1:y1 | down right corner = x2:y2 x1,x2,y1,y2 = OCR.getcorners((row,column),r_points) crop = res2[y1+5 : y2-5 , x1+5 : x2-5] if crop.size == 0: result[row][column] = "E" continue cv2.imwrite("debug/digits"+str(row)+str(column)+".jpg",crop) digit = cv2.cv.CreateImageHeader((crop.shape[1],crop.shape[0]), cv2.cv.IPL_DEPTH_8U, 1) cv2.cv.SetData(digit, crop.tostring(), crop.dtype.itemsize*crop.shape[1]) ##recognize the digit result[column][row] = OCR.ocr_singledigit(digit)
C_POINTS = [sorted(i, key = lambda x: x[1]) for i in OCR.split_len(sorted(POINTS), 10)] R_POINTS = [ list(i) for i in zip(*C_POINTS)] R_POINTS = [x for sublist in R_POINTS for x in sublist] ###OCR Stage print "[7]OCR Stage: " RESULT = [[0]*9 for i in range(9)] for row in range(9): print "\t[+]Row: " + str(row + 1) for column in range(9): ## top left corner = x1:y1 | down right corner = x2:y2 x1, x2, y1, y2 = OCR.getcorners((row, column), R_POINTS) crop = RES2[y1 + 7 : y2 - 7 , x1 + 7: x2 - 7] digit = cv2.cv.CreateImageHeader((crop.shape[1], crop.shape[0]), cv2.cv.IPL_DEPTH_8U, 1) cv2.cv.SetData(digit, crop.tostring(), crop.dtype.itemsize*crop.shape[1]) if DEBUG_MODE: print row, column cv2.imwrite(DEBUG_FOLDER + str(row) + str(column)+".jpg", crop) ##recognize the digit RESULT[column][row] = OCR.ocr_singledigit(digit) ##print out the sudoku puzzle