Visual Servoing Platform  version 3.5.1 under development (2023-02-02)
vpImageIo.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Read/write images.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
44 #ifndef vpIMAGEIO_H
45 #define vpIMAGEIO_H
46 
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpImageConvert.h>
50 
51 #include <iostream>
52 #include <stdio.h>
53 
103 class VISP_EXPORT vpImageIo
104 {
105 private:
106  typedef enum {
107  FORMAT_PGM,
108  FORMAT_PPM,
109  FORMAT_JPEG,
110  FORMAT_PNG,
111  // Formats supported by opencv
112  FORMAT_TIFF,
113  FORMAT_BMP,
114  FORMAT_DIB,
115  FORMAT_PBM,
116  FORMAT_RASTER,
117  FORMAT_JPEG2000,
118  FORMAT_UNKNOWN
119  } vpImageFormatType;
120 
121  static vpImageFormatType getFormat(const std::string &filename);
122  static std::string getExtension(const std::string &filename);
123 
124 public:
131  IO_STB_IMAGE_BACKEND
132  };
133 
134  static void read(vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
135  static void read(vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
136 
137  static void write(const vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
138  static void write(const vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
139 
140  static void readPFM(vpImage<float> &I, const std::string &filename);
141  static void readPFM_HDR(vpImage<float> &I, const std::string &filename);
142  static void readPFM_HDR(vpImage<vpRGBf> &I, const std::string &filename);
143 
144  static void readPGM(vpImage<unsigned char> &I, const std::string &filename);
145  static void readPGM(vpImage<vpRGBa> &I, const std::string &filename);
146 
147  static void readPPM(vpImage<unsigned char> &I, const std::string &filename);
148  static void readPPM(vpImage<vpRGBa> &I, const std::string &filename);
149 
150  static void readJPEG(vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
151  static void readJPEG(vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
152 
153  static void readPNG(vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
154  static void readPNG(vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
155 
156  static void writePFM(const vpImage<float> &I, const std::string &filename);
157  static void writePFM_HDR(const vpImage<float> &I, const std::string &filename);
158  static void writePFM_HDR(const vpImage<vpRGBf> &I, const std::string &filename);
159 
160  static void writePGM(const vpImage<unsigned char> &I, const std::string &filename);
161  static void writePGM(const vpImage<short> &I, const std::string &filename);
162  static void writePGM(const vpImage<vpRGBa> &I, const std::string &filename);
163 
164  static void writePPM(const vpImage<unsigned char> &I, const std::string &filename);
165  static void writePPM(const vpImage<vpRGBa> &I, const std::string &filename);
166 
167  static void writeJPEG(const vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND,
168  int quality = 90);
169  static void writeJPEG(const vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND,
170  int quality = 90);
171 
172  static void writePNG(const vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
173  static void writePNG(const vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
174 };
175 #endif
Read/write images with various image format.
Definition: vpImageIo.h:104
vpImageIoBackendType
Image IO backend for only jpeg and png formats image loading and saving.
Definition: vpImageIo.h:126
@ IO_DEFAULT_BACKEND
Default backend.
Definition: vpImageIo.h:127
@ IO_SIMDLIB_BACKEND
Use embedded simd library.
Definition: vpImageIo.h:130
@ IO_SYSTEM_LIB_BACKEND
Use system libraries like libpng or libjpeg.
Definition: vpImageIo.h:128
@ IO_OPENCV_BACKEND
Use OpenCV.
Definition: vpImageIo.h:129