I am studying 3d point cloud and I am using opencv surface matchig module But I have an error I cant understand
My code is :
#include "stdafx.h"
#include <iostream>
#include <vector>
#include "opencv2/core/utility.hpp"
#include "opencv2\opencv_modules.hpp"
#include "opencv2\surface_matching.hpp"
#include "opencv2\surface_matching\ppf_helpers.hpp"
using namespace std;
using namespace cv;
using namespace cv::ppf_match_3d;
static void help(const string& errorMessage)
{
cout << "Program init error : " << errorMessage << endl;
cout << "\nUsage : ppf_matching [input model file] [input scene file]" << endl;
cout << "\nPlease start again with new parameters" << endl;
}
int main(int argc, char** argv)
{
// welcome message
cout << "****************************************************" << endl;
cout << "* Surface Matching demonstration : demonstrates the use of surface matching"
" using point pair features." << endl;
cout << "* The sample loads a model and a scene, where the model lies in a different"
" pose than the training.\n* It then trains the model and searches for it in the"
" input scene. The detected poses are further refined by ICP\n* and printed to the "
" standard output." << endl;
cout << "****************************************************" << endl;
/* if (argc < 2)
{
help("Not enough input arguments");
exit(1);
}*/
/*#if (defined __x86_64__ || defined _M_X64)
cout << "Running on 64 bits" << endl;
#else
cout << "Running on 32 bits" << endl;
#endif
#ifdef _OPENMP
cout << "Running with OpenMP" << endl;
#else
cout << "Running without OpenMP and without TBB" << endl;
#endif*/
string modelFileName = "C://opencv_contrib-master//modules//surface_matching//samples//data//parasaurolophus_6700";
string sceneFileName = "C://opencv_contrib-master//modules//surface_matching//samples//data//parasaurolophus_low_normals2";
Mat pc = loadPLYSimple(modelFileName.c_str(), 1);
// Now train the model
cout << "Training..." << endl;
int64 tick1 = cv::getTickCount();
ppf_match_3d::PPF3DDetector detector(0.025, 0.05);
detector.trainModel(pc);
int64 tick2 = cv::getTickCount();
cout << endl << "Training complete in "
<< (double)(tick2 - tick1) / cv::getTickFrequency()
<< " sec" << endl << "Loading model..." << endl;
// Read the scene
Mat pcTest = loadPLYSimple(sceneFileName.c_str(), 1);
// Match the model to the scene and get the pose
cout << endl << "Starting matching..." << endl;
vector<Pose3DPtr> results;
tick1 = cv::getTickCount();
detector.match(pcTest, results, 1.0 / 40.0, 0.05);
tick2 = cv::getTickCount();
cout << endl << "PPF Elapsed Time "
<< (tick2 - tick1) / cv::getTickFrequency() << " sec" << endl;
// Get only first N results
int N = 2;
vector<Pose3DPtr> resultsSub(results.begin(), results.begin() + N);
// Create an instance of ICP
ICP icp(100, 0.005f, 2.5f, 8);
int64 t1 = cv::getTickCount();
// Register for all selected poses
cout << endl << "Performing ICP on " << N << " poses..." << endl;
icp.registerModelToScene(pc, pcTest, resultsSub);
int64 t2 = cv::getTickCount();
cout << endl << "ICP Elapsed Time "
<< (t2 - t1) / cv::getTickFrequency() << " sec" << endl;
cout << "Poses: " << endl;
// debug first five poses
for (size_t i = 0; i<resultsSub.size(); i++)
{
Pose3DPtr result = resultsSub[i];
cout << "Pose Result " << i << endl;
result->printPose();
if (i == 0)
{
Mat pct = transformPCPose(pc, result->pose);
writePLY(pct, "para6700PCTrans.ply");
}
}
return 0;
}
And my error :(when code was these line :
detector.trainModel(pc);
int64 tick2 = cv::getTickCount();
I get this error:
Use debug mode. Change Key type at t_hash_int.cpp source file by these lines
#if (defined x86_64 || defined _M_X64)
typedef uint64_t KeyType;
#else
typedef unsigned int KeyType;
#endif
Build again from the source
Check this issue: https://github.com/opencv/opencv_contrib/issues/170
It seems that you use the release mode to run the program.
I have meet this problem before. When I change to debug mode. Everything works well.
Related
Im trying to get working the Surface Matching Sample code from surface_matching. Im able to compile the code then when run with ./surface_matching /home/surface_matching/coke.ply /home/surface_matching/01.ply
Im running the same code sample as in the link. Code is the followving
#include "opencv2/surface_matching.hpp"
#include <iostream>
#include "opencv2/surface_matching/ppf_helpers.hpp"
#include "opencv2/core/utility.hpp"
using namespace std;
using namespace cv;
using namespace ppf_match_3d;
static void help(const string& errorMessage)
{
cout << "Program init error : "<< errorMessage << endl;
cout << "\nUsage : ppf_matching [input model file] [input scene file]"<< endl;
cout << "\nPlease start again with new parameters"<< endl;
}
int main(int argc, char** argv)
{
// welcome message
cout << "****************************************************" << endl;
cout << "* Surface Matching demonstration : demonstrates the use of surface matching"
" using point pair features." << endl;
cout << "* The sample loads a model and a scene, where the model lies in a different"
" pose than the training.\n* It then trains the model and searches for it in the"
" input scene. The detected poses are further refined by ICP\n* and printed to the "
" standard output." << endl;
cout << "****************************************************" << endl;
if (argc < 3)
{
help("Not enough input arguments");
exit(1);
}
#if (defined __x86_64__ || defined _M_X64)
cout << "Running on 64 bits" << endl;
#else
cout << "Running on 32 bits" << endl;
#endif
#ifdef _OPENMP
cout << "Running with OpenMP" << endl;
#else
cout << "Running without OpenMP and without TBB" << endl;
#endif
string modelFileName = (string)argv[1];
string sceneFileName = (string)argv[2];
Mat pc = loadPLYSimple(modelFileName.c_str(), 1);
// Now train the model
cout << "Training..." << endl;
int64 tick1 = cv::getTickCount();
ppf_match_3d::PPF3DDetector detector(0.025, 0.05);
detector.trainModel(pc);
int64 tick2 = cv::getTickCount();
cout << endl << "Training complete in "
<< (double)(tick2-tick1)/ cv::getTickFrequency()
<< " sec" << endl << "Loading model..." << endl;
// Read the scene
Mat pcTest = loadPLYSimple(sceneFileName.c_str(), 1);
// Match the model to the scene and get the pose
cout << endl << "Starting matching..." << endl;
vector<Pose3DPtr> results;
tick1 = cv::getTickCount();
// orig detector.match(pcTest, results, 1.0/40.0, 0.05);
detector.match(pcTest, results, 1.0/40.0, 0.05);
tick2 = cv::getTickCount();
cout << endl << "PPF Elapsed Time " <<
(tick2-tick1)/cv::getTickFrequency() << " sec" << endl;
// Get only first N results
int N = 2;
vector<Pose3DPtr> resultsSub(results.begin(),results.begin()+N);
// Create an instance of ICP
ICP icp(100, 0.005f, 2.5f, 8);
int64 t1 = cv::getTickCount();
// Register for all selected poses
cout << endl << "Performing ICP on " << N << " poses..." << endl;
icp.registerModelToScene(pc, pcTest, resultsSub);
int64 t2 = cv::getTickCount();
cout << endl << "ICP Elapsed Time " <<
(t2-t1)/cv::getTickFrequency() << " sec" << endl;
cout << "Poses: " << endl;
// debug first five poses
for (size_t i=0; i<resultsSub.size(); i++)
{
Pose3DPtr result = resultsSub[i];
cout << "Pose Result " << i << endl;
result->printPose();
if (i==0)
{
Mat pct = transformPCPose(pc, result->pose);
writePLY(pct, "para6700PCTrans.ply");
}
}
return 0;
}
It runs but never gets any results. I got this error
$ ./surface_matching /home/admini/surface_matching/coke.ply /home/admini/surface_matching/01.ply
****************************************************
* Surface Matching demonstration : demonstrates the use of surface matching using point pair features.
* The sample loads a model and a scene, where the model lies in a different pose than the training.
* It then trains the model and searches for it in the input scene. The detected poses are further refined by ICP
* and printed to the standard output.
****************************************************
Running on 64 bits
Running without OpenMP and without TBB
Training...
Training complete in 0.100169 sec
Loading model...
Starting matching...
Segmentation fault (core dumped)
Training is complete and starts matching but then Segmentation fault. What can be the problem? Here the object model file:
And the scene file
What can be the problem?
I'm trying to import facial landmark points from webcam or video
using dlib into a file . I can display all detected landmarks on the terminal
but it is only saving the first and second landmark ponits (x,y) into the
output file , and not saving all the detected landmarks into
the output file
#include <dlib/opencv.h>
#include <opencv2/highgui/highgui.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
using namespace dlib;
using namespace std;
int main()
{
try
{
cv::VideoCapture cap(0);
if (!cap.isOpened())
{
cerr << "Unable to connect to camera" << endl;
return 1;
}
image_window win;
frontal_face_detector detector = get_frontal_face_detector();
shape_predictor pose_model;
deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;
while(!win.is_closed())
{
// Grab a frame
cv::Mat temp;
cap >> temp;
cv_image<bgr_pixel> cimg(temp);
std::vector<rectangle> faces = detector(cimg);
std::vector<full_object_detection> shapes;
for (unsigned long i = 0; i < faces.size(); ++i)
{
full_object_detection shape = pose_model(cimg, faces[i]);
cout << "number of parts: "<< shape.num_parts() << endl;
cout << "pixel position of first part: " << shape.part(0) << endl;
cout << "pixel position of second part: " << shape.part(1) << endl;
shapes.push_back(pose_model(cimg, faces[i]));
const full_object_detection& d = shapes[0];
ofstream outputfile;
outputfile.open("data1.txt");
outputfile<< shape.part(0).x() << " " << shape.part(0).y() << endl;
outputfile<< shape.part(1).x() << " " << shape.part(1).y() << endl;
}
win.clear_overlay();
win.set_image(cimg);
win.add_overlay(render_face_detections(shapes));
}
}
catch(serialization_error& e)
{
cout << "You need dlib's default face landmarking model file to run this example." << endl;
cout << "You can get it from the following URL: " << endl;
cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
}
catch(exception& e)
{
cout << e.what() << endl;
}
}
Am I wrong or you want to save all landmarks when you have only:
ofstream outputfile;
outputfile.open("data1.txt");
outputfile<< shape.part(0).x() << " " << shape.part(0).y() << endl;
outputfile<< shape.part(1).x() << " " << shape.part(1).y() << endl;
And even not closing the file correctly. Try with for statement.
I have compilation errors to just simply output a cout message. Below is my code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
char letter = 'a';
short age = 10;
int cout = 575;
long numStars = 985632145;
float pi = 3.1;
double price = 89.65;
string season = "summer";
cout << "Letter: "<< letter << endl;
std::cout << "Age: " << age<< endl;
std::cout << "Cout: " << cout << endl;
std::cout << "Number Stars: " << numStars << endl;
std::cout << "Pi: " << pi << endl;
std::cout << "Price: " << price << endl;
std::cout << "Season: " << season;
system("pause");
return 0;
}
The errors I get are on the line:
cout << "Letter: "<< letter << endl;
I have tried reinstalling VS2015 but that didn't help.
You have a variable of type int called cout - this is not allowed given that you are using namespace std. Change this variable name to something else, and avoid the statement using namespace std.
std::cout is a "reserved type/keyword" so you cannot use it as a variable name.
I've computed a 2D constrained delaunay triangulation from 2.5D data using the projection_traits_xy_3 [1]. Now I would like to get a mesh that I can visualize.
I've managed to do that with 3d delaunay following the manual[2], how could I achieve it with a 2.5D CDT ?
[...]
typedef CGAL::Projection_traits_xy_3<K> Gt;
typedef CGAL::Constrained_Delaunay_triangulation_2<Gt, Tds> CDT;
[...]
CDT cdt;
cdt.insert(points.begin(),points.end());
[...]
¿?
[...]
std::ofstream out(outdir + "out.off");
Polyhedron output_mesh;
CGAL::output_surface_facets_to_polyhedron(¿?, output_mesh);
out << output_mesh;
[1] http://pastebin.com/HzAwrnW5
[2] http://doc.cgal.org/latest/Point_set_processing_3/index.html#chappoint_set_processing_3
http://doc.cgal.org/latest/Surface_reconstruction_points_3/
Here comes pseudocode forwriting it into an off file
cout << "OFF\n" << cdt.number_of_vertices()
<< " " << cdt.number_of_faces() << " 0" << std::endl;
std::map<vertex_handle,int> indices;
int counter = 0;
for all finite vertices v {
cout << v->point() <<std::endl;
indices.insert(v, counter++);
}
for all finite faces f {
cout << "3 " << indices[f->vertex(0)]
<< " " << indices[f->vertex(1)]
<< " " << indices[f->vertex(2)] << std::endl;
}
From #Andreas suggestion:
Here comes the code for writing it into an off file
std::ofstream outstream("output.off");
outstream << "OFF\n" << cdt.number_of_vertices()
<< " " << cdt.number_of_faces() << " 0" << std::endl;
std::map<CDT::Vertex_handle,int> indices;
int counter = 0;
for(CDT::Finite_vertices_iterator it = cdt.finite_vertices_begin(); it != cdt.finite_vertices_end(); ++it)
{
outstream << it->point() << std::endl;
indices.insert(std::pair<CDT::Vertex_handle,int>(it, counter++));
}
for(CDT::Finite_faces_iterator it = cdt.finite_faces_begin(); it != cdt.finite_faces_end(); ++it)
{
outstream << "3 " << indices[it->vertex(0)]
<< " " << indices[it->vertex(1)]
<< " " << indices[it->vertex(2)] << std::endl;
}
How would I change this code, preserving formatting to C++ using cout?
printf(" %5lu %3d %+1.2f ", nodes, depth, best_score / 100.0);
To be honest, I've never liked the ostream formatting mechanism. I've tended to use boost::format when I need to do something like this.
std::cout << boost::format(" %5lu %3d %+1.2f ") % nodes % depth % (best_score / 100.0);
#include <iostream>
#include <iomanip>
void func(unsigned long nodes, int depth, float best_score) {
//store old format
streamsize pre = std::cout.precision();
ios_base::fmtflags flags = std::cout.flags();
std::cout << setw(5) << nodes << setw(3) << depth;
std::cout << showpos << setw(4) << setprecision(2) << showpos (best_score/100.);
//restore old format
std::cout.precision(pre);
std::cout.flags(flags);
}
Use cout.width(n) and cout.precision(n);
So, for example:
cout.width(5);
cout << nodes << " ";
cout.width(3);
cout << depth << " ";
cout.setiosflags(ios::fixed);
cout.precision(2);
cout.width(4);
cout << best_score/100.0 << " " << endl;
You can chain things together:
cout << width(5) << nodes << " " << width(3) << depth << " "
<< setiosflags(ios::fixed) << precision(2) << best_score/100.0 << " "
<< endl;