45 #ifndef vpIMAGECONVERT_H
46 #define vpIMAGECONVERT_H
49 #include <visp3/core/vpConfig.h>
50 #include <visp3/core/vpImage.h>
51 #include <visp3/core/vpDebug.h>
53 #include <visp3/core/vpRGBa.h>
55 #ifdef VISP_HAVE_OPENCV
56 # if (VISP_HAVE_OPENCV_VERSION >= 0x030000) // Require opencv >= 3.0.0
57 # include <opencv2/core/core.hpp>
58 # include <opencv2/highgui/highgui.hpp>
59 # include <opencv2/imgproc/imgproc_c.h>
60 # elif (VISP_HAVE_OPENCV_VERSION >= 0x020408) // Require opencv >= 2.4.8
61 # include <opencv2/core/core.hpp>
62 # include <opencv2/highgui/highgui.hpp>
63 # elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
64 # include <opencv2/core/core.hpp>
65 # include <opencv2/legacy/legacy.hpp>
66 # include <opencv2/highgui/highgui.hpp>
67 # include <opencv2/highgui/highgui_c.h>
74 # include <yarp/sig/Image.h>
113 #ifdef VISP_HAVE_OPENCV
115 static void convert(
const IplImage* src,
117 static void convert(
const IplImage* src,
123 # if VISP_HAVE_OPENCV_VERSION >= 0x020100
124 static void convert(
const cv::Mat& src,
126 static void convert(
const cv::Mat& src,
131 cv::Mat& dest,
const bool copyData =
true) ;
135 #ifdef VISP_HAVE_YARP
137 yarp::sig::ImageOf< yarp::sig::PixelMono > *dest,
const bool copyData =
true) ;
138 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelMono > *src,
143 yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
const bool copyData =
true) ;
144 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
148 yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest) ;
149 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgb > *src,
190 dr = floor(0.9999695*y - 0.0009508*(u-128) + 1.1359061*(v-128));
191 dg = floor(0.9999695*y - 0.3959609*(u-128) - 0.5782955*(v-128));
192 db = floor(0.9999695*y + 2.04112*(u-128) - 0.0016314*(v-128));
194 dr = dr < 0. ? 0. : dr;
195 dg = dg < 0. ? 0. : dg;
196 db = db < 0. ? 0. : db;
197 dr = dr > 255. ? 255. : dr;
198 dg = dg > 255. ? 255. : dg;
199 db = db > 255. ? 255. : db;
201 r = (
unsigned char) dr;
202 g = (
unsigned char) dg;
203 b = (
unsigned char) db;
205 static void YUYVToRGBa(
unsigned char* yuyv,
unsigned char* rgba,
206 unsigned int width,
unsigned int height);
207 static void YUYVToRGB(
unsigned char* yuyv,
unsigned char* rgb,
208 unsigned int width,
unsigned int height);
209 static void YUYVToGrey(
unsigned char* yuyv,
unsigned char* grey,
211 static void YUV411ToRGBa(
unsigned char* yuv,
212 unsigned char* rgba,
unsigned int size);
213 static void YUV411ToRGB(
unsigned char* yuv,
214 unsigned char* rgb,
unsigned int size);
215 static void YUV411ToGrey(
unsigned char* yuv,
216 unsigned char* grey,
unsigned int size);
217 static void YUV422ToRGBa(
unsigned char* yuv,
218 unsigned char* rgba,
unsigned int size);
219 static void YUV422ToRGB(
unsigned char* yuv,
220 unsigned char* rgb,
unsigned int size);
221 static void YUV422ToGrey(
unsigned char* yuv,
222 unsigned char* grey,
unsigned int size);
223 static void YUV420ToRGBa(
unsigned char* yuv,
224 unsigned char* rgba,
unsigned int width,
unsigned int height);
225 static void YUV420ToRGB(
unsigned char* yuv,
226 unsigned char* rgb,
unsigned int width,
unsigned int height);
227 static void YUV420ToGrey(
unsigned char* yuv,
228 unsigned char* grey,
unsigned int size);
230 static void YUV444ToRGBa(
unsigned char* yuv,
231 unsigned char* rgba,
unsigned int size);
232 static void YUV444ToRGB(
unsigned char* yuv,
233 unsigned char* rgb,
unsigned int size);
234 static void YUV444ToGrey(
unsigned char* yuv,
235 unsigned char* grey,
unsigned int size);
237 static void YV12ToRGBa(
unsigned char* yuv,
238 unsigned char* rgba,
unsigned int width,
unsigned int height);
239 static void YV12ToRGB(
unsigned char* yuv,
240 unsigned char* rgb,
unsigned int width,
unsigned int height);
241 static void YVU9ToRGBa(
unsigned char* yuv,
242 unsigned char* rgba,
unsigned int width,
unsigned int height);
243 static void YVU9ToRGB(
unsigned char* yuv,
244 unsigned char* rgb,
unsigned int width,
unsigned int height);
245 static void RGBToRGBa(
unsigned char* rgb,
246 unsigned char* rgba,
unsigned int size);
247 static void RGBaToRGB(
unsigned char* rgba,
248 unsigned char* rgb,
unsigned int size);
250 static void RGBToGrey(
unsigned char* rgb,
251 unsigned char* grey,
unsigned int size);
252 static void RGBaToGrey(
unsigned char* rgba,
253 unsigned char* grey,
unsigned int size);
255 static void RGBToRGBa(
unsigned char * bgr,
unsigned char * rgba,
256 unsigned int width,
unsigned int height,
bool flip =
false);
257 static void RGBToGrey(
unsigned char * bgr,
unsigned char * grey,
258 unsigned int width,
unsigned int height,
bool flip =
false);
260 static void GreyToRGBa(
unsigned char* grey,
261 unsigned char* rgba,
unsigned int size);
262 static void GreyToRGB(
unsigned char* grey,
263 unsigned char* rgb,
unsigned int size);
265 static void BGRToRGBa(
unsigned char * bgr,
unsigned char * rgba,
266 unsigned int width,
unsigned int height,
bool flip=
false);
268 static void BGRToGrey(
unsigned char * bgr,
unsigned char * grey,
269 unsigned int width,
unsigned int height,
bool flip=
false);
271 static void YCbCrToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
273 static void YCbCrToRGBa (
unsigned char *ycbcr,
unsigned char *rgb,
275 static void YCrCbToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
277 static void YCrCbToRGBa(
unsigned char *ycbcr,
unsigned char *rgb,
279 static void YCbCrToGrey(
unsigned char *ycbcr,
unsigned char *grey,
281 static void MONO16ToGrey(
unsigned char *grey16,
unsigned char *grey,
283 static void MONO16ToRGBa(
unsigned char *grey16,
unsigned char *rgba,
286 static void HSVToRGBa(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgba,
287 const unsigned int size);
288 static void HSVToRGBa(
const unsigned char *hue,
const unsigned char *saturation,
const unsigned char *value,
289 unsigned char *rgba,
const unsigned int size);
290 static void RGBaToHSV(
const unsigned char *rgba,
double *hue,
double *saturation,
double *value,
291 const unsigned int size);
292 static void RGBaToHSV(
const unsigned char *rgba,
unsigned char *hue,
unsigned char *saturation,
unsigned char *value,
293 const unsigned int size);
295 static void HSVToRGB(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgb,
296 const unsigned int size);
297 static void HSVToRGB(
const unsigned char *hue,
const unsigned char *saturation,
const unsigned char *value,
298 unsigned char *rgb,
const unsigned int size);
299 static void RGBToHSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
300 const unsigned int size);
301 static void RGBToHSV(
const unsigned char *rgb,
unsigned char *hue,
unsigned char *saturation,
unsigned char *value,
302 const unsigned int size);
305 static void computeYCbCrLUT();
307 static void HSV2RGB(
const double *hue,
const double *saturation,
const double *value,
unsigned char *rgba,
308 const unsigned int size,
const unsigned int step);
309 static void RGB2HSV(
const unsigned char *rgb,
double *hue,
double *saturation,
double *value,
310 const unsigned int size,
const unsigned int step);
313 static bool YCbCrLUTcomputed;
314 static int vpCrr[256];
315 static int vpCgb[256];
316 static int vpCgr[256];
317 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)