-
Notifications
You must be signed in to change notification settings - Fork 0
/
quite_good_helpers.py
55 lines (44 loc) · 1.63 KB
/
quite_good_helpers.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
import cv2
import numpy as np
def number_of_clicks(array):
clicks = 0
old = array[0]
for i in range(1, len(array)):
if old != array[i]:
clicks += 1
old = array[i]
return clicks
def get_top_down(gray, window_height):
output = np.zeros(gray.shape)
for down_i in range(gray.shape[0] - window_height):
for left_i in range(gray.shape[1]):
if number_of_clicks(gray[down_i:down_i + window_height, left_i]) > 5:
output[down_i:down_i + window_height, left_i] += 1.
return cv2.normalize(output, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
def get_left_right(gray, window_height):
output = np.zeros(gray.shape)
for down_i in range(gray.shape[0]):
for left_i in range(gray.shape[1] - window_height):
if number_of_clicks(gray[down_i, left_i:left_i + window_height]) > 5:
output[down_i, left_i:left_i + window_height] += 1.
return cv2.normalize(output, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
def extract_two_extremes(array_of_activations):
arr = np.array(array_of_activations, copy=True)
arr.sort()
if len(array_of_activations) == 1729:
thr = arr[-3]
else:
thr = arr[-10]
tmp = []
for i in range(len(array_of_activations)):
if array_of_activations[i] > thr:
tmp.append(i)
current = 0
output = []
for point in tmp:
if point-current > 10:
current = point
output.append(point)
if len(output) == 1:
return output[0], output[0]
return output[0], output[1]