Tenma
Tenma

Reputation: 13

Can't show the video on python OpenCV

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

Answers (2)

jai_kumar
jai_kumar

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

hcerim
hcerim

Reputation: 999

Do you have opencv_ffmpeg.dll or opencv_ffmpeg_64.dll in your C\Python. You need to have these dlls in order to play videos. Check this link for more details.

Upvotes: 1

Related Questions