Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tutorial-bridge-opencv.cpp
1 #include <visp3/core/vpCameraParameters.h>
3 #include <visp3/io/vpImageIo.h>
4 #include <visp3/core/vpImageConvert.h>
5 
6 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
7 #include <opencv2/core/core.hpp>
8 #include <opencv2/imgproc/imgproc.hpp>
9 #endif
10 
11 int main()
12 {
13 #if VISP_HAVE_OPENCV_VERSION >= 0x020300
14  double u0 = 326.6;
16  double v0 = 215.0;
17  double px = 582.7;
18  double py = 580.6;
19  double kud = -0.3372;
20  double kdu = 0.4021;
21  vpCameraParameters cam(px, py, u0, v0, kud, kdu);
23 
25  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);
26  cv::Mat D = (cv::Mat_<double>(4,1) << cam.get_kud(), 0, 0, 0);
28 
31  vpImageIo::read(I, "chessboard.pgm");
33 
35  cv::Mat image;
36  vpImageConvert::convert(I, image);
38 
40  cv::Mat imageUndistorted;
41  cv::undistort(image, imageUndistorted, K, D);
43 
45  vpImage<unsigned char> IUndistorted;
46  vpImageConvert::convert(imageUndistorted, IUndistorted);
48 
50  vpImageIo::write(IUndistorted, "chessboard-undistorted.pgm");
52 #endif
53 }
double get_u0() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
double get_py() const
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:368
double get_v0() const
Generic class defining intrinsic camera parameters.
double get_px() const
double get_kud() const
static void read(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:205