File: tutorial-image-converter.cpp

package info (click to toggle)
visp 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 119,296 kB
  • sloc: cpp: 500,914; ansic: 52,904; xml: 22,642; python: 7,365; java: 4,247; sh: 482; makefile: 237; objc: 145
file content (30 lines) | stat: -rw-r--r-- 818 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*! \example tutorial-image-converter.cpp */
#include <visp3/core/vpImageConvert.h>
#include <visp3/io/vpImageIo.h>

int main()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_IMGCODECS)
  try {
    cv::Mat A;
#if VISP_HAVE_OPENCV_VERSION >= 0x030200
    int flags = cv::IMREAD_GRAYSCALE | cv::IMREAD_IGNORE_ORIENTATION;
#elif VISP_HAVE_OPENCV_VERSION >= 0x030000
    int flags = cv::IMREAD_GRAYSCALE;
#else
    int flags = CV_LOAD_IMAGE_GRAYSCALE;
#endif

    A = cv::imread("monkey.bmp", flags);

    vpImage<unsigned char> I;
    vpImageConvert::convert(A, I);

#ifdef VISP_HAVE_PNG
    vpImageIo::write(I, "monkey.png"); // Gray
#endif
  } catch (const vpException &e) {
    std::cout << "Catch an exception: " << e << std::endl;
  }
#endif
}