49 #include <visp3/core/vpConfig.h> 50 #include <visp3/core/vpConvert.h> 52 bool areSame(
double a,
double b) {
return fabs(a - b) < std::numeric_limits<double>::epsilon(); }
54 void testConvertFromImagePointToPoint2f()
56 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 61 cv::Point2f pt1, pt2, pt3;
66 int nbOk = 0, nbNOk = 0;
67 if (areSame(imPt1.get_u(), pt1.x) && areSame(imPt1.get_v(), pt1.y))
71 if (areSame(imPt2.get_u(), pt2.x) && areSame(imPt2.get_v(), pt2.y))
75 if (areSame(imPt3.get_u(), pt3.x) && areSame(imPt3.get_v(), pt3.y))
80 std::vector<vpImagePoint> listOfImPts(3);
81 listOfImPts[0] = imPt1;
82 listOfImPts[1] = imPt2;
83 listOfImPts[2] = imPt3;
85 std::vector<cv::Point2f> listOfPts;
88 if (listOfImPts.size() == listOfPts.size()) {
89 for (
size_t i = 0; i < 3; i++) {
90 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 (VISP_HAVE_OPENCV_VERSION >= 0x020101) 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))
147 std::cout <<
"testConvertFromPoint2fToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
151 void testConvertFromImagePointToPoint2d()
153 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 158 cv::Point2d pt1, pt2, pt3;
163 int nbOk = 0, nbNOk = 0;
164 if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
168 if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
172 if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
177 std::vector<vpImagePoint> listOfImPts(3);
178 listOfImPts[0] = imPt1;
179 listOfImPts[1] = imPt2;
180 listOfImPts[2] = imPt3;
182 std::vector<cv::Point2d> listOfPts;
185 if (listOfImPts.size() == listOfPts.size()) {
186 for (
size_t i = 0; i < 3; i++) {
187 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
196 std::cout <<
"testConvertFromImagePointToPoint2d=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
200 void testConvertFromPoint2dToImagePoint()
202 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 205 cv::Point2d pt1(12.5, .85), pt2(-44.26, 125.11), pt3(0, -1.756e-10);
210 int nbOk = 0, nbNOk = 0;
211 if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
215 if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
219 if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
224 std::vector<vpImagePoint> listOfImPts;
226 std::vector<cv::Point2d> listOfPts(3);
233 if (listOfImPts.size() == listOfPts.size()) {
234 for (
size_t i = 0; i < 3; i++) {
235 if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
244 std::cout <<
"testConvertFromPoint2dToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
248 void testConvertFromKeyPointToImagePoint()
250 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 251 cv::KeyPoint kp1(12.5f, .85f, 0), kp2(-44.26f, 125.11f, 0), kp3(0.0f, -1.756e-10f, 0);
258 int nbOk = 0, nbNOk = 0;
259 if (areSame(imPt1.
get_u(), kp1.pt.x) && areSame(imPt1.
get_v(), kp1.pt.y))
263 if (areSame(imPt2.
get_u(), kp2.pt.x) && areSame(imPt2.
get_v(), kp2.pt.y))
267 if (areSame(imPt3.
get_u(), kp3.pt.x) && areSame(imPt3.
get_v(), kp3.pt.y))
272 std::vector<cv::KeyPoint> listOfKeyPoints(3);
273 listOfKeyPoints[0] = kp1;
274 listOfKeyPoints[1] = kp2;
275 listOfKeyPoints[2] = kp3;
277 std::vector<vpImagePoint> listOfImPts;
280 if (listOfImPts.size() == listOfKeyPoints.size()) {
281 for (
size_t i = 0; i < 3; i++) {
282 if (areSame(listOfImPts[i].get_u(), listOfKeyPoints[i].pt.x) &&
283 areSame(listOfImPts[i].get_v(), listOfKeyPoints[i].pt.y))
292 std::cout <<
"testConvertFromKeyPointToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
296 void testConvertFromPoint3fToPoint()
298 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 299 cv::Point3f pt1(12.5f, .85f, 110.0f), pt2(-44.26f, 125.11f, -98e2f), pt3(0.0f, -1.756e-10f, 0.00015f);
300 vpPoint point1, point2, point3;
306 int nbOk = 0, nbNOk = 0;
307 if (areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ()))
311 if (areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ()))
315 if (areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ()))
320 std::vector<cv::Point3f> listOfPoints3f(3);
321 listOfPoints3f[0] = pt1;
322 listOfPoints3f[1] = pt2;
323 listOfPoints3f[2] = pt3;
325 std::vector<vpPoint> listOfPts;
328 if (listOfPoints3f.size() == listOfPts.size()) {
329 for (
size_t i = 0; i < 3; i++) {
330 if (areSame(listOfPts[i].get_oX(), listOfPoints3f[i].x) && areSame(listOfPts[i].get_oY(), listOfPoints3f[i].y) &&
331 areSame(listOfPts[i].get_oZ(), listOfPoints3f[i].z))
340 std::cout <<
"testConvertFromPoint3fToPoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
344 void testConvertFromPointToPoint3f()
346 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 347 cv::Point3f pt1, pt2, pt3;
348 vpPoint point1, point2, point3;
358 point3.
set_oY(-1.756e-10f);
365 int nbOk = 0, nbNOk = 0;
366 if (areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ()))
370 if (areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ()))
374 if (areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ()))
379 std::vector<cv::Point3f> listOfPoints3f;
380 std::vector<vpPoint> listOfPts(3);
381 listOfPts[0] = point1;
382 listOfPts[1] = point2;
383 listOfPts[2] = point3;
387 if (listOfPoints3f.size() == listOfPts.size()) {
388 for (
size_t i = 0; i < 3; i++) {
389 if (areSame(listOfPts[i].get_oX(), listOfPoints3f[i].x) && areSame(listOfPts[i].get_oY(), listOfPoints3f[i].y) &&
390 areSame(listOfPts[i].get_oZ(), listOfPoints3f[i].z))
399 std::cout <<
"testConvertFromPointToPoint3f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
405 testConvertFromImagePointToPoint2f();
406 testConvertFromPoint2fToImagePoint();
407 testConvertFromImagePointToPoint2d();
408 testConvertFromPoint2dToImagePoint();
410 testConvertFromKeyPointToImagePoint();
411 testConvertFromPoint3fToPoint();
412 testConvertFromPointToPoint3f();
void set_oZ(const double oZ)
Set the point Z coordinate in the object frame.
double get_oY() const
Get the point Y coordinate in the object frame.
Class that defines what is a point.
static void convertToOpenCV(const vpImagePoint &from, cv::Point2f &to)
double get_oZ() const
Get the point Z coordinate in the object frame.
void set_oX(const double oX)
Set the point X coordinate in the object frame.
double get_oX() const
Get the point X coordinate in the object frame.
void set_oY(const double oY)
Set the point Y coordinate in the object frame.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void convertFromOpenCV(const cv::KeyPoint &from, vpImagePoint &to)