Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
tutorial-image-converter.cpp
1 
2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpImageConvert.h>
4 #include <visp3/io/vpImageIo.h>
5 
6 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
7 #include <opencv2/imgcodecs.hpp>
8 #include <opencv2/imgproc/imgproc.hpp>
9 #endif
10 
11 int main()
12 {
13 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_IMGCODECS)
14 #ifdef ENABLE_VISP_NAMESPACE
15  using namespace VISP_NAMESPACE_NAME;
16 #endif
17  try {
18  cv::Mat A;
19 #if VISP_HAVE_OPENCV_VERSION >= 0x030200
20  int flags = cv::IMREAD_GRAYSCALE | cv::IMREAD_IGNORE_ORIENTATION;
21 #elif VISP_HAVE_OPENCV_VERSION >= 0x030000
22  int flags = cv::IMREAD_GRAYSCALE;
23 #else
24  int flags = CV_LOAD_IMAGE_GRAYSCALE;
25 #endif
26 
27  A = cv::imread("monkey.bmp", flags);
28 
31 
32 #ifdef VISP_HAVE_PNG
33  vpImageIo::write(I, "monkey.png"); // Gray
34 #endif
35  }
36  catch (const vpException &e) {
37  std::cout << "Catch an exception: " << e << std::endl;
38  }
39 #endif
40 }
error that can be emitted by ViSP classes.
Definition: vpException.h:60
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:291