44#include <visp3/core/vpCameraParameters.h>
45#include <visp3/core/vpDebug.h>
46#include <visp3/core/vpMath.h>
47#include <visp3/core/vpMeterPixelConversion.h>
48#include <visp3/core/vpPixelMeterConversion.h>
52#ifdef ENABLE_VISP_NAMESPACE
57 std::cout <<
"* Test operator=()" << std::endl;
62 std::cerr <<
"Issue with vpCameraParameters comparison operator." << std::endl;
68 std::cerr <<
"Issue with vpCameraParameters comparison operator." << std::endl;
72 std::cout <<
"* Test computeFov()" << std::endl;
75 std::cerr <<
"Issue with vpCameraParameters comparison operator." << std::endl;
81 double px, py, u0, v0;
87 double px_dist, py_dist, u0_dist, v0_dist, kud_dist, kdu_dist;
88 px_dist = 1624.824731;
89 py_dist = 1625.263641;
90 u0_dist = 324.0923411;
91 v0_dist = 245.2421388;
92 kud_dist = -0.1741532338;
93 kdu_dist = 0.1771165148;
95 cam.initPersProjWithoutDistortion(px, py, u0, v0);
100 double x1 = 0, y1 = 0;
101 double u2 = 0, v2 = 0;
102 std::cout <<
"* Test point conversion without distortion" << std::endl;
106 std::cerr <<
"Error in point conversion without distortion:\n"
107 <<
"u1 = " << u1 <<
", u2 = " << u2 << std::endl
108 <<
"v1 = " << v1 <<
", v2 = " << v2 << std::endl;
112 std::cout <<
"* Test point conversion with distortion" << std::endl;
116 std::cerr <<
"Error in point conversion without distortion:\n"
117 <<
"u1 = " << u1 <<
", u2 = " << u2 << std::endl
118 <<
"v1 = " << v1 <<
", v2 = " << v2 << std::endl;
122#if defined(HAVE_OPENCV_IMGPROC) && \
123 (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_CALIB)))
126 std::cout <<
"* Compare ViSP and OpenCV point pixel meter conversion without distortion" << std::endl;
127 cv::Mat cameraMatrix = (cv::Mat_<double>(3, 3) << px, 0, u0, 0, py, v0, 0, 0, 1);
128 cv::Mat distCoeffs = cv::Mat::zeros(5, 1, CV_64FC1);
134 std::cerr <<
"Error in point pixel meter conversion: visp result (" << x1 <<
", " << y1 <<
") "
135 <<
"differ from OpenCV result (" << x2 <<
", " << y2 <<
")" << std::endl;
143 std::cerr <<
"Error in point pixel meter conversion: visp result (" << x1 <<
", " << y1 <<
") "
144 <<
"differ from OpenCV result (" << x2 <<
", " << y2 <<
")" << std::endl;
148 std::cout <<
"* Compare ViSP and OpenCV point meter pixel conversion without distortion" << std::endl;
152 std::cerr <<
"Error in point meter pixel conversion: visp result (" << u1 <<
", " << v1 <<
") "
153 <<
"differ from OpenCV result (" << u2 <<
", " << v2 <<
")" << std::endl;
161 std::cerr <<
"Error in point meter pixel conversion: visp result (" << u1 <<
", " << v1 <<
") "
162 <<
"differ from OpenCV result (" << u2 <<
", " << v2 <<
")" << std::endl;
168 std::cout <<
"* Compare ViSP and OpenCV point pixel meter conversion with distortion" << std::endl;
169 cv::Mat cameraMatrix = (cv::Mat_<double>(3, 3) << px_dist, 0, u0_dist, 0, py_dist, v0_dist, 0, 0, 1);
170 cv::Mat distCoeffs = cv::Mat::zeros(5, 1, CV_64FC1);
171 distCoeffs.at<
double>(0, 0) = kdu_dist;
177 std::cerr <<
"Error in point conversion: visp result (" << x1 <<
", " << y1 <<
") "
178 <<
"differ from OpenCV result (" << x2 <<
", " << y2 <<
")" << std::endl;
182 std::cout <<
"* Compare ViSP and OpenCV point meter pixel conversion with distortion" << std::endl;
183 distCoeffs.at<
double>(0, 0) = kud_dist;
187 std::cerr <<
"Error in point meter pixel conversion: visp result (" << u1 <<
", " << v1 <<
") "
188 <<
"differ from OpenCV result (" << u2 <<
", " << v2 <<
")" << std::endl;
194 std::cout <<
"* Compare ViSP and OpenCV line pixel meter conversion without distortion" << std::endl;
195 cv::Mat cameraMatrix = (cv::Mat_<double>(3, 3) << px, 0, u0, 0, py, v0, 0, 0, 1);
197 double rho_m1, theta_m1, rho_m2, theta_m2;
202 std::cerr <<
"Error in line pixel meter conversion: visp result (" << rho_m1 <<
", " << theta_m1 <<
") "
203 <<
"differ from OpenCV result (" << rho_m2 <<
", " << theta_m1 <<
")" << std::endl;
207 std::cout <<
"* Compare ViSP and OpenCV line meter pixel conversion without distortion" << std::endl;
208 double rho_p1, theta_p1, rho_p2, theta_p2;
212 std::cerr <<
"Error in line meter pixel conversion: visp result (" << rho_p1 <<
", " << theta_p1 <<
") "
213 <<
"differ from OpenCV result (" << rho_p2 <<
", " << theta_p1 <<
")" << std::endl;
219 std::cout <<
"* Compare ViSP and OpenCV moments pixel meter conversion without distortion" << std::endl;
220 cv::Mat cameraMatrix = (cv::Mat_<double>(3, 3) << px, 0, u0, 0, py, v0, 0, 0, 1);
221 unsigned int order = 3;
222 double m00 = 2442, m10 = 414992, m01 = 470311, m11 = 7.99558e+07, m02 = 9.09603e+07, m20 = 7.11158e+07;
225 vpMatrix m1(order, order), m2(order, order);
236 for (
unsigned int i = 0;
i < m1.getRows();
i++) {
237 for (
unsigned int j = 0;
j < m1.getCols();
j++) {
239 std::cerr <<
"Error in moments pixel meter conversion: visp result for [" <<
i <<
"][" <<
j <<
"] ("
241 <<
"differ from OpenCV result (" << m2[
i][
j] <<
")" << std::endl;
249 std::cout <<
"* Compare ViSP and OpenCV ellipse from circle meter pixel conversion without distortion"
251 cv::Mat cameraMatrix = (cv::Mat_<double>(3, 3) << px, 0, u0, 0, py, v0, 0, 0, 1);
258 double n20_p1, n11_p1, n02_p1, n20_p2, n11_p2, n02_p2;
265 std::cerr <<
"Error in ellipse from circle meter pixel conversion: visp result (" << n20_p1 <<
", " << n11_p1
266 <<
", " << n02_p1 <<
") "
267 <<
"differ from OpenCV result (" << n20_p2 <<
", " << n11_p2 <<
", " << n02_p2 <<
")" << std::endl;
271 std::cerr <<
"Error in ellipse from circle meter pixel conversion: visp result (" << center_p1 <<
") "
272 <<
"differ from OpenCV result (" << center_p2 <<
")" << std::endl;
276 std::cout <<
"* Compare ViSP and OpenCV ellipse from sphere meter pixel conversion without distortion"
287 std::cerr <<
"Error in ellipse from sphere meter pixel conversion: visp result (" << n20_p1 <<
", " << n11_p1
288 <<
", " << n02_p1 <<
") "
289 <<
"differ from OpenCV result (" << n20_p2 <<
", " << n11_p2 <<
", " << n02_p2 <<
")" << std::endl;
293 std::cerr <<
"Error in ellipse from sphere meter pixel conversion: visp result (" << center_p1 <<
") "
294 <<
"differ from OpenCV result (" << center_p2 <<
")" << std::endl;
300 std::cout <<
"Test successful" << std::endl;
304 std::cout <<
"Catch an exception: " <<
e << std::endl;
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
void initPersProjWithDistortion(double px, double py, double u0, double v0, double kud, double kdu)
void computeFov(const unsigned int &w, const unsigned int &h)
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
void changeFrame(const vpHomogeneousMatrix &noMo, vpColVector &noP) const VP_OVERRIDE
void projection() VP_OVERRIDE
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
static double rad(double deg)
static bool equal(double x, double y, double threshold=0.001)
Implementation of a matrix and operations on matrices.
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
static void convertEllipse(const vpCameraParameters &cam, const vpSphere &sphere, vpImagePoint ¢er_p, double &n20_p, double &n11_p, double &n02_p)
static void convertMoment(const vpCameraParameters &cam, unsigned int order, const vpMatrix &moment_pixel, vpMatrix &moment_meter)
static void convertLine(const vpCameraParameters &cam, const double &rho_p, const double &theta_p, double &rho_m, double &theta_m)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE