Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00050 #include <sensor_msgs/distortion_models.h>
00051
00052 #include "camera.h"
00053
00054 namespace visp_bridge{
00055
00056 vpCameraParameters toVispCameraParameters(const sensor_msgs::CameraInfo& cam_info){
00057 vpCameraParameters cam;
00058
00059
00060 if (cam_info.K.size() != 3 * 3 || cam_info.K[0] == 0.)
00061 throw std::runtime_error ("uncalibrated camera");
00062
00063
00064 if (cam_info.P.size() != 3 * 4)
00065 throw std::runtime_error
00066 ("camera calibration P matrix has an incorrect size");
00067
00068 if (cam_info.distortion_model.empty ())
00069 {
00070 const double& px = cam_info.K[0 * 3 + 0];
00071 const double& py = cam_info.K[1 * 3 + 1];
00072 const double& u0 = cam_info.K[0 * 3 + 2];
00073 const double& v0 = cam_info.K[1 * 3 + 2];
00074 cam.initPersProjWithoutDistortion(px, py, u0, v0);
00075 return cam;
00076 }
00077
00078 if (cam_info.distortion_model == sensor_msgs::distortion_models::PLUMB_BOB)
00079 {
00080 const double& px = cam_info.P[0 * 4 + 0];
00081 const double& py = cam_info.P[1 * 4 + 1];
00082 const double& u0 = cam_info.P[0 * 4 + 2];
00083 const double& v0 = cam_info.P[1 * 4 + 2];
00084 cam.initPersProjWithoutDistortion(px, py, u0, v0);
00085 return cam;
00086 }
00087
00088 throw std::runtime_error ("unsupported distortion model");
00089
00090
00091 }
00092
00093 sensor_msgs::CameraInfo toSensorMsgsCameraInfo(vpCameraParameters& cam_info, unsigned int cam_image_width, unsigned int cam_image_height ){
00094 sensor_msgs::CameraInfo ret;
00095
00096 std::vector<double> D(5);
00097 D[0]=cam_info.get_kdu();
00098 D[1] = D[2] = D[3] = D[4] = 0.;
00099 ret.D = D;
00100 ret.P.assign(0.);
00101 ret.K.assign(0.);
00102 ret.R.assign(0.);
00103
00104 ret.R[0] = 1.;
00105 ret.R[1 * 3 + 1] = 1.;
00106 ret.R[2 * 3 + 2] = 1.;
00107
00108 ret.P[0 * 4 + 0] = cam_info.get_px();
00109 ret.P[1 * 4 + 1] = cam_info.get_py();
00110 ret.P[0 * 4 + 2] = cam_info.get_u0();
00111 ret.P[1 * 4 + 2] = cam_info.get_v0();
00112 ret.P[2 * 4 + 2] = 1;
00113
00114
00115 ret.K[0 * 3 + 0] = cam_info.get_px();
00116 ret.K[1 * 3 + 1] = cam_info.get_py();
00117 ret.K[0 * 3 + 2] = cam_info.get_u0();
00118 ret.K[1 * 3 + 2] = cam_info.get_v0();
00119 ret.K[2 * 3 + 2] = 1;
00120
00121 ret.distortion_model = "plumb_bob";
00122 ret.binning_x = 0;
00123 ret.binning_y = 0;
00124 ret.width = cam_image_width;
00125 ret.height = cam_image_height;
00126
00127 return ret;
00128 }
00129 }
00130