-
Notifications
You must be signed in to change notification settings - Fork 3
/
surf.py
62 lines (48 loc) · 1.46 KB
/
surf.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
60
61
import numpy as np
from math import ceil
import cv2
def detect_character(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
surf = cv2.SURF()
mask = np.uint8(np.ones(gray.shape))
surf_points = surf.detect(gray, mask)
height, width, depth = img.shape
start_x = 0
end_x = height
X = 0
Y = 1
section_index = 0
total = 0
section_num = {}
for i in surf_points:
if (i.pt[X] > start_x and i.pt[X] < end_x):
section_index = int(ceil(i.pt[Y]/10.0))
section_num.setdefault(section_index, 0)
section_num[section_index] += 1
total += 1
avg = total / len(section_num)
slice_total = 10
slice_num = len(section_num) / slice_total
slice_counter = 0
for m in xrange(slice_total):
for n in xrange(m*slice_num, (m+1)*slice_num):
if section_num.get(n,0) >= avg:
slice_counter += 1
break
if (slice_counter >= slice_total):
return -1
con_num = 4
flag = 0
for k,v in section_num.iteritems():
if v > avg and flag == 0:
counter += 1
else:
counter = 0
if counter >= con_num and flag == 0:
sY = k
flag = 1
if sY > con_num and sY < (height / 4):
return 0 if (sY - con_num -11 ) * slice_total < 0 else (sY - con_num -11) * slice_total
elif sY > con_num:
return (sY - con_num) * slice_total
return sY * 10