Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testFindMatch.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See https://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*/
30
31
#include <visp3/core/vpHomogeneousMatrix.h>
32
#include <visp3/core/vpMath.h>
33
#include <visp3/core/vpPoint.h>
34
#include <visp3/vision/vpPose.h>
35
36
#include <stdio.h>
37
#include <stdlib.h>
38
39
#define L 0.1
40
48
49
int
main()
50
{
51
#ifdef ENABLE_VISP_NAMESPACE
52
using namespace
VISP_NAMESPACE_NAME
;
53
#endif
54
55
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
56
try
{
57
std::cout <<
"Find Matches using Ransac"
<< std::endl;
58
std::vector<vpPoint> P;
59
60
P.push_back(
vpPoint
(-L, -L, 0));
61
P.push_back(
vpPoint
(L, -L, 0));
62
P.push_back(
vpPoint
(L, L, 0));
63
P.push_back(
vpPoint
(-L, L, 0));
64
P.push_back(
vpPoint
(-0, L / 2., L));
65
66
vpHomogeneousMatrix
cMo_ref(0, 0.2, 1,
vpMath::rad
(3),
vpMath::rad
(-2),
vpMath::rad
(10));
67
68
std::vector<vpPoint>
p
(P.size());
69
for
(
unsigned
int
i = 0;
i
< P.size();
i
++) {
70
vpPoint
pt = P[
i
];
71
pt.
project
(cMo_ref);
72
p
[
i
].set_x(pt.
get_x
());
73
p
[
i
].set_y(pt.
get_y
());
74
}
75
76
unsigned
int
ninliers;
77
std::vector<vpPoint> inliers;
78
double
threshold = 1
e
-6;
79
unsigned
int
nbInlierToReachConsensus =
static_cast<
unsigned
int
>
(P.size());
80
81
vpHomogeneousMatrix
cMo
;
82
83
vpPose::findMatch
(p, P, nbInlierToReachConsensus, threshold, ninliers, inliers, cMo);
84
85
std::cout <<
"Inliers: "
<< std::endl;
86
for
(
unsigned
int
i = 0;
i
< inliers.size();
i
++) {
87
inliers[
i
].print();
88
std::cout << std::endl;
89
}
90
91
std::cout <<
"cMo :\n"
<<
vpPoseVector
(cMo).
t
() << std::endl << std::endl;
92
93
vpPoseVector
pose_ref =
vpPoseVector
(cMo_ref);
94
vpPoseVector
pose_est =
vpPoseVector
(cMo);
95
96
std::cout << std::endl;
97
std::cout <<
"reference cMo :\n"
<< pose_ref.
t
() << std::endl << std::endl;
98
std::cout <<
"estimated cMo :\n"
<< pose_est.
t
() << std::endl << std::endl;
99
100
int
test_fail = 0;
101
for
(
unsigned
int
i = 0;
i
< 6;
i
++) {
102
if
(std::fabs(pose_ref[i] - pose_est[i]) > 0.001)
103
test_fail = 1;
104
}
105
106
std::cout <<
"Matching is "
<< (test_fail ?
"badly"
:
"well"
) <<
" performed"
<< std::endl;
107
108
return
(test_fail ? EXIT_FAILURE : EXIT_SUCCESS);
109
}
110
catch
(
const
vpException
&e) {
111
std::cout <<
"Catch an exception: "
<<
e
<< std::endl;
112
return
EXIT_FAILURE;
113
}
114
#else
115
std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV"
<< std::endl;
116
return
EXIT_SUCCESS;
117
#endif
118
}
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
vpForwardProjection::project
void project()
Definition
vpForwardProjection.cpp:63
vpHomogeneousMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition
vpHomogeneousMatrix.h:221
vpMath::rad
static double rad(double deg)
Definition
vpMath.h:129
vpPoint
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition
vpPoint.h:79
vpPoint::get_y
double get_y() const
Get the point y coordinate in the image plane.
Definition
vpPoint.cpp:429
vpPoint::get_x
double get_x() const
Get the point x coordinate in the image plane.
Definition
vpPoint.cpp:427
vpPoseVector
Implementation of a pose vector and operations on poses.
Definition
vpPoseVector.h:203
vpPoseVector::t
vpRowVector t() const
Definition
vpPoseVector.cpp:439
vpPose::findMatch
static void findMatch(std::vector< vpPoint > &p2D, std::vector< vpPoint > &p3D, const unsigned int &numberOfInlierToReachAConsensus, const double &threshold, unsigned int &ninliers, std::vector< vpPoint > &listInliers, vpHomogeneousMatrix &cMo, const int &maxNbTrials=10000, bool useParallelRansac=true, unsigned int nthreads=0, FuncCheckValidityPose func=nullptr)
Definition
vpPoseRansac.cpp:574
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.p
p
Definition
ibvs-four-points.py:280
ibvs-four-points.e
e
Definition
ibvs-four-points.py:272
realsense-mbt.cMo
cMo
Definition
realsense-mbt.py:212
yolo-centering-task-afma6.i
i
Definition
yolo-centering-task-afma6.py:329
modules
vision
test
pose
testFindMatch.cpp
Generated by
1.17.0