Test functions in Convert.
#include <iostream>
#include <limits>
#include <math.h>
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpConvert.h>
#ifdef ENABLE_VISP_NAMESPACE
#endif
bool areSame(double a, double b) { return fabs(a - b) < std::numeric_limits<double>::epsilon(); }
void testConvertFromImagePointToPoint2f()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
cv::Point2f pt1, pt2, pt3;
int nbOk = 0, nbNOk = 0;
if (areSame(imPt1.get_u(), pt1.x) && areSame(imPt1.get_v(), pt1.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt2.get_u(), pt2.x) && areSame(imPt2.get_v(), pt2.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt3.get_u(), pt3.x) && areSame(imPt3.get_v(), pt3.y))
nbOk++;
else
nbNOk++;
std::vector<vpImagePoint> listOfImPts(3);
listOfImPts[0] = imPt1;
listOfImPts[1] = imPt2;
listOfImPts[2] = imPt3;
std::vector<cv::Point2f> listOfPts;
if (listOfImPts.size() == listOfPts.size()) {
for (size_t i = 0; i < 3; i++) {
if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
nbOk++;
else
nbNOk++;
}
}
else {
nbNOk += 3;
}
std::cout << "testConvertFromImagePointToPoint2f=" << nbOk << "/" << (nbOk + nbNOk) << std::endl;
#endif
}
void testConvertFromPoint2fToImagePoint()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
cv::Point2f pt1(12.5f, .85f), pt2(-44.26f, 125.11f), pt3(0.0f, -1.756e-10f);
int nbOk = 0, nbNOk = 0;
if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
nbOk++;
else
nbNOk++;
std::vector<vpImagePoint> listOfImPts;
std::vector<cv::Point2f> listOfPts(3);
listOfPts[0] = pt1;
listOfPts[1] = pt2;
listOfPts[2] = pt3;
if (listOfImPts.size() == listOfPts.size()) {
for (size_t i = 0; i < 3; i++) {
if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
nbOk++;
else
nbNOk++;
}
}
else {
nbNOk += 3;
}
std::cout << "testConvertFromPoint2fToImagePoint=" << nbOk << "/" << (nbOk + nbNOk) << std::endl;
#endif
}
void testConvertFromImagePointToPoint2d()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
cv::Point2d pt1, pt2, pt3;
int nbOk = 0, nbNOk = 0;
if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
nbOk++;
else
nbNOk++;
std::vector<vpImagePoint> listOfImPts(3);
listOfImPts[0] = imPt1;
listOfImPts[1] = imPt2;
listOfImPts[2] = imPt3;
std::vector<cv::Point2d> listOfPts;
if (listOfImPts.size() == listOfPts.size()) {
for (size_t i = 0; i < 3; i++) {
if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
nbOk++;
else
nbNOk++;
}
}
else {
nbNOk += 3;
}
std::cout << "testConvertFromImagePointToPoint2d=" << nbOk << "/" << (nbOk + nbNOk) << std::endl;
#endif
}
void testConvertFromPoint2dToImagePoint()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
cv::Point2d pt1(12.5, .85), pt2(-44.26, 125.11), pt3(0, -1.756e-10);
int nbOk = 0, nbNOk = 0;
if (areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y))
nbOk++;
else
nbNOk++;
std::vector<vpImagePoint> listOfImPts;
std::vector<cv::Point2d> listOfPts(3);
listOfPts[0] = pt1;
listOfPts[1] = pt2;
listOfPts[2] = pt3;
if (listOfImPts.size() == listOfPts.size()) {
for (size_t i = 0; i < 3; i++) {
if (areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y))
nbOk++;
else
nbNOk++;
}
}
else {
nbNOk += 3;
}
std::cout << "testConvertFromPoint2dToImagePoint=" << nbOk << "/" << (nbOk + nbNOk) << std::endl;
#endif
}
void testConvertFromKeyPointToImagePoint()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
cv::KeyPoint kp1(12.5f, .85f, 0), kp2(-44.26f, 125.11f, 0), kp3(0.0f, -1.756e-10f, 0);
int nbOk = 0, nbNOk = 0;
if (areSame(imPt1.
get_u(), kp1.pt.x) && areSame(imPt1.
get_v(), kp1.pt.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt2.
get_u(), kp2.pt.x) && areSame(imPt2.
get_v(), kp2.pt.y))
nbOk++;
else
nbNOk++;
if (areSame(imPt3.
get_u(), kp3.pt.x) && areSame(imPt3.
get_v(), kp3.pt.y))
nbOk++;
else
nbNOk++;
std::vector<cv::KeyPoint> listOfKeyPoints(3);
listOfKeyPoints[0] = kp1;
listOfKeyPoints[1] = kp2;
listOfKeyPoints[2] = kp3;
std::vector<vpImagePoint> listOfImPts;
if (listOfImPts.size() == listOfKeyPoints.size()) {
for (size_t i = 0; i < 3; i++) {
if (areSame(listOfImPts[i].get_u(), listOfKeyPoints[i].pt.x) &&
areSame(listOfImPts[i].get_v(), listOfKeyPoints[i].pt.y))
nbOk++;
else
nbNOk++;
}
}
else {
nbNOk += 3;
}
std::cout << "testConvertFromKeyPointToImagePoint=" << nbOk << "/" << (nbOk + nbNOk) << std::endl;
#endif
}
void testConvertFromPoint3fToPoint()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
cv::Point3f pt1(12.5f, .85f, 110.0f), pt2(-44.26f, 125.11f, -98e2f), pt3(0.0f, -1.756e-10f, 0.00015f);
int nbOk = 0, nbNOk = 0;
if (areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ()))
nbOk++;
else
nbNOk++;
if (areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ()))
nbOk++;
else
nbNOk++;
if (areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ()))
nbOk++;
else
nbNOk++;
std::vector<cv::Point3f> listOfPoints3f(3);
listOfPoints3f[0] = pt1;
listOfPoints3f[1] = pt2;
listOfPoints3f[2] = pt3;
std::vector<vpPoint> listOfPts;
if (listOfPoints3f.size() == listOfPts.size()) {
for (size_t i = 0; i < 3; i++) {
if (areSame(listOfPts[i].get_oX(), listOfPoints3f[i].x) && areSame(listOfPts[i].get_oY(), listOfPoints3f[i].y) &&
areSame(listOfPts[i].get_oZ(), listOfPoints3f[i].z))
nbOk++;
else
nbNOk++;
}
}
else {
nbNOk += 3;
}
std::cout << "testConvertFromPoint3fToPoint=" << nbOk << "/" << (nbOk + nbNOk) << std::endl;
#endif
}
void testConvertFromPointToPoint3f()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_FEATURES2D)
cv::Point3f pt1, pt2, pt3;
int nbOk = 0, nbNOk = 0;
if (areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ()))
nbOk++;
else
nbNOk++;
if (areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ()))
nbOk++;
else
nbNOk++;
if (areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ()))
nbOk++;
else
nbNOk++;
std::vector<cv::Point3f> listOfPoints3f;
std::vector<vpPoint> listOfPts(3);
listOfPts[0] = point1;
listOfPts[1] = point2;
listOfPts[2] = point3;
if (listOfPoints3f.size() == listOfPts.size()) {
for (size_t i = 0; i < 3; i++) {
if (areSame(listOfPts[i].get_oX(), listOfPoints3f[i].x) && areSame(listOfPts[i].get_oY(), listOfPoints3f[i].y) &&
areSame(listOfPts[i].get_oZ(), listOfPoints3f[i].z))
nbOk++;
else
nbNOk++;
}
}
else {
nbNOk += 3;
}
std::cout << "testConvertFromPointToPoint3f=" << nbOk << "/" << (nbOk + nbNOk) << std::endl;
#endif
}
int main()
{
testConvertFromImagePointToPoint2f();
testConvertFromPoint2fToImagePoint();
testConvertFromImagePointToPoint2d();
testConvertFromPoint2dToImagePoint();
testConvertFromKeyPointToImagePoint();
testConvertFromPoint3fToPoint();
testConvertFromPointToPoint3f();
return EXIT_SUCCESS;
}
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.