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
00051 #include "visp_bridge/camera.h"
00052
00053 #include <camera_calibration_parsers/parse.h>
00054 #include <visp/vpXmlParserCamera.h>
00055 #include <visp/vpCameraParameters.h>
00056
00057 #include <boost/program_options/options_description.hpp>
00058 #include <boost/program_options/variables_map.hpp>
00059 #include <boost/program_options/parsers.hpp>
00060 #include <boost/filesystem.hpp>
00061
00062 #include <iostream>
00063
00064 namespace po = boost::program_options;
00065 namespace fs = boost::filesystem;
00066
00067
00068 int main(int argc, const char ** argv)
00069 {
00070
00071 po::options_description desc("Usage examples:\n"
00072 " convert_cam_param_file -i input_cam_parameters.ini -c Dragonfly2-8mm-ccmop -w 640 -h 480\n"
00073 " convert_cam_param_file -i input_cam_parameters.yml -c Dragonfly2-8mm-ccmop -w 640 -h 480\n"
00074 " convert_cam_param_file -i input_cam_parameters.xml -c Dragonfly2-8mm-ccmop -w 640 -h 480\n"
00075 " convert_cam_param_file -i input_cam_parameters.xml -o input_cam_parameters.yml -c Dragonfly2-8mm-ccmop -w 640 -h 480\n"
00076 "Allowed options");
00077 desc.add_options()
00078 ("help", "produce help message")
00079 ("input,i", po::value<std::string>(), "input file path")
00080 ("output,o", po::value<std::string>(), "output file path")
00081 ("camera,c", po::value<std::string>(), "camera name")
00082 ("width,w", po::value<unsigned int>(), "camera width")
00083 ("height,h", po::value<unsigned int>(), "camera height")
00084 ("distortion,d", "Use distortion model")
00085 ("force-deleting,f", "Force deleting output file if this exists")
00086 ;
00087
00088 po::variables_map vm;
00089 po::store(po::parse_command_line(argc, argv, desc), vm);
00090 po::notify(vm);
00091
00092 if (vm.count("help")) {
00093 std::cout << desc << std::endl;
00094 return 0;
00095 }
00096
00097 if (!(vm.count("input") && vm.count("camera") && vm.count("width") && vm.count("height"))) {
00098 std::cout << "Missing options" << std::endl;
00099 std::cout << desc << std::endl;
00100 return 1;
00101 }
00102
00103 const fs::path inPath = vm["input"].as<std::string>();
00104 fs::path outPath;
00105
00106 vpXmlParserCamera parser;
00107 vpCameraParameters vispParam;
00108 sensor_msgs::CameraInfo rosParam;
00109 const unsigned int width = vm["width"].as<uint>();
00110 const unsigned int height = vm["height"].as<uint>();
00111
00112 if (inPath.extension() == std::string(".xml")){
00113
00114 if (vm.count("output")){
00115 outPath = vm["output"].as<std::string>();
00116 } else {
00117 outPath = inPath;
00118 outPath.replace_extension(fs::path(".ini"));
00119 }
00120
00121 if (boost::filesystem::exists(outPath)){
00122 if (vm.count("force-deleting")){
00123 boost::filesystem::remove(outPath);
00124 } else {
00125 std::cout << "Output file " << outPath.string() << " already exists. Use -f to force deleting"<< std::endl;
00126 return 1;
00127 }
00128 }
00129
00130 vpCameraParameters::vpCameraParametersProjType projModel;
00131
00132 if (vm.count("distortion")){
00133 projModel = vpCameraParameters::perspectiveProjWithDistortion;
00134 } else {
00135 projModel = vpCameraParameters::perspectiveProjWithoutDistortion;
00136 }
00137
00138 if (parser.parse(vispParam, inPath.string().c_str(), vm["camera"].as<std::string>().c_str(),
00139 projModel, width, height)!=vpXmlParserCamera::SEQUENCE_OK){
00140 std::cout << "Error parsing visp input file " << inPath.string() << std::endl;
00141 return 1;
00142 }
00143
00144 rosParam = visp_bridge::toSensorMsgsCameraInfo(vispParam, width, height);
00145
00146 if(!camera_calibration_parsers::writeCalibration(outPath.string(), vm["camera"].as<std::string>(), rosParam)){
00147 std::cout << "Error writing ros output file " << outPath.string() << std::endl;
00148 return 1;
00149 }
00150
00151 } else if (inPath.extension() == std::string(".ini") || inPath.extension() == std::string(".yml")){
00152
00153 if (vm.count("output")){
00154 outPath = vm["output"].as<std::string>();
00155 } else {
00156 outPath = inPath;
00157 outPath.replace_extension(fs::path(".xml"));
00158 }
00159
00160 if (boost::filesystem::exists(outPath)){
00161 if (vm.count("force-deleting")){
00162 boost::filesystem::remove(outPath);
00163 } else {
00164 std::cout << "Output file " << outPath.string() << " already exists. Use -f to force deleting"<< std::endl;
00165 return 1;
00166 }
00167 }
00168
00169 std::string cameraName = vm["camera"].as<std::string>();
00170
00171 if (!camera_calibration_parsers::readCalibration(inPath.string(), cameraName, rosParam)){
00172 std::cout << "Error parsing ros input file " << inPath.string() << std::endl;
00173 return 1;
00174 }
00175
00176 vispParam = visp_bridge::toVispCameraParameters(rosParam);
00177
00178 if(parser.save(vispParam, outPath.string().c_str(), cameraName, width, height)!=vpXmlParserCamera::SEQUENCE_OK){
00179 std::cout << "Error writing visp output file " << outPath.string() << std::endl;
00180 return 1;
00181 }
00182
00183 } else {
00184 std::cout << "Unknown input file format" << std::endl;
00185 return 1;
00186 }
00187
00188 std::cout << "Successfully created output file: " << outPath << std::endl;
00189
00190 return 0;
00191 }
00192