简体   繁体   English

在opencv中阅读视频(python)

[英]Read a video in opencv (python)

I'm trying to read a video file in opencv (python 2.7), and I just copied the example in the opencv tutorial, but nothing happens: 我正在尝试在opencv(python 2.7)中读取视频文件,我只是在opencv教程中复制了该示例,但没有任何反应:

import numpy as np
import cv2

cap = cv2.VideoCapture('input.mp4')

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

The function cap.isOpened always returns FALSE.I have already tried to use absolute path in the argument of VideoCapture, but I still get the same result. 函数cap.isOpened总是返回FALSE。我已经尝试在VideoCapture的参数中使用绝对路径,但是我仍然得到相同的结果。 What am I getting wrong? 我怎么了?

Maybe your OpenCV version is not properly installed. 也许您的OpenCV版本未正确安装。 You can check your build infos with print cv2.getBuildInformation() if there is any weird components. 如果有任何奇怪的组件,您可以使用print cv2.getBuildInformation()检查您的构建信息。

I would suggest to rebuild it, or install it via Anaconda to be sure not to miss any package. 我建议重建它,或通过Anaconda安装它,以确保不会丢失任何软件包。

您需要定义视频位置或将视频安装到python安装位置

Keep the full path of the video file. 保留视频文件的完整路径。 For example :- 例如 :-

cap = cv2.VideoCapture("D:\\Video Folder\\input.mp4")

I believe this would solve this issue. 我相信这会解决这个问题。

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

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