I wrote python code that contains some opencv code to play with my webcam. I connected it to raspi 3. I want it to start recording automatically at startup (boot). I am using crontab for this.
My Python code is:
import cv
if __name__ == "__main__":
capture = cv2.VideoCapture(0)
capture1 = capture
fourcc = cv2.cv.CV_FOURCC(*'XVID')
videoOut = cv2.VideoWriter('out1.avi', fourcc, 10.0, (640, 480))
videoOut1 = cv2.VideoWriter('out2.avi', fourcc, 10.0, (640, 480))
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
key = cv2.waitKey(1)
capture1.release()
videoOut1.release()
capture.release()
videoOut.release()
cv2.destroyAllWindows()
Then I made a bash script that looks like this:
cd /
cd absolute path to my python file directory
sudo python cam22.py
cd /
cam22.py is the name of my python file
Then I used contrab to run this bash script at runtime by writing
@reboot path to my bash file
After rebooting, two avi files are generated in the same directory, but the video is not recorded, the webcam does not start, which, however, works fine when I execute this bash file myself to run the python file.
, , , (Video Stream: 542): Gtk-Warning **: :