簡體   English   中英

樹莓派pi3啟動時的視頻錄制自動化

[英]Automation of video recording on booting of raspberry pi3

我寫了一個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文件的名稱

然后我通過使用contrab在運行時通過編寫以下bash腳本來運行

@reboot path to my bash file

重新啟動后,在同一目錄中生成了兩個avi文件,但未記錄視頻,網絡攝像頭無法運行,但是當我自己執行此bash文件以運行python文件時,該攝像頭可以完美運行。

如注釋中所建議,我已經創建了一個日志文件,它顯示錯誤日志(視頻流:542):Gtk-警告**:無法打開顯示:

正如Mark Setchell在評論中所建議的那樣,在刪除imshow(),waitkey()之后,它可以正常工作。

如果生成了兩個文件,則意味着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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM