-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_test.py
36 lines (29 loc) · 904 Bytes
/
camera_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
import cv2
def mouseRGB(event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONDOWN: #checks mouse left button down condition
colorsB = img[y,x,0]
colorsG = img[y,x,1]
colorsR = img[y,x,2]
colors = img[y,x]
print("Red: ",colorsR)
print("Green: ",colorsG)
print("Blue: ",colorsB)
print("BRG Format: ",colors)
print("Coordinates of pixel: X: ",x,"Y: ",y)
def show_webcam(mirror=False):
global img
cam = cv2.VideoCapture(4)
cv2.namedWindow('my webcam')
cv2.setMouseCallback('my webcam',mouseRGB)
while True:
ret_val, img = cam.read()
if mirror:
img = cv2.flip(img, 1)
cv2.imshow('my webcam', img)
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()
def main():
show_webcam(mirror=True)
if __name__ == '__main__':
main()