First and foremost, make sure the application succeeds communicating with the camera:
import cv
capture1 = cv.CaptureFromCAM(0)
if not capture1 :
print "!!! Failed to open a camera interface"
# Ideally, exit the application.
cv.SetCaptureProperty(capture1,cv.CV_CAP_PROPER_FRAME_WIDTH,320)
cv.SetCaptureProperty(capture1,cv.CV_CAP_PROPER_FRAME_HEIGHT,240)
Remember to test if the frame was successfully retrieved from the camera:
while 1:
frame = cv.QueryFrame(capture1);
if not frame:
print "!!! Failed to retrieve frame"
break
# Right now, your code overwrites the same file at every iteration of the loop.
# It might be better to add a BREAK at the end for testing purposes.
cv.SaveImage("camera.jpg", frame);
# There's no need to call WaitKey() if the image is not displayed on a window.
#cv.WaitKey(11)
print 'Done!'
SaveImage()
will fail when the application doesn't have permission to write files in the directory from where it was executed. Since crontab is responsible to call your application, I imagine that it does that from a directory where the user doesn't have the right permissions. If this is the case, I strongly suggest you to feed SaveImage()
with the full path to the file.