Reputation: 13
I am currently trying to show a video on Python OpenCV. However, although no errors return with the code below, I still don't see the selected video played.
Environments are: Anaconda3(Python 2.7.13), Windows 7, OpenCV 3.2.0
What I tried is:
import numpy as np
import cv2
cap = cv2.VideoCapture('Traffic.mpg')
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Appreciate for your advices.
Upvotes: 0
Views: 1285
Reputation: 31
An example code snippet which answers the question may look like:
import cv2
capture = cv2.VideoCapture(0)
while True:
ret, frame = capture.read()
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
Upvotes: -1