Webcams / Digital Cameras

MG starts this page on June 12th 2005, to list some of the Tcl applications or extensions for working with Digital Cameras or Webcams.

I wanted to capture some footage from a webcam (or at least see if it was possible) for embedding it in a webpage (I have a program that converts most common movie formats into Flash movies files at the touch of a button), and thought I'd see about doing it in Tcl. There seem to be several extensions (generally aimed at MS Windows, it seems) for working with web cams, so below is a list of all the ones I've found, after a very brief search. If anyone has any more extensions, or info on using webcams or digital still cameras with Tcl and/or Tk, please post it here!


QuickTimeTcl provides a webcam capture facility, according to its homepage, which I believe runs on MS Windows and MacOS (and requires that Quicktime be installed, on both).


tkvideo is a Tk widget for displaying streaming video from a webcam. It currently only supports Windows but may be extended in the future (at least it is structured that way). It can also take still images from the webcam and can be configured to record to AVI or WMV files. The AMSN project is also using this widget to transmit webcam data across the network using the MSN protocols - however this is done by passing a series of snapshots. See [L1 ] and [L2 ] for more info.

At this time the tkvideo widget cannot pipe a video stream to a Tcl channel.

Bugs and requests for enhancement should be raised at one of the trackers on [L3 ]

dzach 2005-9-19: Any docs for the new features besides the demo code? Is it possible to use frames to seek a video position instead of time?

tilaphos is a Time-lapse photography application based on tkvideo.


The AviCapTcl (vfwtcl) package on Sourceforge (at [L4 ], and apparantly also [L5 ], though the second is down due to a work at present) also supports webcam video (and audio) capture to an AVI movie file.


And finally, though I haven't looked at it yet (and taken straight from the Applications in Tcl and Tcl/Tk page: Audela is a free and open source astronomy software intended for digital observations (CCD cameras, Webcams, etc.). Audela is fully customizable and reprogrammable using simple Tcl-Tk scripts. It enables not only camera control, but also full telescope control, locally or at long distance via a network. It has been written for both Windows and Linux platforms and is available in 6 languages (fr,uk,es,it,de,dk). See [L6 ]


SRIV June 12th 2005 I wrote a v4l (video for linux) tcl extension to capture frames from a framegrabber (bt848), but it's been tested with a Phillips/Logitech USB webcam and Logitech USB notebook cam. It doesnt require Tk, so it can be easily used in server-side and cgi applications. It grabs a frame, then converts it to jpeg and returns the jpeg file data, which could then be streamed back to a client as stills or a mjpeg stream. I'll get a page assembled for it here in the next day or so.


MG today (June 13 05) tested PT's tkvideo and the AviCapTcl package on Win XP SP2, just by running their demos. PT's tkvideo works great. The AviCapTcl package displays the webcam on-screen fine, but running their 'test-avicap' demo, to record to an AVI file, only recorded a very (less than 1 second) brief clip, though it should've recorded more. I'll see if I can find out why later...

I haven't looked at QuickTimeTcl's webcam features yet - I tried them once before, and it crashed, but I now have reason to believe the crash was from my drivers, not QuickTimeTcl, so will re-try it later on...


Harm Olthof June 13 2005 - I am not much of a programmer (Windows or Tcl), but this worked for me, using tcom to interface Windows XP's WIA (Windows Image Acquisition).

   package require tcom
   ::tcom::import c:/WINDOWS/system32/wiascr.dll

   set WIAobj [::WIALib::Wia]
   set WIAdevice [$WIAobj Create]
   set WIAcoll [$WIAdevice GetItemsFromUI]
   for {set i 0} {$i<[$WIAcoll Count]} {incr i} {
       set WIAitem($i) [$WIAcoll Item $i]  
      $WIAitem($i) Transfer d:/pic_${i}.bmp 0
   }

This works only for stills, but video should also be possible. More info at [L7 ] I could not getting to work transfering to "clipboard" or using "TakePicture".

MG I haven't looked at the link you gave, but running that code (on Win XP Home SP2), I got errors:

 %   package require tcom
 3.9
 %    ::tcom::import c:/WINDOWS/system32/wiascr.dll
 WIALib
 %    set WIAobj [::WIALib::Wia]
 ::tcom::handle0x00E034E0
 %    set WIAdevice [$WIAobj Create]
 0x80210015 {Unknown error}

And then it failed b/c $WIAdecide hadn't been set.

Harm Olthof June 14 2005 - It still worked yesterday on my Win XP pro SP2 system, but I should have mentioned that the code above assumes that there's only one image device attached. If you have more than one you should adapt the code to choose the device. I cant't remember the details (it was a few months ago), but I think it's all in the link above or on MSDN. Also, unfortunatedly it starts a build-in GUI. I hoped to get the TakePicture method to work, and then transfer the picture to the clipboard and consequently copying it to a canvas every few seconds... I'll try make a better example, but that will no be until next week.


PWE I tried some of the above systems on various windows versions without too much success. I finally got something working with a vb control called ezVidCap [L8 ] and optcl. With these installed, the following should give a very basic program:

 package require optcl

 proc FileSave { filename } {
  global cal
  $cal SaveDIB $filename  
 }
 proc setdriver { number } {
   global cal 
   $cal : DriverIndex $number
 }
 frame .f
 button .f.form -command {$cal ShowDlgVideoFormat} -text Format
 button .f.sourc -command {$cal ShowDlgVideoSource} -text Source 
 set cal [optcl::new -window .cal vbVidC60.ezVidCap]
 .cal config -width 256 -height 192

 set nrdevs [$cal NumCapDevs]
 for { set n 0 } { $n < $nrdevs } { incr n  } {
   lappend drivers [$cal GetDriverName $n]
 }
 if {$tcl_platform(platform) == "macintosh"} {
   set modifier Command
 } elseif {$tcl_platform(platform) == "windows"} {
   set modifier Control
 } else {
   set modifier Meta
 }

 set base ""
 menu $base.menu
 set m $base.menu.file
 menu $m
 $base.menu add cascade -label File -menu $m -underline 0
   $m add command \
       -label SaveImage -underline 0 -accelerator $modifier+S -command {FileSave [tk_getSaveFile -defaultextension bmp ]}
   $m add command \
         -command exit -label Exit -underline 1 -accelerator Alt+x 

 set m $base.menu.options
 menu $m
 $base.menu add cascade -label Options -menu $m -underline 0
 for { set n 0 } { $n < $nrdevs } { incr n  } {
   $m add radio -label [lindex $drivers $n] -variable drivernumber \
       -value $n -command "setdriver $n"
 }
 . configure -menu .menu
 pack .f
 pack .f.form -side left
 pack .f.sourc -side left
 pack .cal -fill both -expand 1
 $cal : StretchPreview 1
 #tlview::viewtype [optcl::class $cal]

2Dcbuilder


Audela


xyd is a daemon for controlling the University of Hawaii 88" Telescope xy stage. [L9 ]


Kroc - a small thing for GrandTec IPCam on the french wiki: http://wfr.tcl.tk/1377


digiCamControl : .NET program for Windows with Tcl scripting hooks.