-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
141 lines (96 loc) · 4.04 KB
/
test.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import numpy as np
import cv2
from skimage.measure import compare_ssim
def check_YCbCr_YUV():
vc = cv2.VideoCapture(0)
if vc.isOpened():
is_capturing, _ = vc.read()
else:
is_capturing = False
while True:
is_capturing, frame = vc.read()
# shape, img = face_detector.detect_faces(frame)
#if shape != 0:
# frame = cv2.rectangle(frame, shape[0], shape[1],
# (255,0,0), thickness = 0)
frame1 = cv2.cvtColor(frame, cv2.COLOR_BGR2YCrCb)
frame2 = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV)
cv2.imshow('YCrCb[0]',frame1[:,:,0])
cv2.imshow('YCrCb[1]',frame1[:,:,1])
cv2.imshow('YCrCb[2]',frame1[:,:,2])
cv2.imshow('YUV[0]',frame2[:,:,0])
cv2.imshow('YUV[1]',frame2[:,:,1])
cv2.imshow('YUV[2]',frame2[:,:,2])
if cv2.waitKey(1) & 0xFF == ord('q'):
break
vc.release()
cv2.destroyAllWindows()
def thresholded():
cap = cv2.VideoCapture(0)
ret, frame_old = cap.read()
while True:
frame_old_gray = cv2.cvtColor(frame_old, cv2.COLOR_BGR2GRAY)
ret, frame = cap.read()
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
(score, diff) = compare_ssim(frame_old_gray, frame_gray, full=True)
diff[diff > 0.2] = 1
diff = (diff * 255).astype("uint8")
#ret, thresh = cv2.threshold(diff, 0,50,cv2.THRESH_BINARY)
thresh = cv2.threshold(diff, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv2.imshow('frame',thresh)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
frame_old = np.copy(frame)
cap.release()
cv2.destroyAllWindows()
def test_colors():
cap = cv2.VideoCapture(0)
ret, frame_old = cap.read()
while True:
frame_old_r =frame_old[:,:,2]
frame_old_g =frame_old[:,:,1]
frame_old_b =frame_old[:,:,0]
ret, frame = cap.read()
frame_r =frame[:,:,2]
frame_g =frame[:,:,1]
frame_b =frame[:,:,0]
(score, diff1) = compare_ssim(frame_old_r, frame_r, full=True)
(score, diff2) = compare_ssim(frame_old_g, frame_g, full=True)
(score, diff3) = compare_ssim(frame_old_b, frame_b, full=True)
#diff[diff > 0.2] = 1
diff1 = (diff1 * 255).astype("uint8")
diff2 = (diff2 * 255).astype("uint8")
diff3 = (diff3 * 255).astype("uint8")
ret, thresh = cv2.threshold(diff, 0,50,cv2.THRESH_BINARY)
thresh1 = cv2.threshold(diff1, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
thresh2 = cv2.threshold(diff2, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
thresh3 = cv2.threshold(diff3, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv2.imshow('red',thresh1)
cv2.imshow('green',thresh2)
cv2.imshow('blue',thresh3)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
frame_old = np.copy(frame)
cap.release()
cv2.destroyAllWindows()
cap = cv2.VideoCapture(0)
ret, frame_old = cap.read()
while True:
frame_old_r =frame_old[:,:,2]
ret, frame = cap.read()
frame_r = frame[:,:,2]
(score, diff1) = compare_ssim(frame_old_r, frame_r, full=True)
diff1[diff1 < 0.8] = 1
diff1 = (diff1 * 255).astype("uint8")
thresh1 = cv2.threshold(diff1, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv2.imshow('red',thresh1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
frame_old = np.copy(frame)
cap.release()
cv2.destroyAllWindows()