-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thresholding live Webcam
34 lines (28 loc) · 990 Bytes
/
Thresholding live Webcam
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
import cv2
def main():
windowName = "Preview"
cap = cv2.VideoCapture(0)
if cap.isOpened():
ret,frame = cap.read()
else:
ret = False
while(ret):
ret,frame = cap.read()
th = 127
max_value = 255
ret,o1 = cv2.threshold(frame,th,max_value,cv2.THRESH_BINARY)
ret,o2 = cv2.threshold(frame,th,max_value,cv2.THRESH_BINARY_INV)
ret,o3 = cv2.threshold(frame,th,max_value,cv2.THRESH_TOZERO)
ret,o4 = cv2.threshold(frame,th,max_value,cv2.THRESH_TOZERO_INV)
ret,o5 = cv2.threshold(frame,th,max_value,cv2.THRESH_TRUNC)
cv2.imshow(windowName + "0", o1)
cv2.imshow(windowName + "1", o2)
cv2.imshow(windowName + "2", o3)
cv2.imshow(windowName + "3", o4)
cv2.imshow(windowName + "4", o5)
if cv2.waitKey(1) == 27:
break
cv2.destroyAllWindows()
cap.release()
if __name__ == "__main__":
main()