-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage_Checker.py
53 lines (43 loc) · 1.27 KB
/
Image_Checker.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
from PIL import Image
import pytesseract
class Image_Checker:
def __init__(self):
train_cnt = 0
th = 0
# need to train pytesseract!!!
def print_str_from_img( self, path ):
try:
im = Image.open(path)
result = pytesseract.image_to_string(im)
except:
print ("Failed to convert img to str")
return None
print(result)
return result
def get_main_color( self, im ):
h = im.histogram()
red = 0
green = 0
blue = 0
# split into red, green, blue
r = h[0:256]
g = h[256:256*2]
b = h[256*2: 256*3]
for i,w in enumerate(r):
red = red + i*w
for i,w in enumerate(g):
green = green + i*w
for i,w in enumerate(b):
blue = blue + i*w
if ( red > blue and red > green ):
#print("Main color is RED!")
return 'r'
elif ( blue > red and blue > green ):
#print("Main color is BLUE!")
return 'b'
elif ( green > red and green > blue ):
#print("Main color is GREEN!")
return 'g'
else:
print("Failed to find main color")
return 'n'