Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-undistort.cpp
1
2#include <visp3/core/vpImageTools.h>
3#include <visp3/core/vpIoTools.h>
4#include <visp3/core/vpXmlParserCamera.h>
5#include <visp3/io/vpImageIo.h>
6
7int main(int argc, char **argv)
8{
9 std::string opt_input_image = "chessboard.jpg";
10 std::string opt_camera_file = "camera.xml";
11 std::string opt_camera_name = "Camera";
12
13 try {
14 for (int i = 1; i < argc; i++) {
15 if (std::string(argv[i]) == "--image" && i + 1 < argc) {
16 opt_input_image = std::string(argv[i + 1]);
17 } else if (std::string(argv[i]) == "--camera-file" && i + 1 < argc) {
18 opt_camera_file = std::string(argv[i + 1]);
19 } else if (std::string(argv[i]) == "--camera-name" && i + 1 < argc) {
20 opt_camera_name = std::string(argv[i + 1]);
21 } else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
22 std::cout << argv[0] << " [--image <input image (pgm,ppm,jpeg,png,tiff,bmp,ras,jp2)>]"
23 << " [--camera-file <xml file>] [--camera-name <name>] [--help] [-h]\n"
24 << std::endl;
25 std::cout << "Examples: " << std::endl
26 << argv[0] << std::endl
27 << argv[0] << " --image chessboard.jpg --camera-file camera.xml --camera-name Camera" << std::endl;
28 return EXIT_SUCCESS;
29 }
30 }
31
34 std::cout << "Read input image: " << opt_input_image << std::endl;
35 vpImageIo::read(I, opt_input_image);
37
43 if (p.parse(cam, opt_camera_file, opt_camera_name, projModel, I.getWidth(), I.getHeight()) !=
45 std::cout << "Cannot found parameters for camera named \"Camera\"" << std::endl;
46 }
49#if 0
50 cam.initPersProjWithDistortion(582.7, 580.6, 326.6, 215.0, -0.3372, 0.4021);
51#endif
53
54 std::cout << cam << std::endl;
55
58 vpImageTools::undistort(I, cam, Iud);
59 std::string name_we = vpIoTools::getNameWE(opt_input_image);
60 std::string ext = vpIoTools::getFileExtension(opt_input_image);
61 std::string output_image = name_we + "-undistort" + ext;
62 std::cout << "Save undistorted image in: " << output_image << std::endl;
63 vpImageIo::write(Iud, output_image);
65 } catch (const vpException &e) {
66 std::cout << "Catch an exception: " << e << std::endl;
67 return EXIT_FAILURE;
68 }
69
70 return EXIT_SUCCESS;
71}
Generic class defining intrinsic camera parameters.
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
void initPersProjWithDistortion(double px, double py, double u0, double v0, double kud, double kdu)
error that can be emitted by ViSP classes.
Definition vpException.h:59
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)
static void undistort(const vpImage< Type > &I, const vpCameraParameters &cam, vpImage< Type > &newI, unsigned int nThreads=2)
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
static std::string getFileExtension(const std::string &pathname, bool checkFile=false)
static std::string getNameWE(const std::string &pathname)
XML parser to load and save intrinsic camera parameters.
int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, unsigned int image_width=0, unsigned int image_height=0, bool verbose=true)