简体   繁体   English

无法在 python OpenCV 上显示视频

[英]Can't show the video on python OpenCV

I am currently trying to show a video on Python OpenCV.我目前正在尝试在 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环境有: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.感谢您的建议。

Do you have opencv_ffmpeg.dll or opencv_ffmpeg_64.dll in your C\\Python .你的C\\Pythonopencv_ffmpeg.dllopencv_ffmpeg_64.dll You need to have these dlls in order to play videos.您需要拥有这些dlls才能播放视频。 Check this link for more details.查看此链接了解更多详情。

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM