Visual Servoing Platform  version 3.6.1 under development (2024-03-18)
vpImageIo Class Reference

#include <visp3/io/vpImageIo.h>

Public Types

enum  vpImageIoBackendType {
  IO_DEFAULT_BACKEND , IO_SYSTEM_LIB_BACKEND , IO_OPENCV_BACKEND , IO_SIMDLIB_BACKEND ,
  IO_STB_IMAGE_BACKEND
}
 

Static Public Member Functions

static void read (vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void read (vpImage< vpRGBa > &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 write (const vpImage< vpRGBa > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void readPFM (vpImage< float > &I, const std::string &filename)
 
static void readPFM_HDR (vpImage< float > &I, const std::string &filename)
 
static void readPFM_HDR (vpImage< vpRGBf > &I, const std::string &filename)
 
static void readPGM (vpImage< unsigned char > &I, const std::string &filename)
 
static void readPGM (vpImage< vpRGBa > &I, const std::string &filename)
 
static void readPPM (vpImage< unsigned char > &I, const std::string &filename)
 
static void readPPM (vpImage< vpRGBa > &I, const std::string &filename)
 
static void readJPEG (vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void readJPEG (vpImage< vpRGBa > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void readPNG (vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void readPNG (vpImage< vpRGBa > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void readEXR (vpImage< float > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void readEXR (vpImage< vpRGBf > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void writePFM (const vpImage< float > &I, const std::string &filename)
 
static void writePFM_HDR (const vpImage< float > &I, const std::string &filename)
 
static void writePFM_HDR (const vpImage< vpRGBf > &I, const std::string &filename)
 
static void writePGM (const vpImage< unsigned char > &I, const std::string &filename)
 
static void writePGM (const vpImage< short > &I, const std::string &filename)
 
static void writePGM (const vpImage< vpRGBa > &I, const std::string &filename)
 
static void writePPM (const vpImage< unsigned char > &I, const std::string &filename)
 
static void writePPM (const vpImage< vpRGBa > &I, const std::string &filename)
 
static void writeJPEG (const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND, int quality=90)
 
static void writeJPEG (const vpImage< vpRGBa > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND, int quality=90)
 
static void writePNG (const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void writePNG (const vpImage< vpRGBa > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void writeEXR (const vpImage< float > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void writeEXR (const vpImage< vpRGBf > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
 
static void readPNGfromMem (const std::vector< unsigned char > &buffer, vpImage< unsigned char > &I, int backend=IO_DEFAULT_BACKEND)
 
static void readPNGfromMem (const std::vector< unsigned char > &buffer, vpImage< vpRGBa > &I, int backend=IO_DEFAULT_BACKEND)
 
static void writePNGtoMem (const vpImage< unsigned char > &I, std::vector< unsigned char > &buffer, int backend=IO_DEFAULT_BACKEND)
 
static void writePNGtoMem (const vpImage< vpRGBa > &I, std::vector< unsigned char > &buffer, int backend=IO_DEFAULT_BACKEND, bool saveAlpha=false)
 

Detailed Description

Read/write images with various image format.

This class has its own implementation of PGM and PPM images read/write.

This class may benefit from optional 3rd parties:

  • libpng: If installed this optional 3rd party is used to read/write PNG images. Installation instructions are provided here https://visp.inria.fr/3rd_png.
  • libjpeg: If installed this optional 3rd party is used to read/write JPEG images. Installation instructions are provided here https://visp.inria.fr/3rd_jpeg.
  • OpenCV: If installed this optional 3rd party is used to read/write other image formats TIFF, BMP, DIB, PBM, RASTER, JPEG2000. If libpng or libjpeg is not installed OpenCV is also used to consider these image formats. Installation instructions are provided here https://visp.inria.fr/3rd_opencv.

The code below shows how to convert an PPM P6 image file format into a PGM P5 image file format. The extension of the filename is here used in read() and write() functions to set the image file format (".pgm" for PGM P5 and ".ppm" for PPM P6).

#include <visp3/io/vpImageIo.h>
int main()
{
#if defined(_WIN32)
std::string filename("C:/Temp/visp-images/Klimt/Klimt.ppm");
#else // UNIX
std::string filename("/local/soft/ViSP/ViSP-images/Klimt/Klimt.ppm");
#endif
vpImageIo::read(I, filename); // Convert the color image in a gray level image
vpImageIo::write(I, "Klimt.pgm"); // Write the image in a PGM P5 image file format
}
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:143
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:287

This other example available in tutorial-image-reader.cpp shows how to read/write jpeg images. It supposes that libjpeg is installed.

#include <visp3/io/vpImageIo.h>
int main()
{
try {
vpImageIo::read(I, "monkey.jpeg");
vpImageIo::write(I, "monkey.png");
} catch (const vpException &e) {
std::cout << e.getMessage() << std::endl;
} catch (...) {
std::cout << "Unsupported image format" << std::endl;
}
}
error that can be emitted by ViSP classes.
Definition: vpException.h:59
const char * getMessage() const
Definition: vpException.cpp:64

Definition at line 98 of file vpImageIo.h.

Member Enumeration Documentation

◆ vpImageIoBackendType

Image IO backend for only jpeg and png formats image loading and saving.

Enumerator
IO_DEFAULT_BACKEND 

Default backend.

IO_SYSTEM_LIB_BACKEND 

Use system libraries like libpng or libjpeg-turbo.

IO_OPENCV_BACKEND 

Use OpenCV imgcodecs module.

IO_SIMDLIB_BACKEND 

Use embedded simd library.

IO_STB_IMAGE_BACKEND 

Use embedded stb_image library.

Definition at line 122 of file vpImageIo.h.

Member Function Documentation

◆ read() [1/2]

void vpImageIo::read ( vpImage< unsigned char > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Read the contents of the image filename, allocate memory for the corresponding grayscale image, update its content, and return a reference to the image.

If the image has been already initialized, memory allocation is done only if the new image size is different, else we re-use the same memory space.

Supported formats are:

  • portable gray map: *.pgm file
  • portable pix map: *.ppm file
  • portable float map: *.pfm file
  • jpeg: *.jpg, *.jpeg files
  • png: *.png file

If ViSP is build with OpenCV support, additional formats are considered:

  • *.jp2, *.rs, *.ras, *.tiff, *.tif, *.png, *.bmp, *.pbm files.

If EXIF information is embedded in the image file, the EXIF orientation is ignored.

Parameters
I: Image to set with the filename content.
filename: Name of the file containing the image.
backend: Library backend type (see vpImageIo::vpImageIoBackendType) for image reading. This parameter is only used when the image need to be loaded in jpeg or png format. To know which is the default backend see respectively void vpImageIo::readJPEG(const vpImage<unsigned char> &, const std::string &, int) and void vpImageIo::readPNG(const vpImage<unsigned char> &, const std::string &, int).
Examples
displayD3D.cpp, displayGTK.cpp, displayOpenCV.cpp, displaySequence.cpp, displayX.cpp, displayXMulti.cpp, histogram.cpp, imageDiskRW.cpp, manDisplay.cpp, mbtGenericTrackingDepth.cpp, mbtGenericTrackingDepthOnly.cpp, perfImageAddSub.cpp, photometricVisualServoing.cpp, photometricVisualServoingWithoutVpServo.cpp, poseVirtualVS.cpp, readRealSenseData.cpp, testAprilTag.cpp, testAutoThreshold.cpp, testClick.cpp, testColorConversion.cpp, testConnectedComponents.cpp, testContours.cpp, testConversion.cpp, testCrop.cpp, testCropAdvanced.cpp, testFloodFill.cpp, testGaussianFilter.cpp, testGenericTracker.cpp, testGenericTrackerDepth.cpp, testHistogram.cpp, testImageAddSub.cpp, testImageComparison.cpp, testImageFilter.cpp, testImageWarp.cpp, testImgproc.cpp, testIoPGM.cpp, testIoPPM.cpp, testKeyPoint-2.cpp, testKeyPoint-3.cpp, testKeyPoint-4.cpp, testKeyPoint-5.cpp, testKeyPoint-6.cpp, testKeyPoint-7.cpp, testKeyPoint.cpp, testMomentAlpha.cpp, testMouseEvent.cpp, testPerformanceLUT.cpp, testReadImage.cpp, testTrackDot.cpp, testUndistortImage.cpp, testVideoDevice.cpp, trackDot.cpp, trackDot2.cpp, trackDot2WithAutoDetection.cpp, trackKltOpencv.cpp, trackMeCircle.cpp, trackMeLine.cpp, tutorial-apriltag-detector.cpp, tutorial-autothreshold.cpp, tutorial-barcode-detector.cpp, tutorial-blob-auto-tracker.cpp, tutorial-bridge-opencv-camera-param.cpp, tutorial-bridge-opencv-image.cpp, tutorial-brightness-adjustment.cpp, tutorial-circle-hough.cpp, tutorial-connected-components.cpp, tutorial-contour.cpp, tutorial-contrast-sharpening.cpp, tutorial-count-coins.cpp, tutorial-detection-object-mbt2-deprecated.cpp, tutorial-detection-object-mbt2.cpp, tutorial-ibvs-4pts-image-tracking.cpp, tutorial-image-colormap.cpp, tutorial-image-filter.cpp, tutorial-image-reader.cpp, tutorial-image-simulator.cpp, tutorial-image-viewer.cpp, tutorial-mb-generic-tracker-rgbd-blender.cpp, tutorial-mb-generic-tracker-rgbd.cpp, tutorial-pose-from-planar-object.cpp, tutorial-pose-from-points-image.cpp, tutorial-pose-from-qrcode-image.cpp, tutorial-undistort.cpp, and tutorial-viewer.cpp.

Definition at line 143 of file vpImageIo.cpp.

References vpIoTools::checkFilename(), vpImageException::ioError, vpIoTools::path(), readJPEG(), readPGM(), readPNG(), and readPPM().

Referenced by vpDiskGrabber::acquire(), vpImageSimulator::init(), vpMbTracker::initClick(), vpKeyPoint::loadLearningData(), and vpVirtualGrabber::vpVirtualGrabber().

◆ read() [2/2]

void vpImageIo::read ( vpImage< vpRGBa > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Read the contents of the image filename, allocate memory for the corresponding grayscale image, update its content, and return a reference to the image.

If the image has been already initialized, memory allocation is done only if the new image size is different, else we re-use the same memory space.

Supported formats are:

  • portable gray map: *.pgm file
  • portable pix map: *.ppm file
  • portable float map: *.pfm file
  • jpeg: *.jpg, *.jpeg files
  • png: *.png file

If ViSP is build with OpenCV support, additional formats are considered:

  • *.jp2, *.rs, *.ras, *.tiff, *.tif, *.png, *.bmp, *.pbm files.

If EXIF information is embedded in the image file, the EXIF orientation is ignored.

Parameters
I: Image to set with the filename content.
filename: Name of the file containing the image.
backend: Library backend type (see vpImageIo::vpImageIoBackendType) for image reading. This parameter is only used when the image need to be loaded in jpeg or png format. To know which is the default backend see respectively void vpImageIo::readJPEG(const vpImage<unsigned char> &, const std::string &, int) and void vpImageIo::readPNG(const vpImage<unsigned char> &, const std::string &, int).

Definition at line 219 of file vpImageIo.cpp.

References vpIoTools::checkFilename(), vpImageException::ioError, vpIoTools::path(), readJPEG(), readPGM(), readPNG(), and readPPM().

◆ readEXR() [1/2]

void vpImageIo::readEXR ( vpImage< float > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Load an image in EXR format.

Parameters
[out]I: Floating-point single channel image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Only OpenCV and the Tiny OpenEXR image libraries can currently read EXR image. The default backend vpImageIo::IO_DEFAULT_BACKEND is the Tiny OpenEXR image library.
Examples
testIoEXR.cpp.

Definition at line 723 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ readEXR() [2/2]

void vpImageIo::readEXR ( vpImage< vpRGBf > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Load an image in EXR format.

Parameters
[out]I: Floating-point three channels image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Only OpenCV and the Tiny OpenEXR image libraries can currently read EXR image. The default backend vpImageIo::IO_DEFAULT_BACKEND is the Tiny OpenEXR image library.

Definition at line 772 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ readJPEG() [1/2]

void vpImageIo::readJPEG ( vpImage< unsigned char > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Load a jpeg image. If it is a color image it is converted in gray.

Parameters
[out]I: Gray level image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Depending on its availability, the default backend vpImageIo::IO_DEFAULT_BACKEND is chosen in the following order: vpImageIo::IO_OPENCV_BACKEND, vpImageIo::IO_SYSTEM_LIB_BACKEND, vpImageIo::IO_STB_IMAGE_BACKEND.

Definition at line 395 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

Referenced by read().

◆ readJPEG() [2/2]

void vpImageIo::readJPEG ( vpImage< vpRGBa > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Load a jpeg image. If it is a gray image it is converted in color.

Parameters
[out]I: Color image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Depending on its availability, the default backend vpImageIo::IO_DEFAULT_BACKEND is chosen in the following order: vpImageIo::IO_OPENCV_BACKEND, vpImageIo::IO_SYSTEM_LIB_BACKEND, vpImageIo::IO_STB_IMAGE_BACKEND.

Definition at line 478 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ readPFM()

void vpImageIo::readPFM ( vpImage< float > &  I,
const std::string &  filename 
)
static

Load an image in portable float map format.

Parameters
[out]I: Image read from filename.
[in]filename: Image location.

Definition at line 1340 of file vpImageIo.cpp.

Referenced by vpDiskGrabber::acquire().

◆ readPFM_HDR() [1/2]

void vpImageIo::readPFM_HDR ( vpImage< float > &  I,
const std::string &  filename 
)
static

Load an image in portable float map format and not restricted to the [0, 255] dynamic range.

Parameters
[out]I: Image read from filename.
[in]filename: Image location.
Examples
testIoEXR.cpp, testIoPFM.cpp, and tutorial-image-colormap.cpp.

Definition at line 1347 of file vpImageIo.cpp.

◆ readPFM_HDR() [2/2]

void vpImageIo::readPFM_HDR ( vpImage< vpRGBf > &  I,
const std::string &  filename 
)
static

Load an image in portable float map format and not restricted to the [0, 255] dynamic range.

Parameters
[out]I: Image read from filename and with three channels.
[in]filename: Image location.

Definition at line 1354 of file vpImageIo.cpp.

◆ readPGM() [1/2]

void vpImageIo::readPGM ( vpImage< unsigned char > &  I,
const std::string &  filename 
)
static

Load an image in portable gray map format. If the image is in color, it is converted in gray level.

Parameters
[out]I: Image read from filename.
[in]filename: Image location.

Definition at line 1361 of file vpImageIo.cpp.

Referenced by read().

◆ readPGM() [2/2]

void vpImageIo::readPGM ( vpImage< vpRGBa > &  I,
const std::string &  filename 
)
static

Load an image in portable float map format. If the image is in gray, it is converted in color.

Parameters
[out]I: Image read from filename.
[in]filename: Image location.

Definition at line 1368 of file vpImageIo.cpp.

◆ readPNG() [1/2]

void vpImageIo::readPNG ( vpImage< unsigned char > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Load an image in png format. If it is a color image it is converted in gray.

Parameters
[out]I: Gray level image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Depending on its availability, the default backend vpImageIo::IO_DEFAULT_BACKEND is chosen in the following order: vpImageIo::IO_SYSTEM_LIB_BACKEND, vpImageIo::IO_OPENCV_BACKEND, vpImageIo::IO_STB_IMAGE_BACKEND.

Definition at line 561 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

Referenced by read().

◆ readPNG() [2/2]

void vpImageIo::readPNG ( vpImage< vpRGBa > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Load an image in png format. If it is a gray level image it is converted in color.

Parameters
[out]I: Color image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Depending on its availability, the default backend vpImageIo::IO_DEFAULT_BACKEND is chosen in the following order: vpImageIo::IO_OPENCV_BACKEND, vpImageIo::IO_STB_IMAGE_BACKEND.

Definition at line 644 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ readPNGfromMem() [1/2]

void vpImageIo::readPNGfromMem ( const std::vector< unsigned char > &  buffer,
vpImage< unsigned char > &  I,
int  backend = IO_DEFAULT_BACKEND 
)
static

Read the content of the grayscale image bitmap stored in memory and encoded using the PNG format.

Parameters
[in]buffer: Grayscale image buffer encoded in PNG as 1-D unsigned char vector.
[out]I: Output decoded grayscale image.
[in]backend: Supported backends are IO_OPENCV_BACKEND and IO_STB_IMAGE_BACKEND, default IO_DEFAULT_BACKEND will choose IO_OPENCV_BACKEND if available or IO_STB_IMAGE_BACKEND otherwise.

Definition at line 1405 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ readPNGfromMem() [2/2]

void vpImageIo::readPNGfromMem ( const std::vector< unsigned char > &  buffer,
vpImage< vpRGBa > &  I,
int  backend = IO_DEFAULT_BACKEND 
)
static

Read the content of the grayscale image bitmap stored in memory and encoded using the PNG format.

Parameters
[in]buffer: Color image buffer encoded in PNG as 1-D unsigned char vector.
[out]I: Output decoded color image.
[in]backend: Supported backends are IO_OPENCV_BACKEND and IO_STB_IMAGE_BACKEND, default IO_DEFAULT_BACKEND will choose IO_OPENCV_BACKEND if available or IO_STB_IMAGE_BACKEND otherwise.

Definition at line 1462 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ readPPM() [1/2]

void vpImageIo::readPPM ( vpImage< unsigned char > &  I,
const std::string &  filename 
)
static

Load an image in portable pixmap format. If the image is in color, it is converted in gray level.

Parameters
[out]I: Image read from filename.
[in]filename: Image location.

Definition at line 1375 of file vpImageIo.cpp.

Referenced by read().

◆ readPPM() [2/2]

void vpImageIo::readPPM ( vpImage< vpRGBa > &  I,
const std::string &  filename 
)
static

Load an image in portable pixmap format. If the image is in gray, it is converted in color.

Parameters
[out]I: Image read from filename.
[in]filename: Image location.

Definition at line 1382 of file vpImageIo.cpp.

◆ write() [1/2]

void vpImageIo::write ( const vpImage< unsigned char > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Write the content of the image in the file which name is given by filename.

Supported formats are:

  • portable gray map: *.pgm file
  • portable pix map: *.ppm file
  • portable float map: *.pfm file
  • jpeg: *.jpg, *.jpeg files
  • png: *.png file

If ViSP is build with OpenCV support, additional formats are considered:

  • *.jp2, *.rs, *.ras, *.tiff, *.tif, *.png, *.bmp, *.pbm files.
Parameters
I: Image to write.
filename: Name of the file containing the image.
backend: Library backend type (see vpImageIo::vpImageIoBackendType) for image writing. This parameter is only used when the image need to be saved in jpeg or png format. To know which is the default backend see respectively void vpImageIo::writeJPEG(const vpImage<unsigned char> &, const std::string &, int, int) and void vpImageIo::writePNG(const vpImage<unsigned char> &, const std::string &, int).
Examples
SickLDMRS-Process.cpp, displayD3D.cpp, displayGTK.cpp, displayOpenCV.cpp, displayX.cpp, displayXMulti.cpp, grab1394CMU.cpp, grab1394Two.cpp, grabDirectShow.cpp, grabDirectShowMulti.cpp, grabFlyCapture.cpp, grabV4l2.cpp, imageDiskRW.cpp, manDisplay.cpp, manGeometricFeatures.cpp, mbot-apriltag-2D-half-vs.cpp, mbot-apriltag-ibvs.cpp, mbot-apriltag-pbvs.cpp, saveRealSenseData.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, sonarPioneerReader.cpp, test1394TwoGrabber.cpp, testAutoThreshold.cpp, testConnectedComponents.cpp, testContours.cpp, testConversion.cpp, testCrop.cpp, testCropAdvanced.cpp, testFloodFill.cpp, testGenericTracker.cpp, testImageDraw.cpp, testImgproc.cpp, testIoPGM.cpp, testIoPPM.cpp, testPerformanceLUT.cpp, testPylonGrabber.cpp, testUndistortImage.cpp, tutorial-bridge-opencv-camera-param.cpp, tutorial-bridge-opencv-image.cpp, tutorial-brightness-adjustment.cpp, tutorial-export-image.cpp, tutorial-image-converter.cpp, tutorial-image-reader.cpp, tutorial-image-simulator.cpp, tutorial-image-viewer.cpp, and tutorial-undistort.cpp.

Definition at line 287 of file vpImageIo.cpp.

References vpImageException::ioError, writeJPEG(), writePGM(), writePNG(), and writePPM().

Referenced by vpImageStorageWorker< Type >::run(), vpVideoWriter::saveFrame(), vpKeyPoint::saveLearningData(), and vpSimulator::write().

◆ write() [2/2]

void vpImageIo::write ( const vpImage< vpRGBa > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Write the content of the image in the file which name is given by filename.

Supported formats are:

  • portable gray map: *.pgm file
  • portable pix map: *.ppm file
  • portable float map: *.pfm file
  • jpeg: *.jpg, *.jpeg files
  • png: *.png file

If ViSP is build with OpenCV support, additional formats are considered:

  • *.jp2, *.rs, *.ras, *.tiff, *.tif, *.png, *.bmp, *.pbm files.
Parameters
I: Image to write.
filename: Name of the file containing the image.
backend: Library backend type (see vpImageIo::vpImageIoBackendType) for image writing. This parameter is only used when the image need to be saved in jpeg or png format. To know which is the default backend see respectively void vpImageIo::writeJPEG(const vpImage<vpRGBa> &, const std::string &, int, int) and void vpImageIo::writePNG(const vpImage<vpRGBa> &, const std::string &, int).

Definition at line 347 of file vpImageIo.cpp.

References vpImageException::ioError, writeJPEG(), writePGM(), writePNG(), and writePPM().

◆ writeEXR() [1/2]

void vpImageIo::writeEXR ( const vpImage< float > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Save an image in EXR format.

Parameters
[in]I: Floating-point single channel image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Only OpenCV and the Tiny OpenEXR image libraries can currently save EXR image. The default backend vpImageIo::IO_DEFAULT_BACKEND is the Tiny OpenEXR image library.
Examples
testIoEXR.cpp.

Definition at line 1200 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ writeEXR() [2/2]

void vpImageIo::writeEXR ( const vpImage< vpRGBf > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Save an image in EXR format.

Parameters
[in]I: Floating-point three channels image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Only OpenCV and the Tiny OpenEXR image libraries can currently save EXR image. The default backend vpImageIo::IO_DEFAULT_BACKEND is the Tiny OpenEXR image library.

Definition at line 1250 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ writeJPEG() [1/2]

void vpImageIo::writeJPEG ( const vpImage< unsigned char > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND,
int  quality = 90 
)
static

Save an image in jpeg format.

Parameters
[in]I: Gray level image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Depending on its availability, the default backend vpImageIo::IO_DEFAULT_BACKEND is chosen in the following order: vpImageIo::IO_SYSTEM_LIB_BACKEND, vpImageIo::IO_OPENCV_BACKEND, vpImageIo::IO_SIMDLIB_BACKEND.
[in]quality: Image quality percentage in range 0-100.

Definition at line 824 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

Referenced by write().

◆ writeJPEG() [2/2]

void vpImageIo::writeJPEG ( const vpImage< vpRGBa > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND,
int  quality = 90 
)
static

Save an image in jpeg format.

Parameters
[in]I: Color image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Depending on its availability, the default backend vpImageIo::IO_DEFAULT_BACKEND is chosen in the following order: vpImageIo::IO_SYSTEM_LIB_BACKEND, vpImageIo::IO_OPENCV_BACKEND, vpImageIo::IO_SIMDLIB_BACKEND.
[in]quality: Image quality percentage in range 0-100.

Definition at line 923 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ writePFM()

void vpImageIo::writePFM ( const vpImage< float > &  I,
const std::string &  filename 
)
static

Save an image in portable float map format.

Parameters
[in]I: Image to save.
[in]filename: Image location.

Definition at line 1296 of file vpImageIo.cpp.

◆ writePFM_HDR() [1/2]

void vpImageIo::writePFM_HDR ( const vpImage< float > &  I,
const std::string &  filename 
)
static

Save a high-dynamic range (not restricted to the [0-255] intensity range) floating-point image in portable float map format.

Parameters
[in]I: Grayscale floating-point image to save.
[in]filename: Image location.
Examples
testIoPFM.cpp.

Definition at line 1304 of file vpImageIo.cpp.

◆ writePFM_HDR() [2/2]

void vpImageIo::writePFM_HDR ( const vpImage< vpRGBf > &  I,
const std::string &  filename 
)
static

Save a RGB high-dynamic range (not restricted to the [0-255] intensity range) floating-point image in portable float map format.

Parameters
[in]I: RGB floating-point image to save.
[in]filename: Image location.

Definition at line 1312 of file vpImageIo.cpp.

◆ writePGM() [1/3]

void vpImageIo::writePGM ( const vpImage< short > &  I,
const std::string &  filename 
)
static

Save a gray level image in portable gray map format.

Parameters
[in]I: Image to save.
[in]filename: Image location.

Definition at line 1326 of file vpImageIo.cpp.

◆ writePGM() [2/3]

void vpImageIo::writePGM ( const vpImage< unsigned char > &  I,
const std::string &  filename 
)
static

Save an image in portable gray map format.

Parameters
[in]I: Image to save.
[in]filename: Image location.

Definition at line 1319 of file vpImageIo.cpp.

Referenced by write().

◆ writePGM() [3/3]

void vpImageIo::writePGM ( const vpImage< vpRGBa > &  I,
const std::string &  filename 
)
static

Save a color image in portable gray map format.

Parameters
[in]I: Image to save.
[in]filename: Image location.

Definition at line 1333 of file vpImageIo.cpp.

◆ writePNG() [1/2]

void vpImageIo::writePNG ( const vpImage< unsigned char > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Save an image in png format.

Parameters
[in]I: Gray level image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Depending on its availability, the default backend vpImageIo::IO_DEFAULT_BACKEND is chosen in the following order: vpImageIo::IO_OPENCV_BACKEND, vpImageIo::IO_SIMDLIB_BACKEND.

Definition at line 1020 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

Referenced by write().

◆ writePNG() [2/2]

void vpImageIo::writePNG ( const vpImage< vpRGBa > &  I,
const std::string &  filename,
int  backend = IO_DEFAULT_BACKEND 
)
static

Save an image in png format.

Parameters
[in]I: Color image.
[in]filename: Image location.
[in]backend: Supported backends are described in vpImageIo::vpImageIoBackendType. Depending on its availability, the default backend vpImageIo::IO_DEFAULT_BACKEND is chosen in the following order: vpImageIo::IO_OPENCV_BACKEND, vpImageIo::IO_SYSTEM_LIB_BACKEND, vpImageIo::IO_SIMDLIB_BACKEND.

Definition at line 1111 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ writePNGtoMem() [1/2]

void vpImageIo::writePNGtoMem ( const vpImage< unsigned char > &  I,
std::vector< unsigned char > &  buffer,
int  backend = IO_DEFAULT_BACKEND 
)
static

In-memory PNG encoding of the grayscale image.

Parameters
[in]I: Input grayscale image.
[out]buffer: Encoded image as 1-D unsigned char vector using the PNG format.
[in]backend: Supported backends are IO_OPENCV_BACKEND and IO_STB_IMAGE_BACKEND, default IO_DEFAULT_BACKEND will choose IO_OPENCV_BACKEND if available or IO_STB_IMAGE_BACKEND otherwise.

Definition at line 1520 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ writePNGtoMem() [2/2]

void vpImageIo::writePNGtoMem ( const vpImage< vpRGBa > &  I,
std::vector< unsigned char > &  buffer,
int  backend = IO_DEFAULT_BACKEND,
bool  saveAlpha = false 
)
static

In-memory PNG encoding of the color image.

Parameters
[in]I: Input color image.
[out]buffer: Encoded image as 1-D unsigned char vector using the PNG format.
[in]backend: Supported backends are IO_OPENCV_BACKEND and IO_STB_IMAGE_BACKEND, default IO_DEFAULT_BACKEND will choose IO_OPENCV_BACKEND if available or IO_STB_IMAGE_BACKEND otherwise.
[in]saveAlpha: If true, alpha channel is also used for encoding.

Definition at line 1583 of file vpImageIo.cpp.

References IO_DEFAULT_BACKEND, IO_OPENCV_BACKEND, IO_SIMDLIB_BACKEND, IO_STB_IMAGE_BACKEND, IO_SYSTEM_LIB_BACKEND, and vpImageException::ioError.

◆ writePPM() [1/2]

void vpImageIo::writePPM ( const vpImage< unsigned char > &  I,
const std::string &  filename 
)
static

Save a gray level image in portable pixmap format.

Parameters
[in]I: Image to save.
[in]filename: Image location.

Definition at line 1389 of file vpImageIo.cpp.

Referenced by write().

◆ writePPM() [2/2]

void vpImageIo::writePPM ( const vpImage< vpRGBa > &  I,
const std::string &  filename 
)
static

Save a color level image in portable pixmap format.

Parameters
[in]I: Image to save.
[in]filename: Image location.

Definition at line 1396 of file vpImageIo.cpp.