树莓派pi3启动时的视频录制自动化 [英] Automation of video recording on booting of raspberry pi3
问题描述
我写了一个python代码,其中包含一些与我的网络摄像头一起播放的opencv代码.我已将它附加到raspi3.我希望它在启动(启动)时自动开始录制视频. 我为此使用crontab.
I have written a python code which contains some opencv code to play around with my webcam. I have attached it to raspi 3. I want that on startup(booting), it start recording video automatically.. I am using crontab for this.
我的Python代码:
My Python code:
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脚本,如下所示,
Then I made a bash script which looks like this,
cd /
cd absolute path to my python file directory
sudo python cam22.py
cd /
cam22.py是我的python文件的名称
cam22.py is the name of my python file
然后我使用contrab在运行时通过编写来运行此bash脚本
Then I used contrab to run this bash script at runtime by writing
@reboot path to my bash file
重新启动后,在同一目录中生成了两个avi文件,但未录制视频,网络摄像头无法运行,但是当我自己执行此bash文件以运行python文件时,该摄像头可以完美运行.
After rebooting two avi files are generated in the same directory but the video is not recorded, the webcam doesn't runs, which however runs perfectly when I myself execute this bash file to run the python file.
正如注释中所建议,我已经创建了一个日志文件,它显示错误日志(视频流:542):Gtk-警告**:无法打开显示:
As Suggested in comments, I've created a log file, it shows The error log shows (Video Stream:542): Gtk-Warning **: cannot open display:
推荐答案
正如Mark Setchell在评论中所建议的那样,在删除imshow()和waitkey()之后,它可以正常工作.
As suggested by Mark Setchell in the comments, it worked correctly after removing imshow(), waitkey().
这篇关于树莓派pi3启动时的视频录制自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!