-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
87 lines (65 loc) · 1.69 KB
/
util.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import cv2
import sys
import uuid
from profiler import print_prof_data
import matplotlib.pyplot as plt
COIN_IMG_SIZE = 256
def draw_hist(hist, bins):
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2
plt.bar(center, hist, align='center', width=width)
plt.show()
def draw_4_hist(hists, bins):
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2
sp = 221
for i in range(len(hists)):
plt.subplot(sp)
sp += 1
plt.bar(center, hists[i], align='center', width=width)
plt.show()
def draw_hist_comparison(hist_array1, hist_array2, bins):
sp = 221
for i in range(len(hist_array1)):
plt.subplot(sp)
sp += 1
plt.plot(bins[:-1], hist_array1[i], "b-", bins[:-1], hist_array2[i], "r-")
plt.show()
def draw_2d_hist(hist2d):
plt.imshow(hist2d, interpolation='nearest')
plt.show()
UTIL_YES = 0
UTIL_NO = 0
def show_image(img, title="", size=(720, 720)):
cv2.namedWindow(title, cv2.WINDOW_NORMAL)
cv2.resizeWindow(title, size[0], size[1])
cv2.imshow(title, img)
key = cv2.waitKey(0)
cv2.destroyAllWindows()
# escape
if key == 27:
print_prof_data()
sys.exit()
# s
if key == 115:
# save
print("saving")
znj = uuid.uuid4()
cv2.imwrite(str(znj) + ".png", img)
global UTIL_NO
global UTIL_YES
# y
if key == 121:
print("yes")
UTIL_YES += 1
# n
if key == 110:
print("no")
UTIL_NO += 1
def print_yes_no():
print("CORRECT = ", UTIL_YES, "\nWRONG = ", UTIL_NO)
def reset_yes_no():
global UTIL_NO
global UTIL_YES
UTIL_YES = 0
UTIL_NO = 0