如何在opencv(python)中加载视频 [英] How to load a video in opencv(python)

查看:73
本文介绍了如何在opencv(python)中加载视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 OpenCV 和 Python 的初学者.我尝试加载视频并使用下面给出的代码显示它:

I am a begginer in OpenCV and Python. I tried to load a video and displaying it using code given below:

import cv2
cap = cv2.VideoCapture('G:\3d scanner\2.mmv')
while(1):
    _ , img2=cap.read()
    cv2.namedWindow('video',cv2.WINDOW_NORMAL)
    cv2.imshow('video',img2)            
    k=cv2.waitKey(1) & 0xFF
    if k==27:
        break
cap.release()
cv2.destroyAllWindows()

但它显示以下错误:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ..\..\..\..\opencv\modules\highgui\src\window.cpp, line 261
File "test3.py", line 8, in <module>
cv2.imshow('video',img2)
cv2.error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow

本网站上有关于此问题的先前问题,但答案是给出的是使用 cv 库而不是 cv2.

There are previous questions on this site regarding this issue but the answers given were using cv library but not cv2.

知道这有什么问题吗?

推荐答案

这可能对您有所帮助:

import numpy as np
import cv2

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

while(cap.isOpened()):
    ret, frame = cap.read()
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

如果它不起作用,他们的文档中有很多有用的解释:http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html

If it doesn't work, there are a lot of useful explanations in their documentation: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html

这篇关于如何在opencv(python)中加载视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆