Visual Servoing Platform  version 3.6.1 under development (2024-04-26)
tutorial-image-converter.cpp
#include <visp3/core/vpImageConvert.h>
#include <visp3/io/vpImageIo.h>
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
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);
#ifdef VISP_HAVE_PNG
vpImageIo::write(I, "monkey.png"); // Gray
#endif
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
}
#endif
}
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