forked from hgarrereyn/OCRaaP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_parser.py
57 lines (38 loc) · 1.33 KB
/
image_parser.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
import numpy as np
import cv2
import imutils
def get_symbols(image, debug=False):
#res = cv2.cvtColor(image, cv2.IMREAD_GRAYSCALE)
res = cv2.resize(image, (1000, 1000), None)
_,thresh = cv2.threshold(res, 127, 255, cv2.THRESH_BINARY_INV)
kernel = np.ones((5,5), np.uint8)
dial = cv2.dilate(thresh, kernel, iterations=2)
params = cv2.SimpleBlobDetector_Params()
params.blobColor = 255
params.filterByColor = True
params.filterByArea = True
params.minArea = 100
params.maxArea = 100000
params.filterByInertia = False
params.filterByConvexity = False
params.filterByCircularity = False
detector = cv2.SimpleBlobDetector(params)
rev = (255-dial)
holes = detector.detect(rev)
for h in holes:
x, y = h.pt
s = int(h.size * 1.2)
cv2.circle(dial, (int(x), int(y)), s, (255,255,255), -1)
keypoints = detector.detect(dial)
if debug:
small = cv2.resize(dial, (600,600), None)
cv2.imshow('a', small)
cv2.waitKey(0)
symb = []
for k in keypoints:
x, y = k.pt
s = int(k.size * 1.2) # ~ sqrt(2) / 2
crop = res[int(max(y-s,0)):int(min(y+s,1000)), int(max(x-s,0)):int(min(x+s,1000))]
crop_res = cv2.resize(crop, (100, 100), None)
symb.append(crop_res)
return (symb, keypoints)