我写了一个python代码,其中包含了一些opencv代码,可以用来玩我的网络摄像头。我已经把它附加到raspi 3。我希望在启动(启动)时,它会自动录制视频。我用的是crontab。
我的Python代码:
import cv
if __name__ == "__main__":
# find the webcam
capture = cv2.VideoCapture(0)
capture1 = capture
# video recorder
fourcc = cv2.cv.CV_FOURCC(*'XVID') #cv2.VideoWriter_fourcc() does not exist
videoOut = cv2.VideoWriter('out1.avi', fourcc, 10.0, (640, 480))
videoOut1 = cv2.VideoWriter('out2.avi', fourcc, 10.0, (640, 480))
# record video
while (capture.isOpened() and capture1.isOpened()):
ret, frame = capture.read()
ret1, frame1 = capture1.read()
if ret:
videoOut.write(frame)
cv2.imshow('Video Stream', frame)
else:
break
if ret1:
frame1 = cv2.flip(frame1,1)
videoOut1.write(frame1)
cv2.imshow('Video Stream1', frame1)
else:
break
# Tiny Pause
key = cv2.waitKey(1)
capture1.release()
videoOut1.release()
capture.release()
videoOut.release()
cv2.destroyAllWindows()然后我做了一个像这样的bash脚本,
cd /
cd absolute path to my python file directory
sudo python cam22.py
cd /cam22.py是我的python文件的名称
然后,我使用禁忌在运行时运行这个bash脚本。
@reboot path to my bash file在重新启动后,在同一个目录中生成两个avi文件,但是没有记录视频,但是当我自己执行这个bash文件来运行python文件时,摄像头就不会运行了。
正如注释中所建议的,我已经创建了一个日志文件,它显示了错误日志显示(视频流:542):Gtk-警告**:无法打开显示:
发布于 2017-08-04 19:55:39
正如Mark在注释中所建议的,在移除imshow()、waitkey()之后,它正确地工作了。
发布于 2017-08-02 05:29:29
如果生成两个文件,这意味着crontab可以正常工作。这也意味着由于格式错误而没有生成的视频,.avi会将其更改为.AVI并尝试一次。
fourcc = cv2.cv.CV_FOURCC('D', 'I', 'V', 'X')
videoOut = cv2.VideoWriter('output1.AVI', fourcc, 20, (640, 480), 1)
videoOut2 = cv2.VideoWriter('output2.AVI', fourcc, 20, (640, 480), 1)https://stackoverflow.com/questions/45447020
复制相似问题