how to use a firefly mv camera with matlab on macos x


I am developing an algorithm for pedestrian detection using a laser range finder and a camera sensors. Well for the laser I'm limited to the currently available Hokuyo-URG04LX. But since there are quite a lot of cameras available in the lab it's more difficult to choose. The last few days I am messing with a Firefly MV FMVU-03MTM monochrome camera. It has two advantages:
  1. It's very rigid and can be screwed to a base. This is great since we want the camera to be in a fixed position in respect with the laser.
  2. It has a much much bigger sensor, which mean less noise, and better lense than any other available webcams I've tried. UPDATE: beware that lense comes with a noticable distortion
For the development I'm using matlab but the final implementation will be on opencv and ROS. So I had to see if it works well with these tools. There are a few tutorials already on how to make a Firefly camera work under ubuntu, ros, opencv. If you're interested in this you can have a look here. There is also a matlab mex wrapper for the dc1394 library from barryk, here. The problem is that the latter didn't work on my mac.
The libdc1394 examples work great but the wrapper doesn't seem to work. I tried downgrading to version 2.0.1 of libddc1394 but this didn't solve the problem either. So after two days of debugging I decided it's time to write my own wrapper of libdc1394 for matlab.

UPDATE: It was too difficult to abandon barryk's wrapper, since it's a great piece of code plus I'm too lazy. So I was using it along with some examples from libdc1394 to understand how I should proceed. After some more (and more and more...) debugging I realized what seem profound from the beginning: the guid of the camera is TOO big to fit into a uint32_t variable. So I changed some declarations and casts, within the camera initiation function, to uint64 and now it works.
To compile the whole think I've used the source files from libdc1394 directly, because using the library led matlab to crash. Also I had to make some changes to the filenames to avoid compiler misinterpretations. Here is the compiling command that I've used.
/Applications/MATLAB_R2011b.app/bin/mex -g dc1394mex.c bayer.c capture_gen.c control_gen.c conversions.c enumeration.c format7.c internal.c iso.c log.c register.c utils.c  -lIOKit -L/opt/local/lib /opt/local/lib/libusb-1.0.dylib -lm  -I/opt/local/include/libusb-1.0/ usb/capture_usb.c usb/control_usb.c macosx/control_mac.c macosx/capture_mac.c vendor/avt.c LDFLAGS='$LDFLAGS -framework Carbon -framework CoreFoundation -framework CoreServices' CFLAGS='$CFLAGS -Wall' -o dc1394
You can ommit the -g parameter. The renames are obvious if you compare them to the original libdc1394 source file/directory structure. This file contains all the source files from libdc1394 you'll need, renamed, plus the dc1394mex with the aforementioned modifications. God speed.
UPDATE: I've corrected the function that sets the feature mode and written a new one for setting manual values to them. I've also added support for gamma. I did all this because I had noticed a very strange flickering. At first I thought it might come from auto or semi-auto settings not being calibrated very well so I needed to manually set the features. Nevertheless the problem was caused by the room lighting, see here a related article from ptgrey. And here are the new files.

Things I've learned along this way:
  • writing matlab mex files  
  • debuging matlab mex files
  • steping into external libraries while debuging
  • using mac's ioregistryexplorer
My setup is: Macbook Unibody Late 2008 with intel core 2 duo, MacOS X Lion 10.7.3, Matlab R2011b
Libraries: libdc1394-2.2.0, libusb-1.0.8
Stathis Fotiadis 03 June 2012

blog comments powered by Disqus