如何在树莓派中启动网络摄像头并在启动时存储在闪存驱动器中



Part 1 : 我正在使用 cv2 运行一个 Python 脚本,将视频从网络摄像头保存到笔式驱动器。

import cv2,os
dypa = ('/media/pi/PSYCH') #specify the absolute output path here
fnam1 = 'output.avi' #specify the output file name here
fnam2 = 'output1.avi'
dypa1 = os.path.join(dypa,fnam1)
dypa2 = os.path.join(dypa, fnam2)
if __name__ == "__main__":
# find the webcam
capture = cv2.VideoCapture(0)
capture1 = capture
# video recorder
fourcc = cv2.cv.CV_FOURCC(*'XVID')
videoOut = cv2.VideoWriter(dypa1, fourcc, 10.0, (640, 480))
videoOut1 = cv2.VideoWriter(dypa2, 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)
else:
break
if ret1:
frame1 = cv2.flip(frame1,1)
videoOut1.write(frame1)
else:
break
# Tiny Pause
key = cv2.waitKey(1)
capture1.release()
videoOut1.release()
capture.release()
videoOut.release()
cv2.destroyAllWindows()

如果我知道笔式驱动器的名称("/media/pi/PSYCH"(,我设法做到了这一点。但是后来我把命令放在一个 bash 文件中

sudo nano/etc/rc.local

并添加

sudo python /home/pi/Desktop/TheCode.py

以便它在启动时执行。

当我重新启动时,仍然存在一个

/

media/pi/PSYCH

但现在无法访问,笔式驱动器现在位于

/

media/pi/PSYCH1

.下一次重新启动,它位于/media/pi/PSYCH2 等。

PS : 我正在使用带有Raspbian Jessie的Rasberry Pi 3

解决方案:

在代码中,我注释掉了所有显示交互。 我还评论了

key = cv2.waitKey(1)

我在 rc.local 中编辑了命令

sudo python /home/pi/Desktop/TheCode.py &

然后我使用库在TheCode.py文件中添加了 1 分钟的延迟

import time

然后写一个

time.delay(60)

这将使笔式驱动器和相机有时间安装,这造成了PSYCH1问题。

最新更新