User Tools

Site Tools


Installation ( levmar-2.4 and ubuntu 9.04 )

1. download from




- Before installation, you have to install package “liblapack-dev” and “libf2c2-dev”. Otherwise, you will have an error,

/usr/bin/ld: cannot find -llapack


/usr/bin/ld: cannot find -lf2c

Anyway, you also have a problem with f2c,

/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/ undefined reference to `MAIN__'

following suggestion here.

Just add

-u MAIN__

to Makefile. So change from

lmdemo: $(DEMOBJS) liblevmar.a
$(CC) $(LDFLAGS) $(DEMOBJS) -o lmdemo -llevmar $(LIBS) -lm


lmdemo: $(DEMOBJS) liblevmar.a
$(CC) $(LDFLAGS) $(DEMOBJS) -o lmdemo -llevmar $(LIBS) -lm -u MAIN__

Test by compile demo

gcc lmdemo.c -o lmdemo1 -L<your levmar folder> -lm -llapack -llevmar

For example,

gcc lmdemo.c -o lmdemo1 -L/mnt/disk/AIT/OpenCV/levmar-2 -lm -llapack -llevmar


dlevmar_dif(costFunc, p0, x0, mlevmar, nlevmar, 1000, opts, info, NULL, NULL, NULL); // no Jacobian

void costFunc(double *p, double *tran_x, int m, int n, void *data);

What levmar did is change p, we have change tran_x.

levmar will compare tran_x to x0, then change p again to optimize p0 ( by minimize sum(tran_xi-x0i)^2 ).

Therefore, you can put any order of params into p0, x0. For example, you can put x0 = [x; x'] or x0 = [x'; x] or whatever.

ref : dsin

opencv/tutorial/using_levmar_to_optimize_cost_function.txt · Last modified: 2014/10/31 06:44 (external edit)