diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt index f5a20d852..0e6dd14fc 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt @@ -1,11 +1,6 @@ cmake_minimum_required(VERSION 2.8) project( PNP_DEMO ) -ADD_DEFINITIONS( - -std=c++11 - # Other flags -) - find_package( OpenCV REQUIRED ) include_directories( diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.cpp index 4277e567a..d97afdb73 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.cpp @@ -1,4 +1,5 @@ #include "CsvReader.h" +#include "Utils.h" /** The default constructor of the CSV reader Class */ CsvReader::CsvReader(const std::string &path, const char &separator){ @@ -27,8 +28,8 @@ void CsvReader::readPLY(std::vector &list_vertex, std::vector &list_vertex, std::vector &list_vertex, std::vector tmp_triangle(3); - tmp_triangle[0] = StringToNumber(id0); - tmp_triangle[1] = StringToNumber(id1); - tmp_triangle[2] = StringToNumber(id2); + tmp_triangle[0] = StringToInt(id0); + tmp_triangle[1] = StringToInt(id1); + tmp_triangle[2] = StringToInt(id2); list_triangles.push_back(tmp_triangle); count++; diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.h b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.h index 1df3835d7..ab94e4c1b 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.h +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvReader.h @@ -5,7 +5,6 @@ #include #include -#include "Mesh.h" using namespace std; using namespace cv; diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.cpp index 65a8beaa5..4671fd098 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/CsvWriter.cpp @@ -1,5 +1,5 @@ -#include #include "CsvWriter.h" +#include "Utils.h" CsvWriter::CsvWriter(const std::string &path, const std::string &separator){ _file.open(path.c_str(), std::ofstream::out); @@ -17,9 +17,9 @@ void CsvWriter::writeXYZ(const std::vector &list_points3d) std::string x, y, z; for(unsigned int i = 0; i < list_points3d.size(); ++i) { - x = std::to_string(list_points3d[i].x); - y = std::to_string(list_points3d[i].y); - z = std::to_string(list_points3d[i].z); + x = FloatToString(list_points3d[i].x); + y = FloatToString(list_points3d[i].y); + z = FloatToString(list_points3d[i].z); _file << x << _separator << y << _separator << z << std::endl; } @@ -31,18 +31,18 @@ void CsvWriter::writeUVXYZ(const std::vector &list_points3d, const std::string u, v, x, y, z, descriptor_str; for(int i = 0; i < list_points3d.size(); ++i) { - u = std::to_string(list_points2d[i].x); - v = std::to_string(list_points2d[i].y); - x = std::to_string(list_points3d[i].x); - y = std::to_string(list_points3d[i].y); - z = std::to_string(list_points3d[i].z); + u = FloatToString(list_points2d[i].x); + v = FloatToString(list_points2d[i].y); + x = FloatToString(list_points3d[i].x); + y = FloatToString(list_points3d[i].y); + z = FloatToString(list_points3d[i].z); _file << u << _separator << v << _separator << x << _separator << y << _separator << z; for(int j = 0; j < 32; ++j) { std::cout << descriptors.at(i,j) << std::endl; - descriptor_str = std::to_string(descriptors.at(i,j)); + descriptor_str = FloatToString(descriptors.at(i,j)); _file << _separator << descriptor_str; } _file << std::endl; diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp index ec8a69ccb..f66a10dd2 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp @@ -6,7 +6,6 @@ */ #include -#include #include "PnPProblem.h" #include "ModelRegistration.h" @@ -30,9 +29,9 @@ double thickness_circ = -1; // Draw a text with the question point void drawQuestion(cv::Mat image, cv::Point3f point, cv::Scalar color) { - std::string x = boost::lexical_cast< std::string >((int)point.x); - std::string y = boost::lexical_cast< std::string >((int)point.y); - std::string z = boost::lexical_cast< std::string >((int)point.z); + std::string x = IntToString((int)point.x); + std::string y = IntToString((int)point.y); + std::string z = IntToString((int)point.z); std::string text = " Where is point (" + x + "," + y + "," + z + ") ?"; cv::putText(image, text, cv::Point(25,50), fontFace, fontScale, color, thickness_font, 8); @@ -53,7 +52,7 @@ void drawText2(cv::Mat image, std::string text, cv::Scalar color) // Draw a text with the frame ratio void drawFPS(cv::Mat image, double fps, cv::Scalar color) { - std::string fps_str = boost::lexical_cast< std::string >((int)fps); + std::string fps_str = IntToString((int)fps); std::string text = fps_str + " FPS"; cv::putText(image, text, cv::Point(500,50), fontFace, fontScale, color, thickness_font, 8); } @@ -61,7 +60,7 @@ void drawFPS(cv::Mat image, double fps, cv::Scalar color) // Draw a text with the frame ratio void drawConfidence(cv::Mat image, double confidence, cv::Scalar color) { - std::string conf_str = boost::lexical_cast< std::string >((int)confidence); + std::string conf_str = IntToString((int)confidence); std::string text = conf_str + " %"; cv::putText(image, text, cv::Point(500,75), fontFace, fontScale, color, thickness_font, 8); } @@ -69,8 +68,8 @@ void drawConfidence(cv::Mat image, double confidence, cv::Scalar color) // Draw a text with the number of entered points void drawCounter(cv::Mat image, int n, int n_max, cv::Scalar color) { - std::string n_str = boost::lexical_cast< std::string >(n); - std::string n_max_str = boost::lexical_cast< std::string >(n_max); + std::string n_str = IntToString(n); + std::string n_max_str = IntToString(n_max); std::string text = n_str + " of " + n_max_str + " points"; cv::putText(image, text, cv::Point(500,50), fontFace, fontScale, color, thickness_font, 8); } @@ -86,10 +85,10 @@ void drawPoints(cv::Mat image, std::vector &list_points_2d, std::ve // Draw Selected points cv::circle(image, point_2d, radius, color, -1, lineType ); - std::string idx = boost::lexical_cast< std::string >(i+1); - std::string x = boost::lexical_cast< std::string >((int)point_3d.x); - std::string y = boost::lexical_cast< std::string >((int)point_3d.y); - std::string z = boost::lexical_cast< std::string >((int)point_3d.z); + std::string idx = IntToString(i+1); + std::string x = IntToString((int)point_3d.x); + std::string y = IntToString((int)point_3d.y); + std::string z = IntToString((int)point_3d.z); std::string text = "P" + idx + " (" + x + "," + y + "," + z +")"; point_2d.x = point_2d.x + 10; @@ -273,3 +272,24 @@ cv::Mat euler2rot(const cv::Mat & euler) return rotationMatrix; } + +int StringToInt ( const std::string &Text ) +{ + std::istringstream ss(Text); + int result; + return ss >> result ? result : 0; +} + +std::string FloatToString ( float Number ) +{ + std::ostringstream ss; + ss << Number; + return ss.str(); +} + +std::string IntToString ( int Number ) +{ + std::ostringstream ss; + ss << Number; + return ss.str(); +} diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.h b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.h index b6a227fbd..d51eb28b3 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.h +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.h @@ -9,9 +9,9 @@ #define UTILS_H_ #include -#include #include +#include "PnPProblem.h" // Draw a text with the question point void drawQuestion(cv::Mat image, cv::Point3f point, cv::Scalar color); @@ -53,6 +53,9 @@ cv::Mat quat2rot(cv::Mat &q); cv::Mat euler2rot(const cv::Mat & euler); cv::Mat rot2euler(const cv::Mat & rotationMatrix); cv::Mat quat2euler(const cv::Mat & q); +int StringToInt ( const std::string &Text ); +std::string FloatToString ( float Number ); +std::string IntToString ( int Number ); class Timer { @@ -69,7 +72,4 @@ private: double tstart, tstop, ttime; }; - - - #endif /* UTILS_H_ */ diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp index 750f1472c..ff00e24e8 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "cv.h" #include "highgui.h" @@ -238,7 +237,7 @@ int main(int argc, char *argv[]) // -- Step 3: Estimate the pose using RANSAC approach pnp_detection.estimatePoseRANSAC( list_points3d_model_match, list_points2d_scene_match, - cv::DLS, inliers_idx, + cv::ITERATIVE, inliers_idx, iterationsCount, reprojectionError, confidence ); // -- Step 4: Catch the inliers keypoints to draw @@ -330,9 +329,9 @@ int main(int argc, char *argv[]) // Draw some debug text int inliers_int = inliers_idx.rows; int outliers_int = good_matches.size() - inliers_int; - std::string inliers_str = boost::lexical_cast< std::string >(inliers_int); - std::string outliers_str = boost::lexical_cast< std::string >(outliers_int); - std::string n = boost::lexical_cast< std::string >(good_matches.size()); + std::string inliers_str = IntToString(inliers_int); + std::string outliers_str = IntToString(outliers_int); + std::string n = IntToString(good_matches.size()); std::string text = "Found " + inliers_str + " of " + n + " matches"; std::string text2 = "Inliers: " + inliers_str + " - Outliers: " + outliers_str; diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp index 4f8903c8f..3b2517b22 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp @@ -1,5 +1,4 @@ #include -#include #include "Mesh.h" #include "Model.h" @@ -261,12 +260,12 @@ int main(int argc, char *argv[]) std::vector list_points_out = model.get_points2d_out(); // Draw some debug text - std::string num = boost::lexical_cast< std::string >(list_points_in.size()); + std::string num = IntToString(list_points_in.size()); std::string text = "There are " + num + " inliers"; drawText(img_vis, text, green); // Draw some debug text - num = boost::lexical_cast< std::string >(list_points_out.size()); + num = IntToString(list_points_out.size()); text = "There are " + num + " outliers"; drawText2(img_vis, text, red); diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_verification.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_verification.cpp index 1c6b15bed..75456588d 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_verification.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_verification.cpp @@ -1,5 +1,4 @@ #include -#include #include "cv.h" #include "highgui.h"