Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
tutorial-undistort.cpp
1 #include <visp3/core/vpImageTools.h>
3 #include <visp3/core/vpXmlParserCamera.h>
4 #include <visp3/io/vpImageIo.h>
5 
6 int main()
7 {
8  try {
11  vpImageIo::read(I, "chessboard.pgm");
13 
16 #ifdef VISP_HAVE_XML2
20  if (p.parse(cam, "camera.xml", "Camera", projModel, I.getWidth(), I.getHeight()) !=
22  std::cout << "Cannot found parameters for camera named \"Camera\"" << std::endl;
23  }
26 #else
27  cam.initPersProjWithDistortion(582.7, 580.6, 326.6, 215.0, -0.3372, 0.4021);
28 #endif
29 
31  std::cout << cam << std::endl;
32 
35  vpImageTools::undistort(I, cam, Iud);
36  vpImageIo::write(Iud, "chessboard-undistort.pgm");
38  } catch (const vpException &e) {
39  std::cout << "Catch an exception: " << e << std::endl;
40  }
41 
42  return 0;
43 }
unsigned int getWidth() const
Definition: vpImage.h:239
error that can be emited by ViSP classes.
Definition: vpException.h:71
XML parser to load and save intrinsic camera parameters.
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:375
Generic class defining intrinsic camera parameters.
static void undistort(const vpImage< Type > &I, const vpCameraParameters &cam, vpImage< Type > &newI, unsigned int nThreads=2)
Definition: vpImageTools.h:621
static void read(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:207
unsigned int getHeight() const
Definition: vpImage.h:178
int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, const unsigned int image_width=0, const unsigned int image_height=0)
void initPersProjWithDistortion(const double px, const double py, const double u0, const double v0, const double kud, const double kdu)