xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks

I have a HP notebook running on ubtunu 10.04 with 200MP webcam whose model is Probook 4321s. Now I intend to write a script to take photos regularly from webcam in perl. It sound be much fun, but I have no idea about knowledge about camera program so far. Neither did I find any useful modules on this on CPAN.

So my question is if there is C or perl library to help me work out? If no, how can I make this work done? Besides, is there a general way to work well on both linux and windows?

Thanks in advance!





I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Replies are listed 'Best First'.
Re: control webcam
by roboticus (Chancellor) on Mar 10, 2011 at 04:50 UTC

    xiaoyafeng:

    I'd start by looking around the Monastery for possible webcam articles, then CPAN to see if any of the modules there (only two that I noticed) will work for you. If that doesn't get you anywhere, I'd check around in the Linux UVC driver & tools page. From there, you may find a useful command-line program, easy-to-call driver interface or some other way to talk with the Webcam. Once you find a way to talk to your webcam, then you can figure out where to start.

    From my (very brief) browsing, I found that some systems have command-line tools to capture images (such as the Mac), while others have FTP and/or HTTP servers built into them, and others are USB devices, presumably with a relatively-standard method to talk to them. Since you've got a laptop, I imagine that it doesn't use FTP/HTTP, so I'd look around the HP forums for a command-line program.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: control webcam
by Anonymous Monk on Mar 10, 2011 at 04:50 UTC
Re: control webcam
by zentara (Cardinal) on Mar 10, 2011 at 14:55 UTC
    You can look at ztk-v4l-video-bloger/recorder for an example. You really need to find out what type of camera you will be using first. Old NTSC , and Pal cameras need different handling than the newer USB cameras. There are also IP cameras, which are probably the most useful.

    From my experience, the apps "mencoder" and "mplayer" are your best bets. They are available on Windows. If you are on linux, you may have to use a usb microphone to get recording, you can google for setting up alsa for a usb microphone recording session. See USB_mic_on_linux

    Here is a simple mencoder string for a usb mic, listed as hw2 in the usb list. Linux hasn't good support for built-in mikes yet. :-( So your built-in mic is hw 1) Google for more mencoder examples. If you want to see how to control mplayer and mencoder from Perl with IPC::Open3, see ztk-v4l-video-bloger/recorder

    mencoder tv:// -tv \ driver=v4l2:device=/dev/video0:width=320:height=240:adevice=/dev/dsp:f +orceaudio:alsa:adevice=hw.2,0 \ -ofps 15 -oac mp3lame -lameopts cbr:br=32 -ovc lavc -lavcopts \ vbitrate=92 -o ./out-low-quality.avi # You can change framerate up to 25, video bitrate to 800 # and sound bitrate to 128 or greater to get excellent quality.

    #########################################

    and here is a simple snapshot app.... just press "s"

    ############################################

    mplayer -vf screenshot tv:// driver=v4l2:width=800:height=600:device=/ +dev/video0 -fps 15 # and that gave me 800x600 video, and after I pressed 's' i obtained 8 +00x600 in the snapshot. # q to quit # I did the same for 1024x768, 1280x1024, and 1600x1200 and obtained a + 1024x768, # 1280x1024, and 1600x1200 video and snapshot respectively. # or get shots from a video # mplayer -vf screenshot some.avi

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh