pro*_*ion 7 python opencv video-capture
我是Python(2.7)的新手,我尝试从事视频处理(使用模块openCv"cv2").从教程开始,我尝试使用本教程的脚本:段落"保存视频".一切正常,除了我保存的视频是空的.我可以在我的目录中找到output.avi,但它的内存大小是0kb,当然,当我运行它时,没有显示视频.
经过一些更改后,我的代码是:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
#fourcc = cv2.VideoWriter_fourcc(*'DIVX')
fourcc = cv2.cv.CV_FOURCC(*'DIVX')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
有谁知道它为什么不能正常工作?
非常感谢.埃德温
小智 4
我从未使用过 openCV,但我敢打赌问题出在
cap = cv2.VideoCapture(0)
Run Code Online (Sandbox Code Playgroud)
这是VideoCapture方法的C版本http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture
也许你也可以尝试做同样的事情。就像是
cap = cv2.VideoCapture(0)
if (not cap.isOpened()):
print "Error"
Run Code Online (Sandbox Code Playgroud)
编辑:刚刚下载了 Python 和 OpenCV,发现问题出在编解码器上。尝试改变
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
Run Code Online (Sandbox Code Playgroud)
为了
out = cv2.VideoWriter('output.avi', -1, 20.0, (640,480))
Run Code Online (Sandbox Code Playgroud)
并手动选择编解码器。
| 归档时间: |
|
| 查看次数: |
8095 次 |
| 最近记录: |