I am creating a Sudoku app. Somehow in the process in the middle, I wanted to divide the image and arrange it side by side, so I created it while googled. I hope it will be helpful to someone.
split_img_and_layout_Horizontally.py
import numpy as np
import cv2
#Read the input image
img = cv2.imread("sudoku_wiki.png ")
#wiki https://en.wikipedia.org/wiki/Sudoku
#Define split size
vertical_split = 9
horizonal_split = 9
#Specify resizing
size = (vertical_split * 200, horizonal_split * 200)
img = cv2.resize(img, size)
#List initialization
split_img = []
#Divided vertically and horizontally
[split_img.extend(np.hsplit(img, horizonal_split)) for img in np.vsplit(img, vertical_split)]
#Arrange the divided images horizontally
img_list = [split_img[i] for i in range(len(split_img))]
merge_img = cv2.hconcat(img_list)
#Save image
cv2.imwrite('merge_img.jpg', merge_img)
Target image: sudoku_wiki.png
Execution result: merge_img.jpg It's hard to see, so please enlarge it. .. ..
・ It will be easier to see if you erase the border with the numbers. → Detects straight lines and paints white
・ Character string from the image of numbers → Incorporate MNIST (machine learning)
I worked on each of them, but the accuracy was not so good, so I hope it will be posted as soon as it can be improved.
Recommended Posts