Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
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
8
using namespace
VISP_NAMESPACE_NAME
;
9
#endif
10
12
void
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
++) {
18
vpPixelMeterConversion::convertPoint
(cam, ip[i], x, y);
19
point[
i
].set_x(x);
20
point[
i
].set_y(y);
21
pose.
addPoint
(point[i]);
22
}
23
24
if
(init ==
true
) {
25
pose.
computePose
(
vpPose::DEMENTHON_LAGRANGE_VIRTUAL_VS
, cMo);
26
}
27
else
{
28
pose.
computePose
(
vpPose::VIRTUAL_VS
, cMo);
29
}
30
}
32
33
#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)
34
std::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) {
40
vpDisplay::flush
(I);
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
);
48
vpDisplay::flush
(I);
49
dot[
i
].initTracking(I);
50
vpDisplay::flush
(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
vpCameraParameters
Generic class defining intrinsic camera parameters.
Definition
vpCameraParameters.h:311
vpColor::red
static const vpColor red
Definition
vpColor.h:198
vpDisplay::flush
static void flush(const vpImage< unsigned char > &I)
Definition
vpDisplay_uchar.cpp:845
vpDisplay::displayText
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition
vpDisplay_uchar.cpp:788
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpException::fatalError
@ fatalError
Fatal error.
Definition
vpException.h:72
vpHomogeneousMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition
vpHomogeneousMatrix.h:221
vpImagePoint::distance
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition
vpImagePoint.cpp:481
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpPixelMeterConversion::convertPoint
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Definition
vpPixelMeterConversion.h:108
vpPose
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
Definition
vpPose.h:82
vpPose::addPoint
void addPoint(const vpPoint &P)
Definition
vpPose.cpp:96
vpPose::DEMENTHON_LAGRANGE_VIRTUAL_VS
@ DEMENTHON_LAGRANGE_VIRTUAL_VS
Definition
vpPose.h:103
vpPose::VIRTUAL_VS
@ VIRTUAL_VS
Definition
vpPose.h:97
vpPose::computePose
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, FuncCheckValidityPose func=nullptr)
Definition
vpPose.cpp:385
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.x
list x
Definition
ibvs-four-points.py:206
yolo-centering-task-afma6.y
y
Definition
yolo-centering-task-afma6.py:304
yolo-centering-task-afma6.j
j
Definition
yolo-centering-task-afma6.py:329
yolo-centering-task-afma6.i
i
Definition
yolo-centering-task-afma6.py:329
tutorial
computer-vision
pose_helper.cpp
Generated by
1.17.0