52 #include <visp/vpConfig.h>
53 #include <visp/vpConvert.h>
56 bool areSame(
double a,
double b) {
57 return fabs(a - b) < std::numeric_limits<double>::epsilon();
60 void testConvertFromImagePointToPoint2f() {
61 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
66 cv::Point2f pt1, pt2, pt3;
71 int nbOk = 0, nbNOk = 0;
72 if(areSame(imPt1.get_u(), pt1.x) && areSame(imPt1.get_v(), pt1.y)) nbOk++;
else nbNOk++;
73 if(areSame(imPt2.get_u(), pt2.x) && areSame(imPt2.get_v(), pt2.y)) nbOk++;
else nbNOk++;
74 if(areSame(imPt3.get_u(), pt3.x) && areSame(imPt3.get_v(), pt3.y)) nbOk++;
else nbNOk++;
76 std::vector<vpImagePoint> listOfImPts(3);
77 listOfImPts[0] = imPt1;
78 listOfImPts[1] = imPt2;
79 listOfImPts[2] = imPt3;
81 std::vector<cv::Point2f> listOfPts;
84 if(listOfImPts.size() == listOfPts.size()) {
85 for(
size_t i = 0; i < 3; i++) {
86 if(areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y)) nbOk++;
else nbNOk++;
92 std::cout <<
"testConvertFromImagePointToPoint2f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
96 void testConvertFromPoint2fToImagePoint() {
97 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
100 cv::Point2f pt1(12.5f, .85f), pt2(-44.26f, 125.11f), pt3(0.0f, -1.756e-10f);
105 int nbOk = 0, nbNOk = 0;
106 if(areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y)) nbOk++;
else nbNOk++;
107 if(areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y)) nbOk++;
else nbNOk++;
108 if(areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y)) nbOk++;
else nbNOk++;
110 std::vector<vpImagePoint> listOfImPts;
112 std::vector<cv::Point2f> listOfPts(3);
119 if(listOfImPts.size() == listOfPts.size()) {
120 for(
size_t i = 0; i < 3; i++) {
121 if(areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y)) nbOk++;
else nbNOk++;
127 std::cout <<
"testConvertFromPoint2fToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
131 void testConvertFromImagePointToPoint2d() {
132 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
137 cv::Point2d pt1, pt2, pt3;
142 int nbOk = 0, nbNOk = 0;
143 if(areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y)) nbOk++;
else nbNOk++;
144 if(areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y)) nbOk++;
else nbNOk++;
145 if(areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y)) nbOk++;
else nbNOk++;
147 std::vector<vpImagePoint> listOfImPts(3);
148 listOfImPts[0] = imPt1;
149 listOfImPts[1] = imPt2;
150 listOfImPts[2] = imPt3;
152 std::vector<cv::Point2d> listOfPts;
155 if(listOfImPts.size() == listOfPts.size()) {
156 for(
size_t i = 0; i < 3; i++) {
157 if(areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y)) nbOk++;
else nbNOk++;
163 std::cout <<
"testConvertFromImagePointToPoint2d=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
167 void testConvertFromPoint2dToImagePoint() {
168 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
171 cv::Point2d pt1(12.5, .85), pt2(-44.26, 125.11), pt3(0, -1.756e-10);
176 int nbOk = 0, nbNOk = 0;
177 if(areSame(imPt1.
get_u(), pt1.x) && areSame(imPt1.
get_v(), pt1.y)) nbOk++;
else nbNOk++;
178 if(areSame(imPt2.
get_u(), pt2.x) && areSame(imPt2.
get_v(), pt2.y)) nbOk++;
else nbNOk++;
179 if(areSame(imPt3.
get_u(), pt3.x) && areSame(imPt3.
get_v(), pt3.y)) nbOk++;
else nbNOk++;
181 std::vector<vpImagePoint> listOfImPts;
183 std::vector<cv::Point2d> listOfPts(3);
190 if(listOfImPts.size() == listOfPts.size()) {
191 for(
size_t i = 0; i < 3; i++) {
192 if(areSame(listOfImPts[i].get_u(), listOfPts[i].x) && areSame(listOfImPts[i].get_v(), listOfPts[i].y)) nbOk++;
else nbNOk++;
198 std::cout <<
"testConvertFromPoint2dToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
202 void testConvertFromKeyPointToImagePoint() {
203 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
204 cv::KeyPoint kp1(12.5f, .85f, 0), kp2(-44.26f, 125.11f, 0), kp3(0.0f, -1.756e-10f, 0);
211 int nbOk = 0, nbNOk = 0;
212 if(areSame(imPt1.
get_u(), kp1.pt.x) && areSame(imPt1.
get_v(), kp1.pt.y)) nbOk++;
else nbNOk++;
213 if(areSame(imPt2.
get_u(), kp2.pt.x) && areSame(imPt2.
get_v(), kp2.pt.y)) nbOk++;
else nbNOk++;
214 if(areSame(imPt3.
get_u(), kp3.pt.x) && areSame(imPt3.
get_v(), kp3.pt.y)) nbOk++;
else nbNOk++;
216 std::vector<cv::KeyPoint> listOfKeyPoints(3);
217 listOfKeyPoints[0] = kp1;
218 listOfKeyPoints[1] = kp2;
219 listOfKeyPoints[2] = kp3;
221 std::vector<vpImagePoint> listOfImPts;
224 if(listOfImPts.size() == listOfKeyPoints.size()) {
225 for(
size_t i = 0; i < 3; i++) {
226 if(areSame(listOfImPts[i].get_u(), listOfKeyPoints[i].pt.x) && areSame(listOfImPts[i].get_v(), listOfKeyPoints[i].pt.y)) nbOk++;
else nbNOk++;
232 std::cout <<
"testConvertFromKeyPointToImagePoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
236 void testConvertFromPoint3fToPoint() {
237 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
238 cv::Point3f pt1(12.5f, .85f, 110.0f), pt2(-44.26f, 125.11f, -98e2f), pt3(0.0f, -1.756e-10f, 0.00015f);
239 vpPoint point1, point2, point3;
245 int nbOk = 0, nbNOk = 0;
246 if(areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ())) nbOk++;
else nbNOk++;
247 if(areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ())) nbOk++;
else nbNOk++;
248 if(areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ())) nbOk++;
else nbNOk++;
250 std::vector<cv::Point3f> listOfPoints3f(3);
251 listOfPoints3f[0] = pt1;
252 listOfPoints3f[1] = pt2;
253 listOfPoints3f[2] = pt3;
255 std::vector<vpPoint> listOfPts;
258 if(listOfPoints3f.size() == listOfPts.size()) {
259 for(
size_t i = 0; i < 3; i++) {
260 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++;
266 std::cout <<
"testConvertFromPoint3fToPoint=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
270 void testConvertFromPointToPoint3f() {
271 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
272 cv::Point3f pt1, pt2, pt3;
273 vpPoint point1, point2, point3;
283 point3.
set_oY(-1.756e-10f);
290 int nbOk = 0, nbNOk = 0;
291 if(areSame(pt1.x, point1.
get_oX()) && areSame(pt1.y, point1.
get_oY()) && areSame(pt1.z, point1.
get_oZ())) nbOk++;
else nbNOk++;
292 if(areSame(pt2.x, point2.
get_oX()) && areSame(pt2.y, point2.
get_oY()) && areSame(pt2.z, point2.
get_oZ())) nbOk++;
else nbNOk++;
293 if(areSame(pt3.x, point3.
get_oX()) && areSame(pt3.y, point3.
get_oY()) && areSame(pt3.z, point3.
get_oZ())) nbOk++;
else nbNOk++;
295 std::vector<cv::Point3f> listOfPoints3f;
296 std::vector<vpPoint> listOfPts(3);
297 listOfPts[0] = point1;
298 listOfPts[1] = point2;
299 listOfPts[2] = point3;
303 if(listOfPoints3f.size() == listOfPts.size()) {
304 for(
size_t i = 0; i < 3; i++) {
305 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++;
311 std::cout <<
"testConvertFromPointToPoint3f=" << nbOk <<
"/" << (nbOk + nbNOk) << std::endl;
316 testConvertFromImagePointToPoint2f();
317 testConvertFromPoint2fToImagePoint();
318 testConvertFromImagePointToPoint2d();
319 testConvertFromPoint2dToImagePoint();
321 testConvertFromKeyPointToImagePoint();
322 testConvertFromPoint3fToPoint();
323 testConvertFromPointToPoint3f();
double get_oY() const
Get the point Y coordinate in the object frame.
void set_oX(const double X)
Set the point X coordinate in the object frame.
Class that defines what is a point.
static void convertToOpenCV(const vpImagePoint &from, cv::Point2f &to)
void set_oZ(const double Z)
Set the point Z coordinate in the object frame.
double get_oZ() const
Get the point Z coordinate in the object frame.
double get_oX() const
Get the point X 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)
void set_oY(const double Y)
Set the point Y coordinate in the object frame.