48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpConvert.h>
52 bool areSame(
double a,
double b) {
53 return fabs(a - b) < std::numeric_limits<double>::epsilon();
56 void testConvertFromImagePointToPoint2f() {
57 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
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)) nbOk++;
else nbNOk++;
69 if(areSame(imPt2.get_u(), pt2.x) && areSame(imPt2.get_v(), pt2.y)) nbOk++;
else nbNOk++;
70 if(areSame(imPt3.get_u(), pt3.x) && areSame(imPt3.get_v(), pt3.y)) nbOk++;
else nbNOk++;
72 std::vector<vpImagePoint> listOfImPts(3);
73 listOfImPts[0] = imPt1;
74 listOfImPts[1] = imPt2;
75 listOfImPts[2] = imPt3;
77 std::vector<cv::Point2f> listOfPts;
80 if(listOfImPts.size() == listOfPts.size()) {
81 for(
size_t i = 0; i < 3; i++) {
82 if(areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y)) nbOk++;
else nbNOk++;
88 std::cout <<
"testConvertFromImagePointToPoint2f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
92 void testConvertFromPoint2fToImagePoint() {
93 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
96 cv::Point2f pt1(12.5f, .85f), pt2(-44.26f, 125.11f), pt3(0.0f, -1.756e-10f);
101 int nbOk = 0, nbNOk = 0;
102 if(areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y)) nbOk++;
else nbNOk++;
103 if(areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y)) nbOk++;
else nbNOk++;
104 if(areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y)) nbOk++;
else nbNOk++;
106 std::vector<vpImagePoint> listOfImPts;
108 std::vector<cv::Point2f> listOfPts(3);
115 if(listOfImPts.size() == listOfPts.size()) {
116 for(
size_t i = 0; i < 3; i++) {
117 if(areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y)) nbOk++;
else nbNOk++;
123 std::cout <<
"testConvertFromPoint2fToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
127 void testConvertFromImagePointToPoint2d() {
128 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
133 cv::Point2d pt1, pt2, pt3;
138 int nbOk = 0, nbNOk = 0;
139 if(areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y)) nbOk++;
else nbNOk++;
140 if(areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y)) nbOk++;
else nbNOk++;
141 if(areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y)) nbOk++;
else nbNOk++;
143 std::vector<vpImagePoint> listOfImPts(3);
144 listOfImPts[0] = imPt1;
145 listOfImPts[1] = imPt2;
146 listOfImPts[2] = imPt3;
148 std::vector<cv::Point2d> listOfPts;
151 if(listOfImPts.size() == listOfPts.size()) {
152 for(
size_t i = 0; i < 3; i++) {
153 if(areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y)) nbOk++;
else nbNOk++;
159 std::cout <<
"testConvertFromImagePointToPoint2d=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
163 void testConvertFromPoint2dToImagePoint() {
164 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
167 cv::Point2d pt1(12.5, .85), pt2(-44.26, 125.11), pt3(0, -1.756e-10);
172 int nbOk = 0, nbNOk = 0;
173 if(areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y)) nbOk++;
else nbNOk++;
174 if(areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y)) nbOk++;
else nbNOk++;
175 if(areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y)) nbOk++;
else nbNOk++;
177 std::vector<vpImagePoint> listOfImPts;
179 std::vector<cv::Point2d> listOfPts(3);
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)) nbOk++;
else nbNOk++;
194 std::cout <<
"testConvertFromPoint2dToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
198 void testConvertFromKeyPointToImagePoint() {
199 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
200 cv::KeyPoint kp1(12.5f, .85f, 0), kp2(-44.26f, 125.11f, 0), kp3(0.0f, -1.756e-10f, 0);
207 int nbOk = 0, nbNOk = 0;
208 if(areSame(imPt1.
get_u(), kp1.pt.x) && areSame(imPt1.
get_v(), kp1.pt.y)) nbOk++;
else nbNOk++;
209 if(areSame(imPt2.
get_u(), kp2.pt.x) && areSame(imPt2.
get_v(), kp2.pt.y)) nbOk++;
else nbNOk++;
210 if(areSame(imPt3.
get_u(), kp3.pt.x) && areSame(imPt3.
get_v(), kp3.pt.y)) nbOk++;
else nbNOk++;
212 std::vector<cv::KeyPoint> listOfKeyPoints(3);
213 listOfKeyPoints[0] = kp1;
214 listOfKeyPoints[1] = kp2;
215 listOfKeyPoints[2] = kp3;
217 std::vector<vpImagePoint> listOfImPts;
220 if(listOfImPts.size() == listOfKeyPoints.size()) {
221 for(
size_t i = 0; i < 3; i++) {
222 if(areSame(listOfImPts[i].get_u(), listOfKeyPoints[i].pt.x) && areSame(listOfImPts[i].get_v(), listOfKeyPoints[i].pt.y)) nbOk++;
else nbNOk++;
228 std::cout <<
"testConvertFromKeyPointToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
232 void testConvertFromPoint3fToPoint() {
233 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
234 cv::Point3f pt1(12.5f, .85f, 110.0f), pt2(-44.26f, 125.11f, -98e2f), pt3(0.0f, -1.756e-10f, 0.00015f);
235 vpPoint point1, point2, point3;
241 int nbOk = 0, nbNOk = 0;
242 if(areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ())) nbOk++;
else nbNOk++;
243 if(areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ())) nbOk++;
else nbNOk++;
244 if(areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ())) nbOk++;
else nbNOk++;
246 std::vector<cv::Point3f> listOfPoints3f(3);
247 listOfPoints3f[0] = pt1;
248 listOfPoints3f[1] = pt2;
249 listOfPoints3f[2] = pt3;
251 std::vector<vpPoint> listOfPts;
254 if(listOfPoints3f.size() == listOfPts.size()) {
255 for(
size_t i = 0; i < 3; i++) {
256 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++;
262 std::cout <<
"testConvertFromPoint3fToPoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
266 void testConvertFromPointToPoint3f() {
267 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
268 cv::Point3f pt1, pt2, pt3;
269 vpPoint point1, point2, point3;
279 point3.
set_oY(-1.756e-10f);
286 int nbOk = 0, nbNOk = 0;
287 if(areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ())) nbOk++;
else nbNOk++;
288 if(areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ())) nbOk++;
else nbNOk++;
289 if(areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ())) nbOk++;
else nbNOk++;
291 std::vector<cv::Point3f> listOfPoints3f;
292 std::vector<vpPoint> listOfPts(3);
293 listOfPts[0] = point1;
294 listOfPts[1] = point2;
295 listOfPts[2] = point3;
299 if(listOfPoints3f.size() == listOfPts.size()) {
300 for(
size_t i = 0; i < 3; i++) {
301 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++;
307 std::cout <<
"testConvertFromPointToPoint3f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
312 testConvertFromImagePointToPoint2f();
313 testConvertFromPoint2fToImagePoint();
314 testConvertFromImagePointToPoint2d();
315 testConvertFromPoint2dToImagePoint();
317 testConvertFromKeyPointToImagePoint();
318 testConvertFromPoint3fToPoint();
319 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)