[英]Using Raspberry Pi + Webcam to record video in python always gets an empty video or only one frame video
I want to record video with Raspberry Pi + wedcam (logitech). 我想用Raspberry Pi + wedcam(logitech)录制视频。 Although I found many examples which are actually almost the same code as following:
尽管我发现了许多示例,这些示例实际上与以下代码几乎相同:
import numpy as np
import cv2
path = ('/.../output.avi')
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter(path,fourcc, 20.0, (640,480))
while(cap.isOpened()):
#read the frame
ret, frame = cap.read()
if ret==True:
#Write the frame
video_writer.write(frame)
#show the frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
video_writer.release()
cv2.destroyAllWindows()
First question, I have tried all solutions from OpenCV write frame to file python but it seems those solutions didn't suitable for me... so I want to know if anyone has other solutions for this problem, I will appreciate! 第一个问题,我尝试了从OpenCV编写框架到文件python的所有解决方案,但似乎这些解决方案不适合我...所以我想知道是否有人对此问题有其他解决方案,我将不胜感激! Second question, I found that someone use
第二个问题,我发现有人使用
cv2.VideoWriter_fourcc('XVID')
instead of 代替
cv2.cv.CV_FOURCC(*'XVID')
Would that be the problem? 那会是问题吗? Also, I have tried to use cv2.VideoWriter_fourcc('XVID'), but get an error: 'module' object has no attribute 'VideoWriter_fourcc'... How can I solve this?
另外,我尝试使用cv2.VideoWriter_fourcc('XVID'),但收到错误消息:'module'对象没有属性'VideoWriter_fourcc'...我该如何解决? Thanks!
谢谢!
You used 'out' to create your video writer object 您使用“ out”创建了视频编写器对象
out = cv2.VideoWriter(path,fourcc, 20.0, (640,480))
So perhaps you should replace video_writer.write(frame)
with out.write(frame)
因此,也许您应该将
video_writer.write(frame)
替换为out.write(frame)
Also replace video_writer.release()
with out.release()
还要用
video_writer.release()
替换out.release()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.