-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractor.py
59 lines (48 loc) · 1.29 KB
/
Extractor.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'''
Source: https://github.com/PortfolioCollection/Character_Recogniser
Authors: Muratovm, cheesywow.
Adapted by: luid101
'''
import tkinter as tk
from tkinter import filedialog
from PIL import Image
import numpy as numpy
def getImage(filename):
"""Returns a two dimensional array of a chosen image's pixels"""
try:
image = Image.open(filename, 'r')
except Exception as e:
print(e)
return image
def selectImage():
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
file = open(file_path)
filename = file.name
print(file.name)
try:
image = Image.open(filename, 'r')
except Exception as e:
print(e)
return image
def ImageToArray(image):
width, height = image.size
pixel_values = list(image.getdata())
color_array = []
for h in range(height):
color_array.append([])
for w in range(width):
color_array[h].append(pixel_values[h*width+w])
return color_array
def ImageToMatrix(image):
array = numpy.asarray(image)
return array
if __name__ == "__main__":
image = getImage()
#matrix = ImageToMatrix(image)
#print(matrix)
array = ImageToArray(image)
for row in array:
print(row)
exit = input("Type any enter to exit")