45 #ifndef vpIMAGECONVERT_H
46 #define vpIMAGECONVERT_H
51 #include <visp3/core/vpConfig.h>
52 #include <visp3/core/vpImage.h>
53 #include <visp3/core/vpDebug.h>
55 #include <visp3/core/vpRGBa.h>
57 #ifdef VISP_HAVE_OPENCV
58 # if (VISP_HAVE_OPENCV_VERSION >= 0x030000) // Require opencv >= 3.0.0
59 # include <opencv2/core/core.hpp>
60 # include <opencv2/highgui/highgui.hpp>
61 # include <opencv2/imgproc/imgproc.hpp>
62 # elif (VISP_HAVE_OPENCV_VERSION >= 0x020408) // Require opencv >= 2.4.8
63 # include <opencv2/core/core.hpp>
64 # include <opencv2/highgui/highgui.hpp>
65 # include <opencv2/imgproc/imgproc.hpp>
66 # elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
67 # include <opencv2/core/core.hpp>
68 # include <opencv2/legacy/legacy.hpp>
69 # include <opencv2/highgui/highgui.hpp>
70 # include <opencv2/highgui/highgui_c.h>
77 # include <yarp/sig/Image.h>
119 template<
typename Type>
125 #ifdef VISP_HAVE_OPENCV
127 static void convert(
const IplImage* src,
vpImage<vpRGBa> & dest,
bool flip =
false) ;
131 # if VISP_HAVE_OPENCV_VERSION >= 0x020100
132 static void convert(
const cv::Mat& src,
vpImage<vpRGBa>& dest,
const bool flip =
false);
139 #ifdef VISP_HAVE_YARP
141 yarp::sig::ImageOf< yarp::sig::PixelMono > *dest,
const bool copyData =
true) ;
142 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelMono > *src,
147 yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
const bool copyData =
true) ;
148 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
152 yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest) ;
153 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgb > *src,
194 dr = floor(0.9999695*y - 0.0009508*(u-128) + 1.1359061*(v-128));
195 dg = floor(0.9999695*y - 0.3959609*(u-128) - 0.5782955*(v-128));
196 db = floor(0.9999695*y + 2.04112*(u-128) - 0.0016314*(v-128));
198 dr = dr < 0. ? 0. : dr;
199 dg = dg < 0. ? 0. : dg;
200 db = db < 0. ? 0. : db;
201 dr = dr > 255. ? 255. : dr;
202 dg = dg > 255. ? 255. : dg;
203 db = db > 255. ? 255. : db;
205 r = (
unsigned char) dr;
206 g = (
unsigned char) dg;
207 b = (
unsigned char) db;
209 static void YUYVToRGBa(
unsigned char* yuyv,
unsigned char* rgba,
210 unsigned int width,
unsigned int height);
211 static void YUYVToRGB(
unsigned char* yuyv,
unsigned char* rgb,
212 unsigned int width,
unsigned int height);
213 static void YUYVToGrey(
unsigned char* yuyv,
unsigned char* grey,
215 static void YUV411ToRGBa(
unsigned char* yuv,
216 unsigned char* rgba,
unsigned int size);
217 static void YUV411ToRGB(
unsigned char* yuv,
218 unsigned char* rgb,
unsigned int size);
219 static void YUV411ToGrey(
unsigned char* yuv,
220 unsigned char* grey,
unsigned int size);
221 static void YUV422ToRGBa(
unsigned char* yuv,
222 unsigned char* rgba,
unsigned int size);
223 static void YUV422ToRGB(
unsigned char* yuv,
224 unsigned char* rgb,
unsigned int size);
225 static void YUV422ToGrey(
unsigned char* yuv,
226 unsigned char* grey,
unsigned int size);
227 static void YUV420ToRGBa(
unsigned char* yuv,
228 unsigned char* rgba,
unsigned int width,
unsigned int height);
229 static void YUV420ToRGB(
unsigned char* yuv,
230 unsigned char* rgb,
unsigned int width,
unsigned int height);
231 static void YUV420ToGrey(
unsigned char* yuv,
232 unsigned char* grey,
unsigned int size);
234 static void YUV444ToRGBa(
unsigned char* yuv,
235 unsigned char* rgba,
unsigned int size);
236 static void YUV444ToRGB(
unsigned char* yuv,
237 unsigned char* rgb,
unsigned int size);
238 static void YUV444ToGrey(
unsigned char* yuv,
239 unsigned char* grey,
unsigned int size);
241 static void YV12ToRGBa(
unsigned char* yuv,
242 unsigned char* rgba,
unsigned int width,
unsigned int height);
243 static void YV12ToRGB(
unsigned char* yuv,
244 unsigned char* rgb,
unsigned int width,
unsigned int height);
245 static void YVU9ToRGBa(
unsigned char* yuv,
246 unsigned char* rgba,
unsigned int width,
unsigned int height);
247 static void YVU9ToRGB(
unsigned char* yuv,
248 unsigned char* rgb,
unsigned int width,
unsigned int height);
249 static void RGBToRGBa(
unsigned char* rgb,
250 unsigned char* rgba,
unsigned int size);
251 static void RGBaToRGB(
unsigned char* rgba,
252 unsigned char* rgb,
unsigned int size);
254 static void RGBToGrey(
unsigned char* rgb,
unsigned char* grey,
unsigned int size);
255 static void RGBaToGrey(
unsigned char* rgba,
unsigned char* grey,
unsigned int size);
257 static void RGBToRGBa(
unsigned char * rgb,
unsigned char * rgba,
258 unsigned int width,
unsigned int height,
bool flip =
false);
259 static void RGBToGrey(
unsigned char * rgb,
unsigned char * grey,
260 unsigned int width,
unsigned int height,
bool flip =
false);
262 static void GreyToRGBa(
unsigned char* grey,
263 unsigned char* rgba,
unsigned int size);
264 static void GreyToRGB(
unsigned char* grey,
265 unsigned char* rgb,
unsigned int size);
267 static void BGRToRGBa(
unsigned char * bgr,
unsigned char * rgba,
268 unsigned int width,
unsigned int height,
bool flip=
false);
270 static void BGRToGrey(
unsigned char * bgr,
unsigned char * grey,
271 unsigned int width,
unsigned int height,
bool flip=
false);
273 static void YCbCrToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
275 static void YCbCrToRGBa (
unsigned char *ycbcr,
unsigned char *rgb,
277 static void YCrCbToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
279 static void YCrCbToRGBa(
unsigned char *ycbcr,
unsigned char *rgb,
281 static void YCbCrToGrey(
unsigned char *ycbcr,
unsigned char *grey,
283 static void MONO16ToGrey(
unsigned char *grey16,
unsigned char *grey,
285 static void MONO16ToRGBa(
unsigned char *grey16,
unsigned char *rgba,
288 static void HSVToRGBa(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgba,
289 const unsigned int size);
290 static void HSVToRGBa(
const unsigned char *hue,
const unsigned char *saturation,
const unsigned char *value,
291 unsigned char *rgba,
const unsigned int size);
292 static void RGBaToHSV(
const unsigned char *rgba,
double *hue,
double *saturation,
double *value,
293 const unsigned int size);
294 static void RGBaToHSV(
const unsigned char *rgba,
unsigned char *hue,
unsigned char *saturation,
unsigned char *value,
295 const unsigned int size);
297 static void HSVToRGB(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgb,
298 const unsigned int size);
299 static void HSVToRGB(
const unsigned char *hue,
const unsigned char *saturation,
const unsigned char *value,
300 unsigned char *rgb,
const unsigned int size);
301 static void RGBToHSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
302 const unsigned int size);
303 static void RGBToHSV(
const unsigned char *rgb,
unsigned char *hue,
unsigned char *saturation,
unsigned char *value,
304 const unsigned int size);
307 static void computeYCbCrLUT();
309 static void HSV2RGB(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgba,
310 const unsigned int size,
const unsigned int step);
311 static void RGB2HSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
312 const unsigned int size,
const unsigned int step);
315 static bool YCbCrLUTcomputed;
316 static int vpCrr[256];
317 static int vpCgb[256];
318 static int vpCgr[256];
319 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.