-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_fly.py
More file actions
49 lines (34 loc) · 1.28 KB
/
Copy pathTest_fly.py
File metadata and controls
49 lines (34 loc) · 1.28 KB
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
import cv2
import numpy as np
if __name__ == '__main__':
def nothing(*arg):
pass
cv2.namedWindow( "result" )
cv2.namedWindow( "settings" )
cap = cv2.VideoCapture(0)
cv2.createTrackbar('h1', 'settings', 0, 255, nothing)
cv2.createTrackbar('s1', 'settings', 0, 255, nothing)
cv2.createTrackbar('v1', 'settings', 0, 255, nothing)
cv2.createTrackbar('h2', 'settings', 255, 255, nothing)
cv2.createTrackbar('s2', 'settings', 255, 255, nothing)
cv2.createTrackbar('v2', 'settings', 255, 255, nothing)
crange = [0,0,0, 0,0,0]
while True:
flag, img = cap.read()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV )
cv2.imshow('cam', img)
h1 = cv2.getTrackbarPos('h1', 'settings')
s1 = cv2.getTrackbarPos('s1', 'settings')
v1 = cv2.getTrackbarPos('v1', 'settings')
h2 = cv2.getTrackbarPos('h2', 'settings')
s2 = cv2.getTrackbarPos('s2', 'settings')
v2 = cv2.getTrackbarPos('v2', 'settings')
h_min = np.array((h1, s1, v1), np.uint8)
h_max = np.array((h2, s2, v2), np.uint8)
thresh = cv2.inRange(hsv, h_min, h_max)
cv2.imshow('result', thresh + img)
ch = cv2.waitKey(5)
if ch == 27:
break
cap.release()
cv2.destroyAllWindows()