Update tutorial

This commit is contained in:
edgarriba 2014-08-05 20:06:47 +02:00
parent 7b0be9cf8f
commit 43301096d3
9 changed files with 61 additions and 49 deletions

View File

@ -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(

View File

@ -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<cv::Point3f> &list_vertex, std::vector<std::
{
getline(liness, tmp_str, _separator);
getline(liness, n);
if(tmp_str == "vertex") num_vertex = StringToNumber(n);
if(tmp_str == "face") num_triangles = StringToNumber(n);
if(tmp_str == "vertex") num_vertex = StringToInt(n);
if(tmp_str == "face") num_triangles = StringToInt(n);
}
if(tmp_str == "end_header") end_header = true;
}
@ -45,9 +46,9 @@ void CsvReader::readPLY(std::vector<cv::Point3f> &list_vertex, std::vector<std::
getline(liness, z);
cv::Point3f tmp_p;
tmp_p.x = StringToNumber(x);
tmp_p.y = StringToNumber(y);
tmp_p.z = StringToNumber(z);
tmp_p.x = StringToInt(x);
tmp_p.y = StringToInt(y);
tmp_p.z = StringToInt(z);
list_vertex.push_back(tmp_p);
count++;
@ -67,9 +68,9 @@ void CsvReader::readPLY(std::vector<cv::Point3f> &list_vertex, std::vector<std::
getline(liness, id2);
std::vector<int> 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++;

View File

@ -5,7 +5,6 @@
#include <fstream>
#include <opencv2/core/core.hpp>
#include "Mesh.h"
using namespace std;
using namespace cv;

View File

@ -1,5 +1,5 @@
#include <string>
#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<cv::Point3f> &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<cv::Point3f> &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<float>(i,j) << std::endl;
descriptor_str = std::to_string(descriptors.at<float>(i,j));
descriptor_str = FloatToString(descriptors.at<float>(i,j));
_file << _separator << descriptor_str;
}
_file << std::endl;

View File

@ -6,7 +6,6 @@
*/
#include <iostream>
#include <boost/lexical_cast.hpp>
#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<cv::Point2f> &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();
}

View File

@ -9,9 +9,9 @@
#define UTILS_H_
#include <iostream>
#include <time.h>
#include <cv.h>
#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_ */

View File

@ -1,6 +1,5 @@
#include <iostream>
#include <time.h>
#include <boost/lexical_cast.hpp>
#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;

View File

@ -1,5 +1,4 @@
#include <iostream>
#include <boost/lexical_cast.hpp>
#include "Mesh.h"
#include "Model.h"
@ -261,12 +260,12 @@ int main(int argc, char *argv[])
std::vector<cv::Point2f> 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);

View File

@ -1,5 +1,4 @@
#include <iostream>
#include <boost/lexical_cast.hpp>
#include "cv.h"
#include "highgui.h"