46 #ifndef vpIMAGECONVERT_H 47 #define vpIMAGECONVERT_H 52 #include <visp3/core/vpConfig.h> 53 #include <visp3/core/vpDebug.h> 54 #include <visp3/core/vpImage.h> 56 #include <visp3/core/vpRGBa.h> 58 #ifdef VISP_HAVE_OPENCV 59 #if ( VISP_HAVE_OPENCV_VERSION >= 0x040000 ) // Require opencv >= 4.0.0 60 #include <opencv2/highgui.hpp> 61 #include <opencv2/imgproc.hpp> 62 #include <opencv2/imgproc/types_c.h> 63 #elif ( VISP_HAVE_OPENCV_VERSION >= 0x030000 ) // Require opencv >= 3.0.0 64 #include <opencv2/core/core.hpp> 65 #include <opencv2/highgui/highgui.hpp> 66 #include <opencv2/imgproc/imgproc.hpp> 67 #elif ( VISP_HAVE_OPENCV_VERSION >= 0x020408 ) // Require opencv >= 2.4.8 68 #include <opencv2/core/core.hpp> 69 #include <opencv2/highgui/highgui.hpp> 70 #include <opencv2/imgproc/imgproc.hpp> 71 #elif ( VISP_HAVE_OPENCV_VERSION >= 0x020101 ) // Require opencv >= 2.1.1 72 #include <opencv2/core/core.hpp> 73 #include <opencv2/highgui/highgui.hpp> 74 #include <opencv2/highgui/highgui_c.h> 75 #include <opencv2/legacy/legacy.hpp> 82 #include <yarp/sig/Image.h> 134 #ifdef VISP_HAVE_OPENCV 136 static void convert(
const IplImage *src,
vpImage< vpRGBa > &dest,
bool flip =
false );
140 #if VISP_HAVE_OPENCV_VERSION >= 0x020100 141 static void convert(
const cv::Mat &src,
vpImage< vpRGBa > &dest,
bool flip =
false );
143 unsigned int nThreads = 0 );
149 #ifdef VISP_HAVE_YARP 151 bool copyData =
true );
153 bool copyData =
true );
155 static void convert(
const vpImage< vpRGBa > &src, yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
156 bool copyData =
true );
157 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
vpImage< vpRGBa > &dest,
158 bool copyData =
true );
160 static void convert(
const vpImage< vpRGBa > &src, yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest );
161 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgb > *src,
vpImage< vpRGBa > &dest );
185 static inline void YUVToRGB(
unsigned char y,
unsigned char u,
unsigned char v,
unsigned char &r,
unsigned char &g,
189 dr = floor( 0.9999695 * y - 0.0009508 * ( u - 128 ) + 1.1359061 * ( v - 128 ) );
190 dg = floor( 0.9999695 * y - 0.3959609 * ( u - 128 ) - 0.5782955 * ( v - 128 ) );
191 db = floor( 0.9999695 * y + 2.04112 * ( u - 128 ) - 0.0016314 * ( v - 128 ) );
193 dr = dr < 0. ? 0. : dr;
194 dg = dg < 0. ? 0. : dg;
195 db = db < 0. ? 0. : db;
196 dr = dr > 255. ? 255. : dr;
197 dg = dg > 255. ? 255. : dg;
198 db = db > 255. ? 255. : db;
200 r = (
unsigned char)dr;
201 g = (
unsigned char)dg;
202 b = (
unsigned char)db;
204 static void YUYVToRGBa(
unsigned char *yuyv,
unsigned char *rgba,
unsigned int width,
unsigned int height );
205 static void YUYVToRGB(
unsigned char *yuyv,
unsigned char *rgb,
unsigned int width,
unsigned int height );
206 static void YUYVToGrey(
unsigned char *yuyv,
unsigned char *grey,
unsigned int size );
207 static void YUV411ToRGBa(
unsigned char *yuv,
unsigned char *rgba,
unsigned int size );
208 static void YUV411ToRGB(
unsigned char *yuv,
unsigned char *rgb,
unsigned int size );
209 static void YUV411ToGrey(
unsigned char *yuv,
unsigned char *grey,
unsigned int size );
210 static void YUV422ToRGBa(
unsigned char *yuv,
unsigned char *rgba,
unsigned int size );
211 static void YUV422ToRGB(
unsigned char *yuv,
unsigned char *rgb,
unsigned int size );
212 static void YUV422ToGrey(
unsigned char *yuv,
unsigned char *grey,
unsigned int size );
213 static void YUV420ToRGBa(
unsigned char *yuv,
unsigned char *rgba,
unsigned int width,
unsigned int height );
214 static void YUV420ToRGB(
unsigned char *yuv,
unsigned char *rgb,
unsigned int width,
unsigned int height );
215 static void YUV420ToGrey(
unsigned char *yuv,
unsigned char *grey,
unsigned int size );
217 static void YUV444ToRGBa(
unsigned char *yuv,
unsigned char *rgba,
unsigned int size );
218 static void YUV444ToRGB(
unsigned char *yuv,
unsigned char *rgb,
unsigned int size );
219 static void YUV444ToGrey(
unsigned char *yuv,
unsigned char *grey,
unsigned int size );
221 static void YV12ToRGBa(
unsigned char *yuv,
unsigned char *rgba,
unsigned int width,
unsigned int height );
222 static void YV12ToRGB(
unsigned char *yuv,
unsigned char *rgb,
unsigned int width,
unsigned int height );
223 static void YVU9ToRGBa(
unsigned char *yuv,
unsigned char *rgba,
unsigned int width,
unsigned int height );
224 static void YVU9ToRGB(
unsigned char *yuv,
unsigned char *rgb,
unsigned int width,
unsigned int height );
225 static void RGBToRGBa(
unsigned char *rgb,
unsigned char *rgba,
unsigned int size );
226 static void RGBaToRGB(
unsigned char *rgba,
unsigned char *rgb,
unsigned int size );
228 static void RGBToGrey(
unsigned char *rgb,
unsigned char *grey,
unsigned int width,
unsigned int height,
230 static void RGBToGrey(
unsigned char *rgb,
unsigned char *grey,
unsigned int size );
231 static void RGBaToGrey(
unsigned char *rgba,
unsigned char *grey,
unsigned int width,
unsigned int height,
232 unsigned int nThreads = 0 );
233 static void RGBaToGrey(
unsigned char *rgba,
unsigned char *grey,
unsigned int size );
235 static void RGBToRGBa(
unsigned char *rgb,
unsigned char *rgba,
unsigned int width,
unsigned int height,
238 static void GreyToRGBa(
unsigned char *grey,
unsigned char *rgba,
unsigned int width,
unsigned int height );
239 static void GreyToRGBa(
unsigned char *grey,
unsigned char *rgba,
unsigned int size );
240 static void GreyToRGB(
unsigned char *grey,
unsigned char *rgb,
unsigned int size );
242 static void BGRToRGBa(
unsigned char *bgr,
unsigned char *rgba,
unsigned int width,
unsigned int height,
245 static void BGRToGrey(
unsigned char *bgr,
unsigned char *grey,
unsigned int width,
unsigned int height,
246 bool flip =
false,
unsigned int nThreads = 0 );
248 static void BGRaToGrey(
unsigned char *bgra,
unsigned char *grey,
unsigned int width,
unsigned int height,
249 bool flip =
false,
unsigned int nThreads = 0 );
250 static void BGRaToRGBa(
unsigned char *bgra,
unsigned char *rgba,
unsigned int width,
unsigned int height,
253 static void YCbCrToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
unsigned int size );
254 static void YCbCrToRGBa(
unsigned char *ycbcr,
unsigned char *rgb,
unsigned int size );
255 static void YCbCrToGrey(
unsigned char *ycbcr,
unsigned char *grey,
unsigned int size );
256 static void YCrCbToRGB(
unsigned char *ycrcb,
unsigned char *rgb,
unsigned int size );
257 static void YCrCbToRGBa(
unsigned char *ycrcb,
unsigned char *rgb,
unsigned int size );
258 static void MONO16ToGrey(
unsigned char *grey16,
unsigned char *grey,
unsigned int size );
259 static void MONO16ToRGBa(
unsigned char *grey16,
unsigned char *rgba,
unsigned int size );
261 static void HSVToRGBa(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgba,
263 static void HSVToRGBa(
const unsigned char *hue,
const unsigned char *saturation,
const unsigned char *value,
264 unsigned char *rgba,
unsigned int size );
265 static void RGBaToHSV(
const unsigned char *rgba,
double *hue,
double *saturation,
double *value,
unsigned int size );
266 static void RGBaToHSV(
const unsigned char *rgba,
unsigned char *hue,
unsigned char *saturation,
unsigned char *value,
269 static void HSVToRGB(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgb,
271 static void HSVToRGB(
const unsigned char *hue,
const unsigned char *saturation,
const unsigned char *value,
272 unsigned char *rgb,
unsigned int size );
273 static void RGBToHSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
unsigned int size );
274 static void RGBToHSV(
const unsigned char *rgb,
unsigned char *hue,
unsigned char *saturation,
unsigned char *value,
277 static void demosaicBGGRToRGBaBilinear(
const uint8_t *bggr, uint8_t *rgba,
unsigned int width,
unsigned int height,
278 unsigned int nThreads = 0 );
279 static void demosaicBGGRToRGBaBilinear(
const uint16_t *bggr, uint16_t *rgba,
unsigned int width,
unsigned int height,
280 unsigned int nThreads = 0 );
282 static void demosaicGBRGToRGBaBilinear(
const uint8_t *gbrg, uint8_t *rgba,
unsigned int width,
unsigned int height,
283 unsigned int nThreads = 0 );
284 static void demosaicGBRGToRGBaBilinear(
const uint16_t *gbrg, uint16_t *rgba,
unsigned int width,
unsigned int height,
285 unsigned int nThreads = 0 );
287 static void demosaicGRBGToRGBaBilinear(
const uint8_t *grbg, uint8_t *rgba,
unsigned int width,
unsigned int height,
288 unsigned int nThreads = 0 );
289 static void demosaicGRBGToRGBaBilinear(
const uint16_t *grbg, uint16_t *rgba,
unsigned int width,
unsigned int height,
290 unsigned int nThreads = 0 );
292 static void demosaicRGGBToRGBaBilinear(
const uint8_t *rggb, uint8_t *rgba,
unsigned int width,
unsigned int height,
293 unsigned int nThreads = 0 );
294 static void demosaicRGGBToRGBaBilinear(
const uint16_t *rggb, uint16_t *rgba,
unsigned int width,
unsigned int height,
295 unsigned int nThreads = 0 );
297 static void demosaicBGGRToRGBaMalvar(
const uint8_t *bggr, uint8_t *rgba,
unsigned int width,
unsigned int height,
298 unsigned int nThreads = 0 );
299 static void demosaicBGGRToRGBaMalvar(
const uint16_t *bggr, uint16_t *rgba,
unsigned int width,
unsigned int height,
300 unsigned int nThreads = 0 );
302 static void demosaicGBRGToRGBaMalvar(
const uint8_t *gbrg, uint8_t *rgba,
unsigned int width,
unsigned int height,
303 unsigned int nThreads = 0 );
304 static void demosaicGBRGToRGBaMalvar(
const uint16_t *gbrg, uint16_t *rgba,
unsigned int width,
unsigned int height,
305 unsigned int nThreads = 0 );
307 static void demosaicGRBGToRGBaMalvar(
const uint8_t *grbg, uint8_t *rgba,
unsigned int width,
unsigned int height,
308 unsigned int nThreads = 0 );
309 static void demosaicGRBGToRGBaMalvar(
const uint16_t *grbg, uint16_t *rgba,
unsigned int width,
unsigned int height,
310 unsigned int nThreads = 0 );
312 static void demosaicRGGBToRGBaMalvar(
const uint8_t *rggb, uint8_t *rgba,
unsigned int width,
unsigned int height,
313 unsigned int nThreads = 0 );
314 static void demosaicRGGBToRGBaMalvar(
const uint16_t *rggb, uint16_t *rgba,
unsigned int width,
unsigned int height,
315 unsigned int nThreads = 0 );
318 static void computeYCbCrLUT();
320 static void HSV2RGB(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgba,
321 unsigned int size,
unsigned int step );
322 static void RGB2HSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
unsigned int size,
326 static bool YCbCrLUTcomputed;
327 static int vpCrr[256];
328 static int vpCgb[256];
329 static int vpCgr[256];
330 static int vpCbb[256];
static void YUVToRGB(unsigned char y, unsigned char u, unsigned char v, unsigned char &r, unsigned char &g, unsigned char &b)
static void convert(const vpImage< Type > &src, vpImage< Type > &dest)
Definition of the vpImage class member functions.