ceres_costs_utils_test.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (Apache License)
00003  *
00004  * Copyright (c) 2014, Southwest Research Institute
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  *   http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00019 #ifndef CERES_COSTS_UTILS_TEST_HPP_
00020 #define CERES_COSTS_UTILS_TEST_HPP_
00021 
00022 #include "ceres/ceres.h"
00023 #include "ceres/rotation.h"
00024 #include <industrial_extrinsic_cal/basic_types.h>
00025 
00026 namespace industrial_extrinsic_cal
00027 {
00028 
00029 /* local prototypes of helper functions */
00030 
00040 void printQTasH(double qx, double qy, double qz, double qw, double tx, double ty, double tz);
00041 
00050 void printAATasH(double ax, double ay, double az, double tx, double ty, double tz);
00051 
00060 void printAATasHI(double ax, double ay, double az, double tx, double ty, double tz);
00061 
00067 void printAAasEuler(double ax, double ay, double az);
00068 
00073 void printCameraParameters(CameraParameters C, std::string words);
00074 
00079 Observation projectPointWithDistortion(CameraParameters camera_parameters, Point3d point);
00080 Observation projectPointNoDistortion(CameraParameters camera_params, Point3d point_to_project);
00081 
00082 Observation projectPointWithDistortion(CameraParameters C, Point3d P)
00083 {
00084   double p[3];
00085   double pt[3];
00086   pt[0] = P.x;
00087   pt[1] = P.y;
00088   pt[2] = P.z;
00089 
00090   /* transform point into camera frame */
00091   /* note, camera transform takes points from camera frame into world frame */
00092   double aa[3];
00093   aa[0]=C.pb_extrinsics[0];
00094   aa[1]=C.pb_extrinsics[1];
00095   aa[2]=C.pb_extrinsics[2];
00096   ceres::AngleAxisRotatePoint(aa, pt, p);
00097 
00098   // apply camera translation
00099   double xp1 = p[0] + C.pb_extrinsics[3];
00100   double yp1 = p[1] + C.pb_extrinsics[4];
00101   double zp1 = p[2] + C.pb_extrinsics[5];
00102   //p[0] +=C.pb_extrinsics[3];
00103   //p[1] +=C.pb_extrinsics[4];
00104   //p[2] +=C.pb_extrinsics[5];
00105 
00106   double xp = xp1 / zp1;
00107   double yp = yp1 / zp1;
00108 
00109   // calculate terms for polynomial distortion
00110   double r2 = xp * xp + yp * yp;
00111   double r4 = r2 * r2;
00112   double r6 = r2 * r4;
00113 
00114   double xp2 = xp * xp; /* temporary variables square of others */
00115   double yp2 = yp * yp;
00116 
00117   /* apply the distortion coefficients to refine pixel location */
00118   double xpp = xp + C.distortion_k1 * r2 * xp + C.distortion_k2 * r4 * xp +
00119       C.distortion_k3 * r6 * xp + C.distortion_p2 * (r2 + 2 * xp2) + 2 * C.distortion_p1 * xp * yp;
00120   double ypp = yp + C.distortion_k1 * r2 * yp + C.distortion_k2 * r4 * yp +
00121       C.distortion_k3 * r6 * yp + C.distortion_p1 * (r2 + 2 * yp2) + 2 * C.distortion_p2 * xp * yp;
00122 
00123   /* perform projection using focal length and camera center into image plane */
00124   Observation O;
00125   O.point_id = 0;
00126   O.image_loc_x = C.focal_length_x * xpp + C.center_x;
00127   O.image_loc_y = C.focal_length_y * ypp + C.center_y;
00128   return (O);
00129 }
00130 
00131 Observation projectPointNoDistortion(CameraParameters C, Point3d P)
00132 {
00133   double p[3];                  // rotated into camera frame
00134   double point[3];              // world location of point
00135   double aa[3];                 // angle axis representation of camera transform
00136   double tx = C.position[0];    // location of origin in camera frame x
00137   double ty = C.position[1];    // location of origin in camera frame y
00138   double tz = C.position[2];    // location of origin in camera frame z
00139   double fx = C.focal_length_x; // focal length x
00140   double fy = C.focal_length_y; // focal length y
00141   double cx = C.center_x;       // optical center x
00142   double cy = C.center_y;       // optical center y
00143 
00144   aa[0] = C.angle_axis[0];
00145   aa[1] = C.angle_axis[1];
00146   aa[2] = C.angle_axis[2];
00147   point[0] = P.x;
00148   point[1] = P.y;
00149   point[2] = P.z;
00150 
00152   ceres::AngleAxisRotatePoint(aa, point, p);
00153 
00154   // apply camera translation
00155   double xp1 = p[0] + tx;
00156   double yp1 = p[1] + ty;
00157   double zp1 = p[2] + tz;
00158 
00159   // scale into the image plane by distance away from camera
00160   double xp = xp1 / zp1;
00161   double yp = yp1 / zp1;
00162 
00163   // perform projection using focal length and camera center into image plane
00164   Observation O;
00165   O.image_loc_x = fx * xp + cx;
00166   O.image_loc_y = fy * yp + cy;
00167   return (O);
00168 }
00169 
00170 } // end of namespace
00171 #endif


industrial_extrinsic_cal
Author(s): Chris Lewis
autogenerated on Wed Aug 26 2015 12:00:27