Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
tutorial-bridge-opencv.cpp
1 #include <visp3/core/vpCameraParameters.h>
3 #include <visp3/core/vpImageConvert.h>
4 #include <visp3/io/vpImageIo.h>
5 
6 #if VISP_HAVE_OPENCV_VERSION >= 0x040000
7 #include <opencv2/core/core.hpp>
8 #include <opencv2/imgproc/imgproc.hpp>
9 #include <opencv2/calib3d/calib3d.hpp>
10 #elif VISP_HAVE_OPENCV_VERSION >= 0x020300
11 #include <opencv2/core/core.hpp>
12 #include <opencv2/imgproc/imgproc.hpp>
13 #endif
14 
15 int main()
16 {
17 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
18  double u0 = 326.6;
20  double v0 = 215.0;
21  double px = 582.7;
22  double py = 580.6;
23  double kud = -0.3372;
24  double kdu = 0.4021;
25  vpCameraParameters cam(px, py, u0, v0, kud, kdu);
27 
29  cv::Mat K = (cv::Mat_<double>(3, 3) << cam.get_px(), 0, cam.get_u0(), 0, cam.get_py(), cam.get_v0(), 0, 0, 1);
30  cv::Mat D = (cv::Mat_<double>(4, 1) << cam.get_kud(), 0, 0, 0);
32 
35  vpImageIo::read(I, "chessboard.pgm");
37 
39  cv::Mat image;
40  vpImageConvert::convert(I, image);
42 
44  cv::Mat imageUndistorted;
45  cv::undistort(image, imageUndistorted, K, D);
47 
49  vpImage<unsigned char> IUndistorted;
50  vpImageConvert::convert(imageUndistorted, IUndistorted);
52 
54  vpImageIo::write(IUndistorted, "chessboard-undistorted.pgm");
56 #endif
57 }
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:445
Generic class defining intrinsic camera parameters.
static void read(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:243
double get_kud() const