I have been struggling to implement a reliable webcam on the 'Bot for a while now. I think I have finally gotten there but it has been, well, a struggle. My requirement is to stream images in as close to real time as possible but while using a minimum of processing power.
My original idea was to capture images in Python using cv per this example. I worked on this for quite a while and finally gave up as I could not get it to be stable. Invariably, while it would work for a while, it would finally die (webcam would come unbound?). I thought that it might be the cheap webcam that I am using and tried another with the same results.
My next attempt was to try ffmpeg which is a powerful command line utility that can do a lot of image related functions...many more than I need. It does, however, have the capability to capture images from a video stream and save them with a unique time stamped file name. It drove me nuts. I still do not know why but it would save an image from a point back in time...! I thought that it was my code that was the problem as I do have some latency with my message queing and the like but I finally determined that it was ffmpeg. I strongly suspect that it was user error but did not take the time to prove this as I found an easier solution.
In any case, I am now using another command line utility called fswebcam. It is simpler than ffmpeg, but more importantly, it does what I want it to do! It runs in a little script that is spawned when the 'Bot starts running:
while [ 1 != 999 ]
fswebcam -r 320x240 -S 1 --jpeg 95 --save $FILE -q --timestamp %H:%M:%S