Evolution of a Blog

This blog has evolved as I have as a maker. It starts at the beginning of my journey where I began to re-tread my tires in the useful lore of micro electronics and the open-source software that can drive them. While building solutions around micro-electronics are still an occasional topic my more recent focus has been on the 3D Printing side of making.

Monday, February 18, 2013

Webcam Struggles

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 ]
    do
        FILE="/var/www/stream_$(date +%H%M%S).jpg"
        fswebcam -r 320x240 -S 1 --jpeg 95  --save $FILE -q --timestamp %H:%M:%S
    done


3 comments:

  1. Have you looked at the RPI camera-module thats coming out soon (http://www.raspberrypi.org/archives/3224)? I'm not entirely sure how it connects yet, but I think this could circumvent a lot of issues trying to fit a webcam on it. Also they claim it can stream video at 30fps in 720p/1080p.

    Wasn't able to find any info about how much current it would draw, but I'm going to get one and try it out once its up for sale.

    ReplyDelete
  2. That looks pretty cool. I don't think it will work on my 'Bot as I have fully committed the ribbon cable to other purposes but I may have to invent a reason to get one of these...cost being at the right point of course!

    ReplyDelete
    Replies
    1. It looks like the price will be around $25, which I think is fairly reasonable. I wonder how much demand it will put on the Pi though, might have to run it at a slightly lower bitrate.

      Delete