Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-bridge-opencv-camera-param.cpp
1
2#include <iostream>
3
4#include <visp3/core/vpConfig.h>
5
6#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) \
7 && (((VISP_HAVE_OPENCV_VERSION < 0x050000) && defined(HAVE_OPENCV_CALIB3D)) || ((VISP_HAVE_OPENCV_VERSION >= 0x050000) && defined(HAVE_OPENCV_3D)))
8
9#include <visp3/core/vpCameraParameters.h>
10#include <visp3/core/vpImageConvert.h>
11#include <visp3/io/vpImageIo.h>
12
13#if defined(HAVE_OPENCV_CALIB3D)
14#include <opencv2/calib3d/calib3d.hpp>
15#elif defined(HAVE_OPENCV_3D)
16#include <opencv2/3d.hpp>
17#endif
18#include <opencv2/core/core.hpp>
19#include <opencv2/imgproc/imgproc.hpp>
20
21int main()
22{
23#ifdef ENABLE_VISP_NAMESPACE
24 using namespace VISP_NAMESPACE_NAME;
25#endif
27 double u0 = 326.6;
28 double v0 = 215.0;
29 double px = 582.7;
30 double py = 580.6;
31 double kud = -0.3372;
32 double kdu = 0.4021;
33 vpCameraParameters cam(px, py, u0, v0, kud, kdu);
35
37 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);
38 cv::Mat D = (cv::Mat_<double>(4, 1) << cam.get_kud(), 0, 0, 0);
40
43 std::string image_name = "chessboard.jpeg";
44 std::cout << "Read image: " << image_name << std::endl;
45 vpImageIo::read(I, image_name);
47
49 cv::Mat image;
52
54 cv::Mat imageUndistorted;
55 cv::undistort(image, imageUndistorted, K, D);
57
59 vpImage<unsigned char> IUndistorted;
60 vpImageConvert::convert(imageUndistorted, IUndistorted);
62
64 image_name = "chessboard-undistorted.jpeg";
65 std::cout << "Save undistorted image: " << image_name << std::endl;
66 vpImageIo::write(IUndistorted, image_name);
68}
69
70#else
71int main()
72{
73#if !defined(HAVE_OPENCV_IMGPROC)
74 std::cout << "This tutorial requires OpenCV imgproc module." << std::endl;
75#endif
76#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION < 0x050000) && !defined(HAVE_OPENCV_CALIB3D)
77 std::cout << "This tutorial requires OpenCV calib3d module." << std::endl;
78#endif
79#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x050000) && !defined(HAVE_OPENCV_3D)
80 std::cout << "This tutorial requires OpenCV 3d module." << std::endl;
81#endif
82 return EXIT_SUCCESS;
83}
84#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:131