42 #include <visp3/core/vpConfig.h> 43 #include <visp3/core/vpDebug.h> 44 #include <visp3/core/vpImage.h> 45 #include <visp3/core/vpImageConvert.h> 46 #include <visp3/core/vpIoTools.h> 47 #include <visp3/core/vpTime.h> 48 #include <visp3/io/vpImageIo.h> 49 #include <visp3/io/vpParseArgv.h> 58 #define GETOPTARGS "cdi:o:n:h" 71 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user,
int nbiter)
74 Test image conversions.\n\ 77 %s [-i <input image path>] [-o <output image path>] [-n <nb benchmark iterations>]\n\ 83 -i <input image path> %s\n\ 84 Set image input path.\n\ 85 From this path read \"Klimt/Klimt.pgm\"\n\ 86 and \"Klimt/Klimt.ppm\" images.\n\ 87 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 88 variable produces the same behaviour than using\n\ 91 -o <output image path> %s\n\ 92 Set image output path.\n\ 93 From this directory, creates the \"%s\"\n\ 94 subdirectory depending on the username, where \n\ 95 Klimt_grey.pgm and Klimt_color.ppm output images\n\ 98 -n <nb benchmark iterations> %d\n\ 99 Set the number of benchmark iterations.\n\ 102 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str(), nbiter);
105 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
121 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user,
136 nbIterations = atoi(optarg_);
139 usage(argv[0], NULL, ipath, opath, user, nbIterations);
148 usage(argv[0], optarg_, ipath, opath, user, nbIterations);
154 if ((c == 1) || (c == -1)) {
156 usage(argv[0], NULL, ipath, opath, user, nbIterations);
157 std::cerr <<
"ERROR: " << std::endl;
158 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
165 void computeRegularRGBaToGrayscale(
const unsigned char *rgba,
unsigned char *grey,
unsigned int size)
167 const unsigned char *pt_input = rgba;
168 const unsigned char *pt_end = rgba + size * 4;
169 unsigned char *pt_output = grey;
171 while (pt_input != pt_end) {
172 *pt_output = (
unsigned char)(0.2126 * (*pt_input) + 0.7152 * (*(pt_input + 1)) + 0.0722 * (*(pt_input + 2)));
178 void computeRegularRGBToGrayscale(
const unsigned char *rgb,
unsigned char *grey,
unsigned int size)
180 const unsigned char *pt_input = rgb;
181 const unsigned char *pt_end = rgb + size * 3;
182 unsigned char *pt_output = grey;
184 while (pt_input != pt_end) {
185 *pt_output = (
unsigned char)(0.2126 * (*pt_input) + 0.7152 * (*(pt_input + 1)) + 0.0722 * (*(pt_input + 2)));
191 void computeRegularBGRToGrayscale(
unsigned char *bgr,
unsigned char *grey,
unsigned int width,
unsigned int height,
196 int lineStep = (flip) ? -(
int)(width * 3) : (
int)(width * 3);
199 unsigned char *src = (flip) ? bgr + (width * height * 3) + lineStep : bgr;
204 for (i = 0; i < height; i++) {
205 unsigned char *line = src;
206 for (j = 0; j < width; j++) {
207 *grey++ = (
unsigned char)(0.2126 * *(line + 2) + 0.7152 * *(line + 1) + 0.0722 * *(line + 0));
216 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 219 if (src.type() == CV_8UC3) {
220 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
222 if (src.isContinuous()) {
223 computeRegularBGRToGrayscale((
unsigned char *)src.data, (
unsigned char *)dest.
bitmap, (
unsigned int)src.cols,
224 (
unsigned int)src.rows,
false);
230 int main(
int argc,
const char **argv)
233 std::string env_ipath;
234 std::string opt_ipath;
235 std::string opt_opath;
238 std::string filename;
239 std::string username;
240 int nbIterations = 1;
247 if (!env_ipath.empty())
252 opt_opath =
"C:/temp";
261 if (getOptions(argc, argv, opt_ipath, opt_opath, username, nbIterations) ==
false) {
266 if (!opt_ipath.empty())
268 if (!opt_opath.empty())
280 usage(argv[0], NULL, ipath, opt_opath, username, nbIterations);
281 std::cerr << std::endl <<
"ERROR:" << std::endl;
282 std::cerr <<
" Cannot create " << opath << std::endl;
283 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
290 if (opt_ipath.empty()) {
291 if (ipath != env_ipath) {
292 std::cout << std::endl <<
"WARNING: " << std::endl;
293 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 294 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
295 <<
" we skip the environment variable." << std::endl;
300 if (opt_ipath.empty() && env_ipath.empty()) {
301 usage(argv[0], NULL, ipath, opt_opath, username, nbIterations);
302 std::cerr << std::endl <<
"ERROR:" << std::endl;
303 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
304 <<
" environment variable to specify the location of the " << std::endl
305 <<
" image path where test images are located." << std::endl
318 std::cout <<
"** Convert a grey image (.pgm) to a color image (.ppm)" << std::endl;
321 std::cout <<
" Load " << filename << std::endl;
326 std::cout <<
" Resulting image saved in: " << filename << std::endl;
330 std::cout <<
"** Convert a color image (.ppm) to a grey image (.pgm)" << std::endl;
333 std::cout <<
" Load " << filename << std::endl;
338 std::cout <<
" Resulting image saved in: " << filename << std::endl;
342 std::cout <<
"** Convert YUV pixel value to a RGB value" << std::endl;
343 unsigned char y = 187, u = 10, v = 30;
344 unsigned char r, g, b;
348 std::cout <<
" y(" << (int)y <<
") u(" << (
int)u << ") v(" << (
int)v << ") = r(" << (
int)r << ") g(" << (
int)g
349 << ") b(" << (
int)b << ")" <<
std::endl;
351 #ifdef VISP_HAVE_OPENCV 352 #if VISP_HAVE_OPENCV_VERSION < 0x020408 357 std::cout <<
"** Convert an IplImage to a vpImage<vpRGBa>" << std::endl;
358 IplImage *image = NULL;
363 std::cout <<
" Reading the color image with opencv: " << filename << std::endl;
364 if ((image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_COLOR)) == NULL) {
365 std::cout <<
" Cannot read image: " << filename << std::endl;
370 std::cout <<
" Resulting image saved in: " << filename << std::endl;
373 std::cout <<
" Convert result in " << filename << std::endl;
378 std::cout <<
" Reading the greyscale image with opencv: " << filename << std::endl;
380 cvReleaseImage(&image);
381 if ((image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE)) == NULL) {
382 std::cout <<
" Cannot read image: " << filename << std::endl;
387 std::cout <<
" Resulting image saved in: " << filename << std::endl;
390 std::cout <<
" Convert result in " << filename << std::endl;
395 std::cout <<
"** Convert an IplImage to a vpImage<unsigned char>" << std::endl;
400 std::cout <<
" Reading the color image with opencv: " << filename << std::endl;
402 cvReleaseImage(&image);
403 if ((image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_COLOR)) == NULL) {
404 std::cout <<
" Cannot read image: " << filename << std::endl;
409 std::cout <<
" Resulting image saved in: " << filename << std::endl;
412 std::cout <<
" Convert result in " << filename << std::endl;
418 std::cout <<
" Reading the greyscale image with opencv: " << filename << std::endl;
420 cvReleaseImage(&image);
421 if ((image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE)) == NULL) {
422 std::cout <<
" Cannot read image: " << filename << std::endl;
427 std::cout <<
" Resulting image saved in: " << filename << std::endl;
430 std::cout <<
" Convert result in " << filename << std::endl;
435 std::cout <<
"** Convert a vpImage<vpRGBa> to an IplImage" << std::endl;
441 std::cout <<
" Load " << filename << std::endl;
446 std::cout <<
" Write " << filename << std::endl;
447 if ((cvSaveImage(filename.c_str(), image)) == 0) {
448 std::cout <<
" Cannot write image: " << filename << std::endl;
450 cvReleaseImage(&image);
453 std::cout <<
" Convert result in " << filename << std::endl;
458 std::cout <<
"** Convert a vpImage<unsigned char> to an IplImage" << std::endl;
464 std::cout <<
" Load " << filename << std::endl;
470 std::cout <<
" Write " << filename << std::endl;
471 if ((cvSaveImage(filename.c_str(), image)) == 0) {
472 std::cout <<
" Cannot write image: " << std::endl << filename << std::endl;
474 cvReleaseImage(&image);
477 std::cout <<
" Convert result in " << filename << std::endl;
480 cvReleaseImage(&image);
482 std::cout <<
"== Conversion c interface : " << t1 - t0 <<
" ms" << std::endl;
489 #if VISP_HAVE_OPENCV_VERSION >= 0x020100 494 std::cout <<
"** Convert a cv::Mat to a vpImage<vpRGBa>" << std::endl;
497 std::cout <<
" Reading the color image with c++ interface of opencv: " << filename << std::endl;
498 imageMat = cv::imread(filename, 1);
499 if (imageMat.data == NULL) {
500 std::cout <<
" Cannot read image: " << filename << std::endl;
505 std::cout <<
" Resulting image saved in: " << filename << std::endl;
511 std::cout <<
" Reading the greyscale image with opencv: " << filename << std::endl;
512 imageMat = cv::imread(filename, 0);
513 if (imageMat.data == NULL) {
514 std::cout <<
" Cannot read image: " << filename << std::endl;
519 std::cout <<
" Resulting image saved in: " << filename << std::endl;
525 std::cout <<
"** Convert a cv::Mat to a vpImage<nsigned char>" << std::endl;
530 std::cout <<
" Reading the color image with opencv: " << filename << std::endl;
531 imageMat = cv::imread(filename, 1);
532 if (imageMat.data == NULL) {
533 std::cout <<
" Cannot read image: " << filename << std::endl;
538 std::cout <<
" Resulting image saved in: " << filename << std::endl;
545 std::cout <<
" Reading the greyscale image with opencv: " << filename << std::endl;
546 imageMat = cv::imread(filename, 0);
547 if (imageMat.data == NULL) {
548 std::cout <<
" Cannot read image: " << filename << std::endl;
553 std::cout <<
" Resulting image saved in: " << filename << std::endl;
556 std::cout <<
" Convert result in " << filename << std::endl;
561 std::cout <<
"** Convert a vpImage<vpRGBa> to a cv::Mat" << std::endl;
567 std::cout <<
" Load " << filename << std::endl;
572 std::cout <<
" Resulting image saved in: " << filename << std::endl;
573 if (!cv::imwrite(filename, imageMat)) {
574 std::cout <<
" Cannot write image: " << filename << std::endl;
577 std::cout <<
" Convert result in " << filename << std::endl;
582 std::cout <<
"** Convert a vpImage<unsigned char> to a cv::Mat" << std::endl;
588 std::cout <<
" Load " << filename << std::endl;
594 std::cout <<
" Resulting image saved in: " << filename << std::endl;
595 if (!cv::imwrite(filename, imageMat)) {
596 std::cout <<
" Cannot write image: " << filename << std::endl;
599 std::cout <<
" Convert result in " << filename << std::endl;
601 std::cout <<
"== Conversion c++ interface : " << t3 - t2 <<
" ms" << std::endl;
608 std::cout <<
"** Split a vpImage<vpRGBa> to vpImage<unsigned char>" << std::endl;
614 std::cout <<
" Load " << filename << std::endl;
619 for (
int iteration = 0; iteration < nbIterations; iteration++) {
624 std::cout <<
" Time for " << nbIterations <<
" split (ms): " << endtime - begintime << std::endl;
628 std::cout <<
" Save Klimt R channel: " << filename << std::endl;
633 std::cout <<
" Save Klimt B channel: " << filename << std::endl;
639 std::cout <<
"** Merge 4 vpImage<unsigned char> (RGBa) to vpImage<vpRGBa>" << std::endl;
643 for (
int iteration = 0; iteration < nbIterations; iteration++) {
648 std::cout <<
" Time for 1000 merge (ms): " << endtime - begintime << std::endl;
651 std::cout <<
" Resulting image saved in: " << filename << std::endl;
658 std::cout <<
"** Convert a vpImage<vpRGBa> in RGB color space to a " 659 "vpImage<vpRGBa> in HSV color" 661 unsigned int size = Ic.
getSize();
663 unsigned char *hue =
new unsigned char[size];
664 unsigned char *saturation =
new unsigned char[size];
665 unsigned char *value =
new unsigned char[size];
675 std::cout <<
" Resulting image saved in: " << filename << std::endl;
679 double *hue2 =
new double[size];
680 double *saturation2 =
new double[size];
681 double *value2 =
new double[size];
684 unsigned char *rgba =
new unsigned char[size * 4];
692 if (saturation2 != NULL) {
693 delete[] saturation2;
697 if (value2 != NULL) {
704 std::cout <<
" Resulting image saved in: " << filename << std::endl;
707 for (
unsigned int i = 0; i < Ic.
getHeight(); i++) {
708 for (
unsigned int j = 0; j < Ic.
getWidth(); j++) {
709 if (Ic[i][j].R != I_HSV2RGBa[i][j].R || Ic[i][j].G != I_HSV2RGBa[i][j].G || Ic[i][j].B != I_HSV2RGBa[i][j].B) {
710 std::cerr <<
"Ic[i][j].R=" <<
static_cast<unsigned>(Ic[i][j].R)
711 <<
" ; I_HSV2RGBa[i][j].R=" << static_cast<unsigned>(I_HSV2RGBa[i][j].R) << std::endl;
712 std::cerr <<
"Ic[i][j].G=" <<
static_cast<unsigned>(Ic[i][j].G)
713 <<
" ; I_HSV2RGBa[i][j].G=" << static_cast<unsigned>(I_HSV2RGBa[i][j].G) << std::endl;
714 std::cerr <<
"Ic[i][j].B=" <<
static_cast<unsigned>(Ic[i][j].B)
715 <<
" ; I_HSV2RGBa[i][j].B=" << static_cast<unsigned>(I_HSV2RGBa[i][j].B) << std::endl;
724 std::cout <<
"** Construction of a vpImage from an array with copyData==true" << std::endl;
725 unsigned char *rgba2 =
new unsigned char[size * 4];
726 memset(rgba2, 127, size * 4);
733 std::cout <<
" Resulting image saved in: " << filename << std::endl;
736 if (I_copyData.getSize() > 0) {
737 I_copyData[0][0].R = 10;
742 std::cout <<
"** Benchmark and test RGBa / RGB / cv::Mat to Grayscale " 752 unsigned char value_sse = 0, value_regular = 0;
755 for (
int iteration = 0; iteration < nbIterations; iteration++) {
757 value_sse += I_gray_sse[0][0];
762 for (
int iteration = 0; iteration < nbIterations; iteration++) {
763 computeRegularRGBaToGrayscale((
unsigned char *)I_color.
bitmap, I_gray_regular.bitmap, I_color.
getSize());
764 value_regular += I_gray_regular[0][0];
769 double rmse_error = 0.0;
770 for (
unsigned int i = 0; i < I_color.
getHeight(); i++) {
771 for (
unsigned int j = 0; j < I_color.
getWidth(); j++) {
772 rmse_error += (I_gray_sse[i][j] - I_gray_regular[i][j]) * (I_gray_sse[i][j] - I_gray_regular[i][j]);
776 std::cout <<
"\n RGBa to Grayscale" << std::endl;
777 std::cout <<
" t_regular (" << nbIterations <<
" iterations)=" << t_regular <<
" ms" 778 <<
" ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
779 std::cout <<
" Speed-up=" << (t_regular / t_sse) <<
"X" << std::endl;
780 std::cout <<
" RMSE error between SSE and regular version: " << (std::sqrt(rmse_error / I_color.
getSize()))
784 std::cout <<
" value_sse=" <<
static_cast<unsigned>(value_sse)
785 <<
" ; value_regular=" << static_cast<unsigned>(value_regular) << std::endl;
788 std::cout <<
" Resulting image saved in: " << filename << std::endl;
792 std::cout <<
" Resulting image saved in: " << filename << std::endl;
796 unsigned char *rgb_array =
new unsigned char[I_color.
getSize() * 3];
802 unsigned char *rgb2gray_array_sse =
new unsigned char[I_color.
getSize()];
804 for (
int iteration = 0; iteration < nbIterations; iteration++) {
806 value_sse += rgb2gray_array_sse[0];
810 unsigned char *rgb2gray_array_regular =
new unsigned char[I_color.
getSize()];
812 for (
int iteration = 0; iteration < nbIterations; iteration++) {
813 computeRegularRGBToGrayscale(rgb_array, rgb2gray_array_regular, I_color.
getSize());
814 value_regular += rgb2gray_array_regular[0];
824 for (
unsigned int i = 0; i < I_color.
getHeight(); i++) {
825 for (
unsigned int j = 0; j < I_color.
getWidth(); j++) {
827 (I_gray2rgba_sse[i][j] - I_gray2rgba_regular[i][j]) * (I_gray2rgba_sse[i][j] - I_gray2rgba_regular[i][j]);
831 std::cout <<
"\n RGB to Grayscale" << std::endl;
832 std::cout <<
" t_regular (" << nbIterations <<
" iterations)=" << t_regular <<
" ms" 833 <<
" ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
834 std::cout <<
" Speed-up=" << (t_regular / t_sse) <<
"X" << std::endl;
835 std::cout <<
" RMSE error between SSE and regular version: " << (std::sqrt(rmse_error / I_color.
getSize()))
839 std::cout <<
" value_sse=" <<
static_cast<unsigned>(value_sse)
840 <<
" ; value_regular=" << static_cast<unsigned>(value_regular) << std::endl;
843 std::cout <<
" Resulting image saved in: " << filename << std::endl;
847 std::cout <<
" Resulting image saved in: " << filename << std::endl;
850 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 852 std::cout <<
"\n BGR cv::Mat to Grayscale" << std::endl;
854 cv::Mat colorMat = cv::imread(filename);
855 std::cout <<
" colorMat=" << colorMat.cols <<
"x" << colorMat.rows << std::endl;
862 for (
int iteration = 0; iteration < nbIterations; iteration++) {
864 value_sse += I_mat2gray_sse[0][0];
869 for (
int iteration = 0; iteration < nbIterations; iteration++) {
870 computeRegularBGRToGrayscale(colorMat, I_mat2gray_regular);
871 value_regular += I_mat2gray_sse[0][0];
877 for (
unsigned int i = 0; i < I_color.
getHeight(); i++) {
878 for (
unsigned int j = 0; j < I_color.
getWidth(); j++) {
880 (I_mat2gray_sse[i][j] - I_mat2gray_regular[i][j]) * (I_mat2gray_sse[i][j] - I_mat2gray_regular[i][j]);
884 std::cout <<
" t_regular (" << nbIterations <<
" iterations)=" << t_regular <<
" ms" 885 <<
" ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
886 std::cout <<
" Speed-up=" << (t_regular / t_sse) <<
"X" << std::endl;
887 std::cout <<
" RMSE error between SSE and regular version: " << (std::sqrt(rmse_error / I_color.
getSize()))
891 std::cout <<
" value_sse=" <<
static_cast<unsigned>(value_sse)
892 <<
" ; value_regular=" << static_cast<unsigned>(value_regular) << std::endl;
895 std::cout <<
" Resulting image saved in: " << filename << std::endl;
899 std::cout <<
" Resulting image saved in: " << filename << std::endl;
903 std::cout <<
"\n BGR Mat to Grayscale Mat" << std::endl;
904 cv::Mat grayscaleMat(colorMat.size(), CV_8U);
905 unsigned char value_mat = 0;
908 for (
int iteration = 0; iteration < nbIterations; iteration++) {
909 cv::cvtColor(colorMat, grayscaleMat, cv::COLOR_BGR2GRAY);
910 value_mat += grayscaleMat.ptr<uchar>(0)[0];
914 std::cout <<
" t_opencv (" << nbIterations <<
" iterations)=" << t_opencv <<
" ms" 915 <<
" ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
916 std::cout <<
" Speed-up=" << (t_opencv / t_sse) <<
"X" << std::endl;
917 std::cout <<
" value_mat=" <<
static_cast<unsigned>(value_mat) << std::endl;
922 std::cout <<
" Resulting image saved in: " << filename << std::endl;
926 std::cout <<
"\n RGB to Grayscale + Flip" << std::endl;
927 unsigned char *rgb2gray_flip_array_sse =
new unsigned char[I_color.
getSize()];
932 std::cout <<
" Resulting image saved in: " << filename << std::endl;
936 std::cout <<
"\n Conversion BGR to Grayscale + Flip" << std::endl;
937 unsigned char *bgr2gray_flip_array_sse =
new unsigned char[I_color.
getSize()];
942 std::cout <<
" Resulting image saved in: " << filename << std::endl;
946 std::cout <<
"\n RGB to Grayscale + Flip + Crop" << std::endl;
947 cv::Rect rect_roi(11, 17, 347, 449);
948 cv::Mat colorMat_crop = colorMat(rect_roi);
949 cv::Mat colorMat_crop_continous = colorMat(rect_roi).clone();
950 std::cout <<
" colorMat_crop: " << colorMat_crop.cols <<
"x" << colorMat_crop.rows <<
" is continuous? " 951 << colorMat_crop.isContinuous() << std::endl;
952 std::cout <<
" colorMat_crop_continous: " << colorMat_crop_continous.cols <<
"x" << colorMat_crop_continous.rows
953 <<
" is continuous? " << colorMat_crop_continous.isContinuous() << std::endl;
955 vpImage<vpRGBa> I_color_crop((
unsigned int)(rect_roi.height - rect_roi.y),
956 (
unsigned int)(rect_roi.width - rect_roi.x));
957 for (
unsigned int i = (
unsigned int)rect_roi.y; i < (
unsigned int)rect_roi.height; i++) {
958 for (
unsigned int j = (
unsigned int)rect_roi.x; j < (
unsigned int)rect_roi.width; j++) {
959 I_color_crop[(
unsigned int)((
int)i - rect_roi.y)][(
unsigned int)((
int)j - rect_roi.x)] = I_color[i][j];
962 filename =
vpIoTools::createFilePath(opath, "I_color_crop.ppm");
963 std::cout << " Resulting image saved in: " << filename <<
std::endl;
964 vpImageIo::write(I_color_crop, filename);
966 unsigned char *rgb_array_crop = new
unsigned char[I_color_crop.getSize() * 3];
967 vpImageConvert::RGBaToRGB((
unsigned char *)I_color_crop.bitmap, rgb_array_crop, I_color_crop.getSize());
969 unsigned char *rgb2gray_flip_crop_array_sse = new
unsigned char[I_color_crop.getSize()];
970 vpImageConvert::RGBToGrey(rgb_array_crop, rgb2gray_flip_crop_array_sse, I_color_crop.getWidth(),
971 I_color_crop.getHeight(), true);
972 vpImage<
unsigned char> I_rgb2gray_flip_crop_sse(rgb2gray_flip_crop_array_sse, I_color_crop.getHeight(),
973 I_color_crop.getWidth());
975 filename =
vpIoTools::createFilePath(opath, "I_rgb2gray_flip_crop_sse.pgm");
976 std::cout << " Resulting image saved in: " << filename <<
std::endl;
977 vpImageIo::write(I_rgb2gray_flip_crop_sse, filename);
980 std::cout << "\n BGR to Grayscale + Flip + Crop" <<
std::endl;
981 vpImage<
unsigned char> I_bgr2gray_flip_crop_sse(I_color_crop.getHeight(), I_color_crop.getWidth());
982 vpImageConvert::convert(colorMat_crop_continous, I_bgr2gray_flip_crop_sse, true);
984 filename =
vpIoTools::createFilePath(opath, "I_bgr2gray_flip_crop_sse.pgm");
985 std::cout << " Resulting image saved in: " << filename <<
std::endl;
986 vpImageIo::write(I_bgr2gray_flip_crop_sse, filename);
989 std::cout << "\n BGR to Grayscale + Flip + Crop + No continuous Mat" <<
std::endl;
990 vpImage<
unsigned char> I_bgr2gray_flip_crop_no_continuous_sse(I_color_crop.getHeight(), I_color_crop.getWidth());
991 vpImageConvert::convert(colorMat_crop, I_bgr2gray_flip_crop_no_continuous_sse, true);
993 filename =
vpIoTools::createFilePath(opath, "I_bgr2gray_flip_crop_no_continuous_sse.pgm");
994 std::cout << " Resulting image saved in: " << filename <<
std::endl;
995 vpImageIo::write(I_bgr2gray_flip_crop_no_continuous_sse, filename);
997 delete[] rgb_array_crop;
1000 std::cout <<
"Test succeed" << std::endl;
1005 std::cout <<
"Catch an exception: " << e.
getMessage() << std::endl;
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int size)
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Type * bitmap
points toward the bitmap
error that can be emited by ViSP classes.
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=NULL)
static void YUVToRGB(unsigned char y, unsigned char u, unsigned char v, unsigned char &r, unsigned char &g, unsigned char &b)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
unsigned int getSize() const
void resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
Read/write images with various image format.
const char * getMessage(void) const
static void merge(const vpImage< unsigned char > *R, const vpImage< unsigned char > *G, const vpImage< unsigned char > *B, const vpImage< unsigned char > *a, vpImage< vpRGBa > &RGBa)
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, const unsigned int size)
static void read(vpImage< unsigned char > &I, const std::string &filename)
static void HSVToRGBa(const double *hue, const double *saturation, const double *value, unsigned char *rgba, const unsigned int size)
unsigned int getHeight() const
static void RGBaToRGB(unsigned char *rgba, unsigned char *rgb, unsigned int size)