Visual Servoing Platform  version 3.6.1 under development (2024-04-19)
tutorial-image-converter.cpp
1 
2 #include <visp3/core/vpImageConvert.h>
3 #include <visp3/io/vpImageIo.h>
4 
5 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
6 #include <opencv2/imgcodecs.hpp>
7 #include <opencv2/imgproc/imgproc.hpp>
8 #endif
9 
10 int main()
11 {
12 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_IMGCODECS)
13  try {
14  cv::Mat A;
15 #if VISP_HAVE_OPENCV_VERSION >= 0x030200
16  int flags = cv::IMREAD_GRAYSCALE | cv::IMREAD_IGNORE_ORIENTATION;
17 #elif VISP_HAVE_OPENCV_VERSION >= 0x030000
18  int flags = cv::IMREAD_GRAYSCALE;
19 #else
20  int flags = CV_LOAD_IMAGE_GRAYSCALE;
21 #endif
22 
23  A = cv::imread("monkey.bmp", flags);
24 
27 
28 #ifdef VISP_HAVE_PNG
29  vpImageIo::write(I, "monkey.png"); // Gray
30 #endif
31  }
32  catch (const vpException &e) {
33  std::cout << "Catch an exception: " << e << std::endl;
34  }
35 #endif
36 }
error that can be emitted by ViSP classes.
Definition: vpException.h:59
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:287