-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseeBoxes.py
More file actions
executable file
·51 lines (40 loc) · 1.34 KB
/
seeBoxes.py
File metadata and controls
executable file
·51 lines (40 loc) · 1.34 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
50
51
import cv2 as cv
import numpy as np
import time
cam = cv.VideoCapture(0)
cam.set(3,1280)
cam.set(4,720)
while True:
ret, frame = cam.read()
hsv_frame = cv.cvtColor(frame,cv.COLOR_BGR2HSV_FULL) #
cv.imshow("Color Frames", (frame))
lb = np.array([156, 50,50])
ub = np.array([184,255,255])
maskBlue = cv.inRange(hsv_frame,lb, ub)
blu = cv.bitwise_and(frame,frame,mask=maskBlue)
lrz = np.array([0, 50,50])
lr = np.array([14, 255,255])
ur = np.array([241,50,50])
urf = np.array([255, 255,255])
maskRedLower = cv.inRange(hsv_frame,lrz, lr)
maskRedUpper= cv.inRange(hsv_frame,ur, urf)
maskRed = cv.bitwise_or(maskRedLower, maskRedUpper)
red = cv.bitwise_and(frame,frame,mask=maskRed)
lg = np.array([70, 50,50])
ug = np.array([100,255,255])
maskGreen = cv.inRange(hsv_frame,lg, ug)
grn = cv.bitwise_and(frame,frame,mask=maskGreen)
# cv.imshow("Logic Frames", (np.logical_and(hsv_frame[:,:,1]>110 , hsv_frame[:,:,1]<150)).astype('float'))
cv.imshow("Red", red)
cv.imshow("Green", grn)
cv.imshow("Blue", blu)
wk = cv.waitKey(1)
if wk != -1:
print(wk)
if wk == 1048608:
print(("hsv:", hsv_frame[320, 240,0]))
print(("rgb:", frame[320, 240]))
if wk == 1048689:
break
cv.imwrite("green.jpg", grn)
cv.destroyAllWindows()