views:

272

answers:

3

I would like to use use numpy's least square algorithm to solve for a camera matrix from 6 known 3D -> 2D point correspondence.

I have been using this website as a reference:

http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL%5FCOPIES/OWENS/LECT9/node4.html

Currently my camera matrix seems to have very small values:

[[ -1.01534118e-11 3.87508914e-11 -2.75515236e-11 5.57599976e+02]

[ -1.84008233e-11 2.78083388e-11 -9.67788509e-11 9.77599976e+02]

[ -2.59237076e-14 -8.57647287e-15 -9.09272657e-14 1.00000000e+00]]

I would like to be able to constrain the numpy solver to prevent it from solving for the trivial solution where the Camera matrix is nearly zero. Does anyone know how to constrain numpy.linalg.lstsqr?

+1  A: 

I suspect you may need to use the fmin_* routines in scipy.optimize. The optimization tutorial covers basic use and scipy.optimize.fmin_slsqp can include constraints.

Rupert Nash
You may be right, fmin_slsqp looks to do what I want. I need to get scipy installed properly.Also if anyone can point me towards example code solving for a camera matrix using linear optimization that would be helpful.
freakTheMighty
Scipy is a bit evil to build from source. Personally, I use the Enthought Python Distribution (http://www.enthought.com/products/epd.php) because it only takes 5 mins to install on most platforms and then gives a consistent environment. Also excellent is Sage (http://www.sagemath.org/), which I used before EPD.
Rupert Nash
+2  A: 

I need to get scipy installed properly

Just a note for installing scipy, ubuntu distributions since 8.04 have had a broken scipy build. That has been taken care of in the latest 9.10 beta build. You could build scipy from scratch, but it isn't in general an easy thing to do. Just a heads up because it took some effort for us here to get that figured out. Maybe it'll save you some frustration =)

Rayjan
A: 

Would least squares staying near a point x0 be of any use, i.e. is there a camera matrix x0 you want to be near to ?
"Keep away from some x0" is non-convex, nasty; keep near x0 or x1 ..., i.e. minimize
|Ax-b|^2 + w^2 (|x-x0|^2 + |x-x1|^2 + ...) is easy.

Denis