Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-bridge-opencv-camera-param.cpp
1
2#include <iostream>
3#include <visp3/core/vpCameraParameters.h>
4#include <visp3/core/vpImageConvert.h>
5#include <visp3/io/vpImageIo.h>
6
7#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_CALIB3D) && defined(HAVE_OPENCV_IMGPROC)
8#include <opencv2/calib3d/calib3d.hpp>
9#include <opencv2/core/core.hpp>
10#include <opencv2/imgproc/imgproc.hpp>
11
12int main()
13{
15 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;
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}
53
54#else
55int main()
56{
57 std::cout << "This tutorial required OpenCV imgproc module" << std::endl;
58 return EXIT_SUCCESS;
59}
60#endif
Generic class defining intrinsic camera parameters.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
Definition vpImage.h:135