Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- # The device number might be 0 or 1 depending on the device and the webcam.
- cap = cv2.VideoCapture()
- cap.open(0, cv2.CAP_DSHOW)
- # this if is in case I want to open a video file that does not exists in a path for cv2.VideoCapture('path')
- if not cap.isOpened():
- raise IOError("Cannot open file")
- # this line here is only to give the window a name before the loop so I
- # can have a reference for the getWindowProperty window name.
- cv2.namedWindow("frame", cv2.WINDOW_AUTOSIZE)
- # getWindowProperty will return -1 if if try to close it with my mouse, weird.... (but useful)
- while(cv2.getWindowProperty('frame', 0) >= 0):
- ret, frame = cap.read()
- cv2.imshow('frame', frame)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- cap.release()
- cv2.destroyAllWindows()
- # TODO: I should try to wrap cv2 inside tkinter GUI to add more elements to the window
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement