-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
25 lines (22 loc) · 1009 Bytes
/
Copy pathmain.py
File metadata and controls
25 lines (22 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from PIL import Image
import sys
import os
import find_lines
# Dimension of a Sudoku puzzle
matrix_size = 9
def main():
if len(sys.argv) < 2:
raise Exception("We need the name of the image file")
input_image = sys.argv[1]
image_path, image_file = os.path.split(input_image)
image_file_name, image_file_extension = os.path.splitext(image_file)
image = Image.open(input_image)
image_mono = find_lines.preprocess_image(image)
image_mono.save(os.path.join(image_path, image_file_name + '_mono' + image_file_extension))
horizontal_lines, vertical_lines = find_lines.find_lines(image_mono)
if len(horizontal_lines)-1 != matrix_size or len(vertical_lines)-1 != matrix_size:
raise Exception('Could not find 10 vertical and 10 horizontal lines in the image')
cell_image_boundaries = find_lines.get_cell_image_boundaries(horizontal_lines, vertical_lines)
find_lines.trim_cell_images(image_mono, cell_image_boundaries)
if __name__ == '__main__':
main()