libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd/cvd camera.h


From: Edward Rosten
Subject: [libcvd-members] libcvd/cvd camera.h
Date: Fri, 29 Aug 2008 20:29:41 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        08/08/29 20:29:41

Modified files:
        cvd            : camera.h 

Log message:
        Square Harris camera model. This kind of camera model is for when the 
aspect 
        ratio of the pixels is known to be 1 (ie from hte datasheet).
        
        The implementation is slightly messy at the moment, since it has room 
for two
        focal lengths, and always forces the second to be zero (along with 
derivatives
        with respect to this parameter). This allows it to work in 
calibrate.cxx, which
        assumes that there will always be 4 linear parameters.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/camera.h?cvsroot=libcvd&r1=1.20&r2=1.21

Patches:
Index: camera.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/camera.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- camera.h    29 Aug 2008 03:33:26 -0000      1.20
+++ camera.h    29 Aug 2008 20:29:40 -0000      1.21
@@ -364,6 +364,145 @@
                        mutable TooN::Vector<2> my_last_camframe;
        };
 
+       ///This camera class is a very similar to the Harris model.
+       ///However, it forces the pixel aspect ratio to be unity.
+       class SquareHarris{
+
+               private:
+                       TooN::Vector<2> radial_distort(const TooN::Vector<2>& 
camframe) const
+                       {
+                               double r2 = camframe*camframe;
+                               return camframe / sqrt(1 + 
my_camera_parameters[4] * r2);
+                       }
+                       
+
+               public:
+                       /// The number of parameters in the camera
+                       static const int num_parameters=5;
+    
+                       ///Load parameters from a stream 
+                       ///@param is The stream to use
+                       inline void load(std::istream& is);
+
+                       /// Save parameters to a stream 
+                       ///@param os The stream to use
+                       inline void save(std::ostream& os)
+                       {
+                               os << my_camera_parameters;
+                       }
+
+
+                       /// Fast linear projection for working out what's there
+                       inline TooN::Vector<2> linearproject(const 
TooN::Vector<2>& camframe, double scale=1) const
+                       {
+                               return TooN::Vector<2>(scale * (camframe* 
my_camera_parameters[0]) + my_camera_parameters.slice<2,2>());
+                       }
+
+                       /// Project from Euclidean camera frame to image plane
+                       inline TooN::Vector<2> project(const TooN::Vector<2>& 
camframe) const 
+                       {
+                               my_last_camframe = camframe;
+                               return linearproject(radial_distort(camframe));
+                       }
+
+                       /// Project from image plane to a Euclidean camera
+                       inline TooN::Vector<2> unproject(const TooN::Vector<2>& 
imframe)
+                       {
+                               //Undo the focal length and optic axis.
+                               TooN::Vector<2> mod_camframe;
+                               mod_camframe[0] = 
(imframe[0]-my_camera_parameters[2])/my_camera_parameters[0];
+                               mod_camframe[1] = 
(imframe[1]-my_camera_parameters[3])/my_camera_parameters[0];
+                               double rprime2 = mod_camframe*mod_camframe;
+                               my_last_camframe =  mod_camframe / sqrt(1 - 
my_camera_parameters[4] * rprime2);
+                               return my_last_camframe;
+                       }
+                       
+                       /// Get the derivative of image frame wrt camera frame 
at the last computed projection
+                       /// in the form \f$ \begin{bmatrix} \frac{\partial 
\text{im1}}{\partial \text{cam1}} & \frac{\partial \text{im1}}{\partial 
\text{cam2}} \\ \frac{\partial \text{im2}}{\partial \text{cam1}} & 
\frac{\partial \text{im2}}{\partial \text{cam2}} \end{bmatrix} \f$
+                       inline TooN::Matrix<2,2> get_derivative() const
+                       {
+                               TooN::Matrix<2,2> J;
+
+                               double xc = my_last_camframe[0];
+                               double yc = my_last_camframe[1];
+
+                               double f= my_camera_parameters[0];
+                               double a = my_camera_parameters[4];
+
+                               double g = 1/sqrt(1 + a * (xc*xc + yc*yc));
+                               double g3= g*g*g;
+                               
+                               J[0][0] = f * (g - 2 * a * xc*xc*g3);
+                               J[0][1] = -2 * f * a * xc * yc * g3;
+                               J[1][0] = -2 * f * a * xc * yc * g3;
+                               J[1][1] = f * (g - 2 * a * yc*yc*g3);
+
+                               return J;
+                       }
+
+                       /// Get the motion of a point with respect to each of 
the internal camera parameters
+                       inline TooN::Matrix<num_parameters,2> 
get_parameter_derivs() const 
+                       {
+                               TooN::Vector<2> mod_camframe = 
radial_distort(my_last_camframe);
+
+                               TooN::Matrix<5, 2> result;
+
+                               double xc = my_last_camframe[0];
+                               double yc = my_last_camframe[1];
+                               double r2 = xc*xc + yc*yc;
+
+                               double f= my_camera_parameters[0];
+                               double a = my_camera_parameters[4];
+
+                               double g = 1/sqrt(1 + a * r2);
+                               double g3= g*g*g;
+
+                               //Derivatives of x_image:
+                               result[0][0] = mod_camframe[0];
+                               result[1][0] = 0;
+                               result[2][0] = 1;
+                               result[3][0] = 0;
+                               result[4][0] = - f * xc * r2 / 2 * g3;
+
+
+
+                               //Derivatives of y_image:
+                               result[0][1] = mod_camframe[1];
+                               result[1][1] = 0;
+                               result[2][1] = 0;
+                               result[3][1] = 1;
+                               result[4][1] = - f * yc * r2 / 2 * g3;
+
+                               return result;
+                       }
+
+                       /// Get the component of the motion of a point in the 
direction provided 
+                       ///     with respect to each of the internal camera 
parameters
+                       /// @param direction The (x,y) direction to use
+                       inline TooN::Vector<num_parameters> 
get_parameter_derivs(const TooN::Vector<2>& direction) const
+                       {
+                               return get_parameter_derivs() * direction;
+                       }       
+
+                       /// Update the internal camera parameters by adding the 
vector given
+                       /// @param updates Update vector in the format 
+                       /// \f$ \begin{pmatrix}\Delta f_u & \Delta f_v & \Delta 
u_0 & \Delta v_0 & \Delta c\end{pmatrix} \f$
+                       //inline void update(const 
TooN::Vector<num_parameters>& updates);
+
+                       /// Returns the vector of camera parameters in the 
format
+                       /// \f$ \begin{pmatrix}f_u & f_v & u_0 & v_0 & 
c\end{pmatrix} \f$
+                       inline TooN::Vector<num_parameters>& get_parameters() 
+                       {
+                               my_camera_parameters[1] = 0;
+                               return my_camera_parameters;
+                       }
+
+                 private:
+                       TooN::Vector<num_parameters> my_camera_parameters; // 
f_u, f_v, u_0, v_0, alpha
+                       mutable TooN::Vector<2> my_last_camframe;
+       };
+
+
 
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]