使用openCV+打开视频;python
我正在使用python 2.7和openCV 2.3.1(Win7)。 我正在尝试打开视频文件:使用openCV+打开视频;python,python,opencv,video-capture,Python,Opencv,Video Capture,我正在使用python 2.7和openCV 2.3.1(Win7)。 我正在尝试打开视频文件: stream = cv.VideoCapture("test1.avi") if stream.isOpened() == False: print "Cannot open input video!" exit() 但我有一个警告: warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl_v2.hpp:394)
stream = cv.VideoCapture("test1.avi")
if stream.isOpened() == False:
print "Cannot open input video!"
exit()
但我有一个警告:
warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl_v2.hpp:394)
如果使用摄像机(stream=cv.VideoCapture(0)
),此代码有效。
你知道我做错了什么吗?
谢谢大家 尝试改用
cv.CaptureFromFile()
如果必须复制此代码:。请尝试改用
cv.CaptureFromFile()
复制此代码,如果必须:.< /p> ,可以使用OpenCV(CV2)的新接口,即面向对象的,它是用C++绑定的。 我发现它更容易阅读
注意:如果你用这个打开一张图片,fps没有任何意义,所以图片保持静止import cv2
import sys
try:
vidFile = cv2.VideoCapture(sys.argv[1])
except:
print "problem opening input stream"
sys.exit(1)
if not vidFile.isOpened():
print "capture stream not open"
sys.exit(1)
nFrames = int(vidFile.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)) # one good way of namespacing legacy openCV: cv2.cv.*
print "frame number: %s" %nFrames
fps = vidFile.get(cv2.cv.CV_CAP_PROP_FPS)
print "FPS value: %s" %fps
ret, frame = vidFile.read() # read first frame, and the return code of the function.
while ret: # note that we don't have to use frame number here, we could read from a live written file.
print "yes"
cv2.imshow("frameWindow", frame)
cv2.waitKey(int(1/fps*1000)) # time to wait between frames, in mSec
ret, frame = vidFile.read() # read next frame, get next return code
可以使用OpenCV(CV2)的新接口,它是面向对象的,它是用C++绑定的。 我发现它更容易阅读
注意:如果你用这个打开一张图片,fps没有任何意义,所以图片保持静止import cv2
import sys
try:
vidFile = cv2.VideoCapture(sys.argv[1])
except:
print "problem opening input stream"
sys.exit(1)
if not vidFile.isOpened():
print "capture stream not open"
sys.exit(1)
nFrames = int(vidFile.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)) # one good way of namespacing legacy openCV: cv2.cv.*
print "frame number: %s" %nFrames
fps = vidFile.get(cv2.cv.CV_CAP_PROP_FPS)
print "FPS value: %s" %fps
ret, frame = vidFile.read() # read first frame, and the return code of the function.
while ret: # note that we don't have to use frame number here, we could read from a live written file.
print "yes"
cv2.imshow("frameWindow", frame)
cv2.waitKey(int(1/fps*1000)) # time to wait between frames, in mSec
ret, frame = vidFile.read() # read next frame, get next return code
从开始,尝试将OpenCV安装中的所有
.dll
文件复制到C:\Python27
,从开始,尝试将OpenCV安装中的所有.dll
文件复制到C:\Python27
中。还有其他更简单的方法吗?这是最简单的方法。还有其他更简单的方法吗?这是最简单的方法。