48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpConvert.h>
51 bool areSame(
double a,
double b) {
return fabs(a - b) < std::numeric_limits<double>::epsilon(); }
53 void testConvertFromImagePointToPoint2f()
55 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
60 cv::Point2f pt1, pt2, pt3;
65 int nbOk = 0, nbNOk = 0;
66 if (areSame(imPt1.get_u(), pt1.x) && areSame(imPt1.get_v(), pt1.y))
70 if (areSame(imPt2.get_u(), pt2.x) && areSame(imPt2.get_v(), pt2.y))
74 if (areSame(imPt3.get_u(), pt3.x) && areSame(imPt3.get_v(), pt3.y))
79 std::vector<vpImagePoint> listOfImPts(3);
80 listOfImPts[0] = imPt1;
81 listOfImPts[1] = imPt2;
82 listOfImPts[2] = imPt3;
84 std::vector<cv::Point2f> listOfPts;
87 if (listOfImPts.size() == listOfPts.size()) {
88 for (
size_t i = 0; i < 3; i++) {
89 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
99 std::cout <<
"testConvertFromImagePointToPoint2f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
103 void testConvertFromPoint2fToImagePoint()
105 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
108 cv::Point2f pt1(12.5f, .85f), pt2(-44.26f, 125.11f), pt3(0.0f, -1.756e-10f);
113 int nbOk = 0, nbNOk = 0;
114 if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
118 if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
122 if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
127 std::vector<vpImagePoint> listOfImPts;
129 std::vector<cv::Point2f> listOfPts(3);
136 if (listOfImPts.size() == listOfPts.size()) {
137 for (
size_t i = 0; i < 3; i++) {
138 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
148 std::cout <<
"testConvertFromPoint2fToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
152 void testConvertFromImagePointToPoint2d()
154 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
159 cv::Point2d pt1, pt2, pt3;
164 int nbOk = 0, nbNOk = 0;
165 if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
169 if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
173 if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
178 std::vector<vpImagePoint> listOfImPts(3);
179 listOfImPts[0] = imPt1;
180 listOfImPts[1] = imPt2;
181 listOfImPts[2] = imPt3;
183 std::vector<cv::Point2d> listOfPts;
186 if (listOfImPts.size() == listOfPts.size()) {
187 for (
size_t i = 0; i < 3; i++) {
188 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
198 std::cout <<
"testConvertFromImagePointToPoint2d=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
202 void testConvertFromPoint2dToImagePoint()
204 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
207 cv::Point2d pt1(12.5, .85), pt2(-44.26, 125.11), pt3(0, -1.756e-10);
212 int nbOk = 0, nbNOk = 0;
213 if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
217 if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
221 if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
226 std::vector<vpImagePoint> listOfImPts;
228 std::vector<cv::Point2d> listOfPts(3);
235 if (listOfImPts.size() == listOfPts.size()) {
236 for (
size_t i = 0; i < 3; i++) {
237 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
247 std::cout <<
"testConvertFromPoint2dToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
251 void testConvertFromKeyPointToImagePoint()
253 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
254 cv::KeyPoint kp1(12.5f, .85f, 0), kp2(-44.26f, 125.11f, 0), kp3(0.0f, -1.756e-10f, 0);
261 int nbOk = 0, nbNOk = 0;
262 if (areSame(imPt1.
get_u(), kp1.pt.x) && areSame(imPt1.
get_v(), kp1.pt.y))
266 if (areSame(imPt2.
get_u(), kp2.pt.x) && areSame(imPt2.
get_v(), kp2.pt.y))
270 if (areSame(imPt3.
get_u(), kp3.pt.x) && areSame(imPt3.
get_v(), kp3.pt.y))
275 std::vector<cv::KeyPoint> listOfKeyPoints(3);
276 listOfKeyPoints[0] = kp1;
277 listOfKeyPoints[1] = kp2;
278 listOfKeyPoints[2] = kp3;
280 std::vector<vpImagePoint> listOfImPts;
283 if (listOfImPts.size() == listOfKeyPoints.size()) {
284 for (
size_t i = 0; i < 3; i++) {
285 if (areSame(listOfImPts[i].get_u(), listOfKeyPoints[i].pt.x) &&
286 areSame(listOfImPts[i].get_v(), listOfKeyPoints[i].pt.y))
296 std::cout <<
"testConvertFromKeyPointToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
300 void testConvertFromPoint3fToPoint()
302 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
303 cv::Point3f pt1(12.5f, .85f, 110.0f), pt2(-44.26f, 125.11f, -98e2f), pt3(0.0f, -1.756e-10f, 0.00015f);
304 vpPoint point1, point2, point3;
310 int nbOk = 0, nbNOk = 0;
311 if (areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ()))
315 if (areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ()))
319 if (areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ()))
324 std::vector<cv::Point3f> listOfPoints3f(3);
325 listOfPoints3f[0] = pt1;
326 listOfPoints3f[1] = pt2;
327 listOfPoints3f[2] = pt3;
329 std::vector<vpPoint> listOfPts;
332 if (listOfPoints3f.size() == listOfPts.size()) {
333 for (
size_t i = 0; i < 3; i++) {
334 if (areSame(listOfPts[i].get_oX(), listOfPoints3f[i].x) && areSame(listOfPts[i].get_oY(), listOfPoints3f[i].y) &&
335 areSame(listOfPts[i].get_oZ(), listOfPoints3f[i].z))
345 std::cout <<
"testConvertFromPoint3fToPoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
349 void testConvertFromPointToPoint3f()
351 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
352 cv::Point3f pt1, pt2, pt3;
353 vpPoint point1, point2, point3;
363 point3.
set_oY(-1.756e-10f);
370 int nbOk = 0, nbNOk = 0;
371 if (areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ()))
375 if (areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ()))
379 if (areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ()))
384 std::vector<cv::Point3f> listOfPoints3f;
385 std::vector<vpPoint> listOfPts(3);
386 listOfPts[0] = point1;
387 listOfPts[1] = point2;
388 listOfPts[2] = point3;
392 if (listOfPoints3f.size() == listOfPts.size()) {
393 for (
size_t i = 0; i < 3; i++) {
394 if (areSame(listOfPts[i].get_oX(), listOfPoints3f[i].x) && areSame(listOfPts[i].get_oY(), listOfPoints3f[i].y) &&
395 areSame(listOfPts[i].get_oZ(), listOfPoints3f[i].z))
405 std::cout <<
"testConvertFromPointToPoint3f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
411 testConvertFromImagePointToPoint2f();
412 testConvertFromPoint2fToImagePoint();
413 testConvertFromImagePointToPoint2d();
414 testConvertFromPoint2dToImagePoint();
416 testConvertFromKeyPointToImagePoint();
417 testConvertFromPoint3fToPoint();
418 testConvertFromPointToPoint3f();
static void convertFromOpenCV(const cv::KeyPoint &from, vpImagePoint &to)
static void convertToOpenCV(const vpImagePoint &from, cv::Point2f &to)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
double get_oX() const
Get the point oX coordinate in the object frame.
double get_oZ() const
Get the point oZ coordinate in the object frame.
void set_oY(double oY)
Set the point oY coordinate in the object frame.
void set_oZ(double oZ)
Set the point oZ coordinate in the object frame.
void set_oX(double oX)
Set the point oX coordinate in the object frame.
double get_oY() const
Get the point oY coordinate in the object frame.