Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
pose_helper.cpp
1#include <visp3/core/vpDisplay.h>
2#include <visp3/core/vpPixelMeterConversion.h>
3#include <visp3/vision/vpPose.h>
4
5#include "pose_helper.h"
6
7#ifdef ENABLE_VISP_NAMESPACE
8using namespace VISP_NAMESPACE_NAME;
9#endif
10
12void computePose(std::vector<vpPoint> &point, const std::vector<vpImagePoint> &ip, const vpCameraParameters &cam,
13 bool init, vpHomogeneousMatrix &cMo)
14{
15 vpPose pose;
16 double x = 0, y = 0;
17 for (unsigned int i = 0; i < point.size(); i++) {
19 point[i].set_x(x);
20 point[i].set_y(y);
21 pose.addPoint(point[i]);
22 }
23
24 if (init == true) {
26 }
27 else {
29 }
30}
32
33#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)
34std::vector<vpImagePoint> track(vpImage<unsigned char> &I, std::vector<vpDot2> &dot, bool init)
35{
36 try {
37 double distance_same_blob = 10.; // 2 blobs are declared same if their distance is less than this value
38 std::vector<vpImagePoint> ip(dot.size());
39 if (init) {
41 for (unsigned int i = 0; i < dot.size(); i++) {
42 dot[i].setGraphics(true);
43 dot[i].setGraphicsThickness(2);
44 std::stringstream ss;
45 ss << "Click on point " << i + 1;
46 vpDisplay::displayText(I, 20, 20, "Status: initialize blob tracker", vpColor::red);
47 vpDisplay::displayText(I, 40 + i * 20, 20, ss.str(), vpColor::red);
49 dot[i].initTracking(I);
51 }
52 }
53 else {
54 for (unsigned int i = 0; i < dot.size(); i++) {
55 dot[i].track(I);
56 }
57 }
58 for (unsigned int i = 0; i < dot.size(); i++) {
59 ip[i] = dot[i].getCog();
60 // Compare distances between all the dots to check if some of them are not the same
61 }
62 for (unsigned int i = 0; i < ip.size(); i++) {
63 for (unsigned int j = i + 1; j < ip.size(); j++) {
64 if (vpImagePoint::distance(ip[i], ip[j]) < distance_same_blob) {
65 std::cout << "Traking lost: 2 blobs are the same" << std::endl;
66 throw(vpException(vpException::fatalError, "Tracking lost: 2 blobs are the same"));
67 }
68 }
69 }
70
71 return ip;
72 }
73 catch (...) {
74 std::cout << "Traking lost" << std::endl;
75 throw(vpException(vpException::fatalError, "Tracking lost"));
76}
77}
78#endif
Generic class defining intrinsic camera parameters.
static const vpColor red
Definition vpColor.h:198
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72
Implementation of an homogeneous matrix and operations on such kind of matrices.
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition of the vpImage class member functions.
Definition vpImage.h:131
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
Definition vpPose.h:82
void addPoint(const vpPoint &P)
Definition vpPose.cpp:96
@ DEMENTHON_LAGRANGE_VIRTUAL_VS
Definition vpPose.h:103
@ VIRTUAL_VS
Definition vpPose.h:97
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, FuncCheckValidityPose func=nullptr)
Definition vpPose.cpp:385