46 #include <visp3/core/vpConfig.h>
47 #include <visp3/core/vpConvert.h>
49 #ifdef ENABLE_VISP_NAMESPACE
53 bool areSame(
double a,
double b) {
return fabs(a - b) < std::numeric_limits<double>::epsilon(); }
55 void testConvertFromImagePointToPoint2f()
57 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
62 cv::Point2f pt1, pt2, pt3;
67 int nbOk = 0, nbNOk = 0;
68 if (areSame(imPt1.get_u(), pt1.x) && areSame(imPt1.get_v(), pt1.y))
72 if (areSame(imPt2.get_u(), pt2.x) && areSame(imPt2.get_v(), pt2.y))
76 if (areSame(imPt3.get_u(), pt3.x) && areSame(imPt3.get_v(), pt3.y))
81 std::vector<vpImagePoint> listOfImPts(3);
82 listOfImPts[0] = imPt1;
83 listOfImPts[1] = imPt2;
84 listOfImPts[2] = imPt3;
86 std::vector<cv::Point2f> listOfPts;
89 if (listOfImPts.size() == listOfPts.size()) {
90 for (
size_t i = 0; i < 3; i++) {
91 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
101 std::cout <<
"testConvertFromImagePointToPoint2f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
105 void testConvertFromPoint2fToImagePoint()
107 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
110 cv::Point2f pt1(12.5f, .85f), pt2(-44.26f, 125.11f), pt3(0.0f, -1.756e-10f);
115 int nbOk = 0, nbNOk = 0;
116 if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
120 if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
124 if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
129 std::vector<vpImagePoint> listOfImPts;
131 std::vector<cv::Point2f> listOfPts(3);
138 if (listOfImPts.size() == listOfPts.size()) {
139 for (
size_t i = 0; i < 3; i++) {
140 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
150 std::cout <<
"testConvertFromPoint2fToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
154 void testConvertFromImagePointToPoint2d()
156 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
161 cv::Point2d pt1, pt2, pt3;
166 int nbOk = 0, nbNOk = 0;
167 if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
171 if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
175 if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
180 std::vector<vpImagePoint> listOfImPts(3);
181 listOfImPts[0] = imPt1;
182 listOfImPts[1] = imPt2;
183 listOfImPts[2] = imPt3;
185 std::vector<cv::Point2d> listOfPts;
188 if (listOfImPts.size() == listOfPts.size()) {
189 for (
size_t i = 0; i < 3; i++) {
190 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
200 std::cout <<
"testConvertFromImagePointToPoint2d=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
204 void testConvertFromPoint2dToImagePoint()
206 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
209 cv::Point2d pt1(12.5, .85), pt2(-44.26, 125.11), pt3(0, -1.756e-10);
214 int nbOk = 0, nbNOk = 0;
215 if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
219 if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
223 if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
228 std::vector<vpImagePoint> listOfImPts;
230 std::vector<cv::Point2d> listOfPts(3);
237 if (listOfImPts.size() == listOfPts.size()) {
238 for (
size_t i = 0; i < 3; i++) {
239 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
249 std::cout <<
"testConvertFromPoint2dToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
253 void testConvertFromKeyPointToImagePoint()
255 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
256 cv::KeyPoint kp1(12.5f, .85f, 0), kp2(-44.26f, 125.11f, 0), kp3(0.0f, -1.756e-10f, 0);
263 int nbOk = 0, nbNOk = 0;
264 if (areSame(imPt1.
get_u(), kp1.pt.x) && areSame(imPt1.
get_v(), kp1.pt.y))
268 if (areSame(imPt2.
get_u(), kp2.pt.x) && areSame(imPt2.
get_v(), kp2.pt.y))
272 if (areSame(imPt3.
get_u(), kp3.pt.x) && areSame(imPt3.
get_v(), kp3.pt.y))
277 std::vector<cv::KeyPoint> listOfKeyPoints(3);
278 listOfKeyPoints[0] = kp1;
279 listOfKeyPoints[1] = kp2;
280 listOfKeyPoints[2] = kp3;
282 std::vector<vpImagePoint> listOfImPts;
285 if (listOfImPts.size() == listOfKeyPoints.size()) {
286 for (
size_t i = 0; i < 3; i++) {
287 if (areSame(listOfImPts[i].get_u(), listOfKeyPoints[i].pt.x) &&
288 areSame(listOfImPts[i].get_v(), listOfKeyPoints[i].pt.y))
298 std::cout <<
"testConvertFromKeyPointToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
302 void testConvertFromPoint3fToPoint()
304 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
305 cv::Point3f pt1(12.5f, .85f, 110.0f), pt2(-44.26f, 125.11f, -98e2f), pt3(0.0f, -1.756e-10f, 0.00015f);
306 vpPoint point1, point2, point3;
312 int nbOk = 0, nbNOk = 0;
313 if (areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ()))
317 if (areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ()))
321 if (areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ()))
326 std::vector<cv::Point3f> listOfPoints3f(3);
327 listOfPoints3f[0] = pt1;
328 listOfPoints3f[1] = pt2;
329 listOfPoints3f[2] = pt3;
331 std::vector<vpPoint> listOfPts;
334 if (listOfPoints3f.size() == listOfPts.size()) {
335 for (
size_t i = 0; i < 3; i++) {
336 if (areSame(listOfPts[i].get_oX(), listOfPoints3f[i].x) && areSame(listOfPts[i].get_oY(), listOfPoints3f[i].y) &&
337 areSame(listOfPts[i].get_oZ(), listOfPoints3f[i].z))
347 std::cout <<
"testConvertFromPoint3fToPoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
351 void testConvertFromPointToPoint3f()
353 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
354 cv::Point3f pt1, pt2, pt3;
355 vpPoint point1, point2, point3;
365 point3.
set_oY(-1.756e-10f);
372 int nbOk = 0, nbNOk = 0;
373 if (areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ()))
377 if (areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ()))
381 if (areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ()))
386 std::vector<cv::Point3f> listOfPoints3f;
387 std::vector<vpPoint> listOfPts(3);
388 listOfPts[0] = point1;
389 listOfPts[1] = point2;
390 listOfPts[2] = point3;
394 if (listOfPoints3f.size() == listOfPts.size()) {
395 for (
size_t i = 0; i < 3; i++) {
396 if (areSame(listOfPts[i].get_oX(), listOfPoints3f[i].x) && areSame(listOfPts[i].get_oY(), listOfPoints3f[i].y) &&
397 areSame(listOfPts[i].get_oZ(), listOfPoints3f[i].z))
407 std::cout <<
"testConvertFromPointToPoint3f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
413 testConvertFromImagePointToPoint2f();
414 testConvertFromPoint2fToImagePoint();
415 testConvertFromImagePointToPoint2d();
416 testConvertFromPoint2dToImagePoint();
418 testConvertFromKeyPointToImagePoint();
419 testConvertFromPoint3fToPoint();
420 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.