Spare Time Labs 2.0

Welcome


EazyCNC


jDraft 2.0




PureJavaComm


PIC CDC ACM


Weather


Ten-Buck Furnace



H8S Bootloader



Camera Calibration



Multitouch



Myford VFD


Fun with HC08


bl08


printf II


Java Goes Native



Densitometer


printf


jApp


Igloo


New Furnace


New Furnace
Part II


Linux 101


H8S/gcc


Quickie


Gas Fired Furnace


Down Memory Lane


Exlibris


Wheel Patterns


Glitches


CHIP-8


eDice


Animato


jDraft


JNA Benchmark


Contact Info
Created 15.4.2009

Camera Calibration Toolbox for Octave

Here are some notes I jotted down when adapting 'Camera Calibration Toolbox for Matlab' for use with Octave. I've cleaned them up a bit and whipped up a this webpage to help myself and others later when I need to re-visit this issue.

Octave, in case you did not know, is a Free (in every sense of the word) Matlab clone that is able to run most Matlab scripts. Matlab is great tool for matrix math that has been around for years. It used to be reasonably priced but nowdays the price is extraorbitant and predatory and the licensing policy leaves a lot to be desired for, especially if all you need is to run some little nice script (like the Toolbox here) that some good man (or woman for that matter) has made available on the net. Fortunately we have a good alternative: Octave.

Octave is available for Mac OS X, Linux and Windows. Since I'm mainly a Mac user the following has some Mac specific notes but a lot of the info here is totally generic as Octave scripts are pretty much platform agnostic. I used Octave version 3.0.3, for which you can download the Mac OS X pre-build version of Octave from octave.sourceforge.net, which also includes gnuplot that you will need. However, before going that route and downloading it here you may want to read more.

The Camera Calibration Toolbox uses some features that are not part of the basic Octave distribution. Most of the missing parts can be found from Octave Forge. However, I found that the easiest way to install Octave AND all the other necessary gear is through MacPorts. This is not the fastest way to install Octave as this involves building the code on your machine but it was the only way in which I was able to get all the necessary parts to install without resorting to hacking.

Without further ado, after installing MacPorts the following should install everything you need to run Camera Calibration Toolbox. Open the terminal and enter following commands:

sudo port install octave sudo port install gnuplot sudo port install octave-plot sudo port install octave-image sudo port install imagemagick

Note that you will need to enter admin passwords and each step can take quite a long time, upto some hours, but in the end it should finish either succesfully or report an error.

(I'm not 100% sure if gnuplot and/or octave-plot are necessary but according to my notes I installed them so I included them here, also imagemagick may not be necessary if you only use '.jpg' and '.png' image formats.)

Next download the Toolbox archive, uncompress it somewhere and add the directory to your path. To do that you can edit your profile (type open ~/.bash_profile) and add a line like:

export PATH=${PATH}:~/TOOLBOX_calib
or you can just (temporarily) add it to the Octave path from within Octave shell with 'addpath' command:

octave:1> addpath ~/TOOLBOX_calib/

Most of the Toolbox code runs pretty much as-is which is a testimony to the Octave Matlab compatibility. The one part that does not run is the main function calib_gui.m, that displays a bunch of buttons to run the various functions in the Toolbox. Since these buttons are just sugar coating for people who are not fit to use proper tools like Octave, just forget that file. Instead open (with text editor) the other equally useless file 'calib_gui_normal.m' and have a peek inside. This will reveal the name of the functions (and thus the names of correspoding '.m' files) behind the buttons. To run those, just type the function names on to the Octave shell prompt. You can also find the names behind the buttons from this page.

You will probabply want to go through the 'First calibration example' described on the Toolbox home page. The first step is to read in the images. The documentation tells you to click the 'Image names' button. Peeping inside the 'calib_gui_normal.m' file you'll see that function name is actualy 'data_calib', so type that instead:

octave:1> data_calib

Apply the above procedure to all of the steps the camera calibration and you should be able to go through the first example. You may stumble accors the following error:

parse error near line 282 of file /Users/nyholku/TOOLBOX_calib/click_ima_calib.m syntax error >>> zoom on;

This is an error (bug) in Octave zoom command. Since this command does not seem to do anything for us in this context anyway, you can just delete it (or the 'on' keyword). So open the offending file with a text editor, goto the indicated line and delete it.

There is a similar issue with 'rotate3d on'. Just delete it. With above instructions you should be able to work through most of the camera calibration.

You will also get the something like following when running ext_calib:

warning: set: invalid property `b-'
warning: set: invalid property `r-'
warning: unknown axis option 'vis3d'
warning: set: invalid property `Name'
warning: set: invalid property `NumberTitle'
error: `uicontrol' undefined near line 204 column 21
error: evaluating assignment expression near line 204, column 19
error: evaluating if command near line 203, column 5
error: evaluating if command near line 202, column 1
error: near line 208 of file `/Users/nyholku/TOOLBOX_calib/ext_calib.m'

which is because Octave does not (yet) have the uicontrol function.

You can ignore this as the plot that this function is supposed to create is already generated and visible when the error occurs. To get rid of the error just delete everything after line 195 or thereabouts. Of course you will not be able to use buttons that the uicontrol call would generate but if you look at the code you'll see that the buttons realy just set the variable 'show_camera' to 1 or 2 or call function 'ext_calib2', and you can do this manually from the command line. Ok, that's about it from me for now. Hope this help someone out there. I've not run all the Toolbox functions but the basic camera calibration functions provided a great reference implementation when I was implementing something similar in Java.

Many thanks for Jean-Yves Bouguet for making the Toolbox publicly available and kudos to all the good folks in the GNU Octave project.

br Kusti