41 #include <visp3/core/vpConfig.h>
42 #include <visp3/core/vpImage.h>
43 #include <visp3/io/vpImageIo.h>
44 #include <visp3/core/vpImageConvert.h>
45 #include <visp3/io/vpParseArgv.h>
46 #include <visp3/core/vpIoTools.h>
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpTime.h>
58 #define GETOPTARGS "cdi:o:n:h"
72 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user,
int nbiter)
75 Test image conversions.\n\
78 %s [-i <input image path>] [-o <output image path>] [-n <nb benchmark iterations>]\n\
84 -i <input image path> %s\n\
85 Set image input path.\n\
86 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
87 and \"ViSP-images/Klimt/Klimt.ppm\" images.\n\
88 Setting the VISP_INPUT_IMAGE_PATH environment\n\
89 variable produces the same behaviour than using\n\
92 -o <output image path> %s\n\
93 Set image output path.\n\
94 From this directory, creates the \"%s\"\n\
95 subdirectory depending on the username, where \n\
96 Klimt_grey.pgm and Klimt_color.ppm output images\n\
99 -n <nb benchmark iterations> %d\n\
100 Set the number of benchmark iterations.\n\
103 Print the help.\n\n",
104 ipath.c_str(), opath.c_str(), user.c_str(), nbiter);
107 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
123 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user,
131 case 'i': ipath = optarg_;
break;
132 case 'o': opath = optarg_;
break;
133 case 'n': nbIterations = atoi(optarg_);
break;
134 case 'h': usage(argv[0], NULL, ipath, opath, user, nbIterations);
return false;
break;
141 usage(argv[0], optarg_, ipath, opath, user, nbIterations);
return false;
break;
145 if ((c == 1) || (c == -1)) {
147 usage(argv[0], NULL, ipath, opath, user, nbIterations);
148 std::cerr <<
"ERROR: " << std::endl;
149 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
156 void computeRegularRGBaToGrayscale(
const unsigned char* rgba,
unsigned char* grey,
unsigned int size) {
157 const unsigned char *pt_input = rgba;
158 const unsigned char *pt_end = rgba + size*4;
159 unsigned char *pt_output = grey;
161 while(pt_input != pt_end) {
162 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
163 + 0.7152 * (*(pt_input + 1))
164 + 0.0722 * (*(pt_input + 2)) );
170 void computeRegularRGBToGrayscale(
const unsigned char* rgb,
unsigned char* grey,
unsigned int size) {
171 const unsigned char *pt_input = rgb;
172 const unsigned char* pt_end = rgb + size*3;
173 unsigned char *pt_output = grey;
175 while(pt_input != pt_end) {
176 *pt_output = (
unsigned char) (0.2126 * (*pt_input)
177 + 0.7152 * (*(pt_input + 1))
178 + 0.0722 * (*(pt_input + 2)) );
184 void computeRegularBGRToGrayscale(
unsigned char * bgr,
unsigned char * grey,
185 unsigned int width,
unsigned int height,
bool flip) {
188 int lineStep = (flip) ? -(
int)(width*3) : (
int)(width*3);
191 unsigned char * src = (flip) ? bgr+(width*height*3)+lineStep : bgr;
196 for(i=0 ; i < height ; i++)
198 unsigned char *line = src;
199 for( j=0 ; j < width ; j++)
201 *grey++ = (
unsigned char)( 0.2126 * *(line+2)
203 + 0.0722 * *(line+0)) ;
212 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
215 if(src.type() == CV_8UC3) {
216 dest.
resize((
unsigned int)src.rows, (
unsigned int)src.cols);
218 if(src.isContinuous()) {
219 computeRegularBGRToGrayscale((
unsigned char*)src.data, (
unsigned char*)dest.
bitmap, (
unsigned int)src.cols, (
unsigned int)src.rows,
false);
226 main(
int argc,
const char ** argv)
229 std::string env_ipath;
230 std::string opt_ipath;
231 std::string opt_opath;
234 std::string filename;
235 std::string username;
236 int nbIterations = 100;
242 if (! env_ipath.empty())
247 opt_opath =
"C:/temp";
256 if (getOptions(argc, argv, opt_ipath, opt_opath, username, nbIterations) ==
false) {
261 if (!opt_ipath.empty())
263 if (!opt_opath.empty())
276 usage(argv[0], NULL, ipath, opt_opath, username, nbIterations);
277 std::cerr << std::endl
278 <<
"ERROR:" << std::endl;
279 std::cerr <<
" Cannot create " << opath << std::endl;
280 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
287 if (opt_ipath.empty()) {
288 if (ipath != env_ipath) {
289 std::cout << std::endl
290 <<
"WARNING: " << std::endl;
291 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
292 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
293 <<
" we skip the environment variable." << std::endl;
298 if (opt_ipath.empty() && env_ipath.empty()){
299 usage(argv[0], NULL, ipath, opt_opath, username, nbIterations);
300 std::cerr << std::endl
301 <<
"ERROR:" << std::endl;
302 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
304 <<
" environment variable to specify the location of the " << std::endl
305 <<
" image path where test images are located." << std::endl << std::endl;
317 std::cout <<
"** Convert a grey image (.pgm) to a color image (.ppm)" << std::endl;
320 std::cout <<
" Load " << filename << std::endl;
325 std::cout <<
" Resulting image saved in: " << filename << std::endl;
329 std::cout <<
"** Convert a color image (.ppm) to a grey image (.pgm)" << std::endl;
332 std::cout <<
" Load " << filename << std::endl;
337 std::cout <<
" Resulting image saved in: " << filename << std::endl;
341 std::cout <<
"** Convert YUV pixel value to a RGB value" << std::endl;
342 unsigned char y=187, u=10, v=30;
343 unsigned char r, g, b;
347 std::cout <<
" y(" << (int)y <<
") u("<< (
int)u << ") v(" << (
int)v << ") = r(" << (
int)r << ") g(" << (
int)g << ") b(" << (
int)b << ")" << std::endl;
349 #ifdef VISP_HAVE_OPENCV
350 #if VISP_HAVE_OPENCV_VERSION < 0x020408
355 std::cout <<
"** Convert an IplImage to a vpImage<vpRGBa>" << std::endl;
356 IplImage* image = NULL;
361 std::cout <<
" Reading the color image with opencv: "<< filename << std::endl;
362 if((image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_COLOR)) == NULL) {
363 std::cout <<
" Cannot read image: "<< filename << std::endl;
368 std::cout <<
" Resulting image saved in: " << filename << std::endl;
371 std::cout <<
" Convert result in " << filename << std::endl;
376 std::cout <<
" Reading the greyscale image with opencv: " << filename << std::endl;
377 if(image!=NULL) cvReleaseImage( &image );
378 if((image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE)) == NULL) {
379 std::cout <<
" Cannot read image: " << filename << std::endl;
384 std::cout <<
" Resulting image saved in: " << filename << std::endl;
387 std::cout <<
" Convert result in " << filename << std::endl;
392 std::cout <<
"** Convert an IplImage to a vpImage<unsigned char>" << std::endl;
397 std::cout <<
" Reading the color image with opencv: "<< filename << std::endl;
398 if(image!=NULL) cvReleaseImage( &image );
399 if((image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_COLOR)) == NULL) {
400 std::cout <<
" Cannot read image: "<< filename << std::endl;
405 std::cout <<
" Resulting image saved in: " << filename << std::endl;
408 std::cout <<
" Convert result in " << filename << std::endl;
414 std::cout <<
" Reading the greyscale image with opencv: " << filename << std::endl;
415 if(image!=NULL) cvReleaseImage( &image );
416 if((image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE)) == NULL) {
417 std::cout <<
" Cannot read image: "<< filename << std::endl;
422 std::cout <<
" Resulting image saved in: " << filename << std::endl;
425 std::cout <<
" Convert result in " << filename << std::endl;
430 std::cout <<
"** Convert a vpImage<vpRGBa> to an IplImage" << std::endl;
436 std::cout <<
" Load " << filename << std::endl;
441 std::cout <<
" Write " << filename << std::endl;
442 if((cvSaveImage(filename.c_str(), image)) == 0) {
443 std::cout <<
" Cannot write image: " << filename << std::endl;
444 if(image!=NULL) cvReleaseImage( &image );
447 std::cout <<
" Convert result in " << filename << std::endl;
452 std::cout <<
"** Convert a vpImage<unsigned char> to an IplImage" << std::endl;
458 std::cout <<
" Load " << filename << std::endl;
464 std::cout <<
" Write " << filename << std::endl;
465 if((cvSaveImage(filename.c_str(), image)) == 0) {
466 std::cout <<
" Cannot write image: "<< std::endl << filename << std::endl;
467 if(image!=NULL) cvReleaseImage( &image );
470 std::cout <<
" Convert result in " << filename << std::endl;
472 if(image!=NULL) cvReleaseImage( &image );
474 std::cout <<
"== Conversion c interface : " << t1 - t0 <<
" ms" << std::endl;
481 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
486 std::cout <<
"** Convert a cv::Mat to a vpImage<vpRGBa>" << std::endl;
489 std::cout <<
" Reading the color image with c++ interface of opencv: " << filename << std::endl;
490 imageMat = cv::imread(filename, 1);
491 if(imageMat.data == NULL){
492 std::cout <<
" Cannot read image: "<< filename << std::endl;
497 std::cout <<
" Resulting image saved in: " << filename << std::endl;
503 std::cout <<
" Reading the greyscale image with opencv: " << filename << std::endl;
504 imageMat = cv::imread(filename, 0);
505 if(imageMat.data == NULL) {
506 std::cout <<
" Cannot read image: "<< filename << std::endl;
511 std::cout <<
" Resulting image saved in: " << filename << std::endl;
517 std::cout <<
"** Convert a cv::Mat to a vpImage<nsigned char>" << std::endl;
522 std::cout <<
" Reading the color image with opencv: " << filename << std::endl;
523 imageMat = cv::imread(filename, 1);
524 if(imageMat.data == NULL){
525 std::cout <<
" Cannot read image: " << filename << std::endl;
530 std::cout <<
" Resulting image saved in: " << filename << std::endl;
537 std::cout <<
" Reading the greyscale image with opencv: " << filename << std::endl;
538 imageMat = cv::imread(filename, 0);
539 if(imageMat.data == NULL){
540 std::cout <<
" Cannot read image: "<< filename << std::endl;
545 std::cout <<
" Resulting image saved in: " << filename << std::endl;
548 std::cout <<
" Convert result in " << filename << std::endl;
553 std::cout <<
"** Convert a vpImage<vpRGBa> to a cv::Mat" << std::endl;
559 std::cout <<
" Load " << filename << std::endl;
564 std::cout <<
" Resulting image saved in: " << filename << std::endl;
565 if(!cv::imwrite(filename, imageMat)){
566 std::cout <<
" Cannot write image: " << filename << std::endl;
569 std::cout <<
" Convert result in " << filename << std::endl;
574 std::cout <<
"** Convert a vpImage<unsigned char> to a cv::Mat" << std::endl;
580 std::cout <<
" Load " << filename << std::endl;
586 std::cout <<
" Resulting image saved in: " << filename << std::endl;
587 if(!cv::imwrite(filename, imageMat)){
588 std::cout <<
" Cannot write image: "<< filename << std::endl;
591 std::cout <<
" Convert result in " << filename << std::endl;
593 std::cout <<
"== Conversion c++ interface : " << t3 - t2 <<
" ms" << std::endl;
600 std::cout <<
"** Split a vpImage<vpRGBa> to vpImage<unsigned char>" << std::endl;
606 std::cout <<
" Load " << filename << std::endl;
611 for(
int i=0; i<1000;i++){
616 std::cout <<
" Time for 1000 split (ms): " << endtime - begintime <<std::endl;
620 std::cout <<
" Save Klimt R channel: " << filename << std::endl;
625 std::cout <<
" Save Klimt B channel: " << filename << std::endl;
631 std::cout <<
"** Merge 4 vpImage<unsigned char> (RGBa) to vpImage<vpRGBa>" << std::endl;
635 for(
int i=0; i<1000; i++){
640 std::cout <<
" Time for 1000 merge (ms): "<< endtime - begintime <<std::endl;
643 std::cout <<
" Resulting image saved in: " << filename << std::endl;
649 std::cout <<
"** Convert a vpImage<vpRGBa> in RGB color space to a vpImage<vpRGBa> in HSV color" << std::endl;
650 unsigned int size = Ic.
getSize();
652 unsigned char *hue =
new unsigned char[size];
653 unsigned char *saturation =
new unsigned char[size];
654 unsigned char *value =
new unsigned char[size];
664 std::cout <<
" Resulting image saved in: " << filename << std::endl;
668 double *hue2 =
new double[size];
669 double *saturation2 =
new double[size];
670 double *value2 =
new double[size];
673 unsigned char *rgba =
new unsigned char[size*4];
681 if(saturation2 != NULL) {
682 delete[] saturation2;
693 std::cout <<
" Resulting image saved in: " << filename << std::endl;
696 for(
unsigned int i = 0; i < Ic.
getHeight(); i++) {
697 for(
unsigned int j = 0; j < Ic.
getWidth(); j++) {
698 if(Ic[i][j].R != I_HSV2RGBa[i][j].R ||
699 Ic[i][j].G != I_HSV2RGBa[i][j].G ||
700 Ic[i][j].B != I_HSV2RGBa[i][j].B) {
701 std::cerr <<
"Ic[i][j].R=" <<
static_cast<unsigned>(Ic[i][j].R)
702 <<
" ; I_HSV2RGBa[i][j].R=" << static_cast<unsigned>(I_HSV2RGBa[i][j].R) << std::endl;
703 std::cerr <<
"Ic[i][j].G=" <<
static_cast<unsigned>(Ic[i][j].G)
704 <<
" ; I_HSV2RGBa[i][j].G=" << static_cast<unsigned>(I_HSV2RGBa[i][j].G) << std::endl;
705 std::cerr <<
"Ic[i][j].B=" <<
static_cast<unsigned>(Ic[i][j].B)
706 <<
" ; I_HSV2RGBa[i][j].B=" << static_cast<unsigned>(I_HSV2RGBa[i][j].B) << std::endl;
715 std::cout <<
"** Construction of a vpImage from an array with copyData==true" << std::endl;
716 unsigned char *rgba2 =
new unsigned char[size*4];
717 memset(rgba2, 127, size*4);
724 std::cout <<
" Resulting image saved in: " << filename << std::endl;
727 if(I_copyData.getSize() > 0) {
728 I_copyData[0][0].R = 10;
734 std::cout <<
"** Benchmark and test RGBa / RGB / cv::Mat to Grayscale conversion" << std::endl;
742 unsigned char value_sse = 0, value_regular = 0;
745 for(
int iteration = 0; iteration < nbIterations; iteration++) {
747 value_sse += I_gray_sse[0][0];
752 for(
int iteration = 0; iteration < nbIterations; iteration++) {
753 computeRegularRGBaToGrayscale((
unsigned char *) I_color.
bitmap, I_gray_regular.bitmap, I_color.
getSize());
754 value_regular += I_gray_regular[0][0];
759 double rmse_error = 0.0;
760 for(
unsigned int i = 0; i < I_color.
getHeight(); i++) {
761 for(
unsigned int j = 0; j < I_color.
getWidth(); j++) {
762 rmse_error += (I_gray_sse[i][j] - I_gray_regular[i][j]) * (I_gray_sse[i][j] - I_gray_regular[i][j]);
766 std::cout <<
"\n RGBa to Grayscale" << std::endl;
767 std::cout <<
" t_regular (" << nbIterations <<
" iterations)=" << t_regular <<
" ms"
768 <<
" ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
769 std::cout <<
" Speed-up=" << (t_regular/t_sse) <<
"X" << std::endl;
770 std::cout <<
" RMSE error between SSE and regular version: " << (std::sqrt(rmse_error/I_color.
getSize())) << std::endl;
773 std::cout <<
" value_sse=" <<
static_cast<unsigned>(value_sse)
774 <<
" ; value_regular=" << static_cast<unsigned>(value_regular) << std::endl;
777 std::cout <<
" Resulting image saved in: " << filename << std::endl;
781 std::cout <<
" Resulting image saved in: " << filename << std::endl;
785 unsigned char *rgb_array =
new unsigned char[I_color.
getSize() * 3];
791 unsigned char *rgb2gray_array_sse =
new unsigned char[I_color.
getSize()];
793 for(
int iteration = 0; iteration < nbIterations; iteration++) {
795 value_sse += rgb2gray_array_sse[0];
799 unsigned char *rgb2gray_array_regular =
new unsigned char[I_color.
getSize()];
801 for(
int iteration = 0; iteration < nbIterations; iteration++) {
802 computeRegularRGBToGrayscale(rgb_array, rgb2gray_array_regular, I_color.
getSize());
803 value_regular += rgb2gray_array_regular[0];
812 for(
unsigned int i = 0; i < I_color.
getHeight(); i++) {
813 for(
unsigned int j = 0; j < I_color.
getWidth(); j++) {
814 rmse_error += (I_gray2rgba_sse[i][j] - I_gray2rgba_regular[i][j]) * (I_gray2rgba_sse[i][j] - I_gray2rgba_regular[i][j]);
818 std::cout <<
"\n RGB to Grayscale" << std::endl;
819 std::cout <<
" t_regular (" << nbIterations <<
" iterations)=" << t_regular <<
" ms"
820 <<
" ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
821 std::cout <<
" Speed-up=" << (t_regular/t_sse) <<
"X" << std::endl;
822 std::cout <<
" RMSE error between SSE and regular version: " << (std::sqrt(rmse_error/I_color.
getSize())) << std::endl;
825 std::cout <<
" value_sse=" <<
static_cast<unsigned>(value_sse)
826 <<
" ; value_regular=" << static_cast<unsigned>(value_regular) << std::endl;
829 std::cout <<
" Resulting image saved in: " << filename << std::endl;
833 std::cout <<
" Resulting image saved in: " << filename << std::endl;
836 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
838 std::cout <<
"\n BGR cv::Mat to Grayscale" << std::endl;
840 cv::Mat colorMat = cv::imread(filename);
841 std::cout <<
" colorMat=" << colorMat.cols <<
"x" << colorMat.rows << std::endl;
848 for(
int iteration = 0; iteration < nbIterations; iteration++) {
850 value_sse += I_mat2gray_sse[0][0];
855 for(
int iteration = 0; iteration < nbIterations; iteration++) {
856 computeRegularBGRToGrayscale(colorMat, I_mat2gray_regular);
857 value_regular += I_mat2gray_sse[0][0];
863 for(
unsigned int i = 0; i < I_color.
getHeight(); i++) {
864 for(
unsigned int j = 0; j < I_color.
getWidth(); j++) {
865 rmse_error += (I_mat2gray_sse[i][j] - I_mat2gray_regular[i][j]) * (I_mat2gray_sse[i][j] - I_mat2gray_regular[i][j]);
869 std::cout <<
" t_regular (" << nbIterations <<
" iterations)=" << t_regular <<
" ms"
870 <<
" ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
871 std::cout <<
" Speed-up=" << (t_regular/t_sse) <<
"X" << std::endl;
872 std::cout <<
" RMSE error between SSE and regular version: " << (std::sqrt(rmse_error/I_color.
getSize())) << std::endl;
875 std::cout <<
" value_sse=" <<
static_cast<unsigned>(value_sse)
876 <<
" ; value_regular=" << static_cast<unsigned>(value_regular) << std::endl;
879 std::cout <<
" Resulting image saved in: " << filename << std::endl;
883 std::cout <<
" Resulting image saved in: " << filename << std::endl;
888 std::cout <<
"\n BGR Mat to Grayscale Mat" << std::endl;
889 cv::Mat grayscaleMat(colorMat.size(), CV_8U);
890 unsigned char value_mat = 0;
893 for(
int iteration = 0; iteration < nbIterations; iteration++) {
894 cv::cvtColor(colorMat, grayscaleMat, cv::COLOR_BGR2GRAY);
895 value_mat += grayscaleMat.ptr<uchar>(0)[0];
899 std::cout <<
" t_opencv (" << nbIterations <<
" iterations)=" << t_opencv <<
" ms"
900 <<
" ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
901 std::cout <<
" Speed-up=" << (t_opencv/t_sse) <<
"X" << std::endl;
902 std::cout <<
" value_mat=" <<
static_cast<unsigned>(value_mat) << std::endl;
907 std::cout <<
" Resulting image saved in: " << filename << std::endl;
912 std::cout <<
"\n RGB to Grayscale + Flip" << std::endl;
913 unsigned char *rgb2gray_flip_array_sse =
new unsigned char[I_color.
getSize()];
918 std::cout <<
" Resulting image saved in: " << filename << std::endl;
923 std::cout <<
"\n Conversion BGR to Grayscale + Flip" << std::endl;
924 unsigned char *bgr2gray_flip_array_sse =
new unsigned char[I_color.
getSize()];
929 std::cout <<
" Resulting image saved in: " << filename << std::endl;
934 std::cout <<
"\n RGB to Grayscale + Flip + Crop" << std::endl;
935 cv::Rect rect_roi(11, 17, 347, 449);
936 cv::Mat colorMat_crop = colorMat(rect_roi);
937 cv::Mat colorMat_crop_continous = colorMat(rect_roi).clone();
938 std::cout <<
" colorMat_crop: " << colorMat_crop.cols <<
"x" << colorMat_crop.rows <<
939 " is continuous? " << colorMat_crop.isContinuous() << std::endl;
940 std::cout <<
" colorMat_crop_continous: " << colorMat_crop_continous.cols
941 <<
"x" << colorMat_crop_continous.rows <<
" is continuous? "
942 << colorMat_crop_continous.isContinuous() << std::endl;
944 vpImage<vpRGBa> I_color_crop( (
unsigned int) (rect_roi.height-rect_roi.y), (
unsigned int) (rect_roi.width-rect_roi.x) );
945 for(
unsigned int i = (
unsigned int) rect_roi.y; i < (
unsigned int) rect_roi.height; i++) {
946 for(
unsigned int j = (
unsigned int) rect_roi.x; j < (
unsigned int) rect_roi.width; j++) {
947 I_color_crop[(
unsigned int) ((
int)i-rect_roi.y)][(
unsigned int) ((
int)j-rect_roi.x)] = I_color[i][j];
950 filename =
vpIoTools::createFilePath(opath, "I_color_crop.ppm");
951 std::cout << " Resulting image saved in: " << filename << std::endl;
952 vpImageIo::write(I_color_crop, filename);
954 unsigned char *rgb_array_crop = new
unsigned char[I_color_crop.getSize()*3];
955 vpImageConvert::RGBaToRGB((
unsigned char *) I_color_crop.bitmap, rgb_array_crop, I_color_crop.getSize());
957 unsigned char *rgb2gray_flip_crop_array_sse = new
unsigned char[I_color_crop.getSize()];
958 vpImageConvert::RGBToGrey(rgb_array_crop, rgb2gray_flip_crop_array_sse, I_color_crop.getWidth(),
959 I_color_crop.getHeight(), true);
960 vpImage<
unsigned char> I_rgb2gray_flip_crop_sse(rgb2gray_flip_crop_array_sse, I_color_crop.getHeight(),
961 I_color_crop.getWidth());
963 filename =
vpIoTools::createFilePath(opath, "I_rgb2gray_flip_crop_sse.pgm");
964 std::cout << " Resulting image saved in: " << filename << std::endl;
965 vpImageIo::write(I_rgb2gray_flip_crop_sse, filename);
969 std::cout << "\n BGR to Grayscale + Flip + Crop" << std::endl;
970 vpImage<
unsigned char> I_bgr2gray_flip_crop_sse(I_color_crop.getHeight(), I_color_crop.getWidth());
971 vpImageConvert::convert(colorMat_crop_continous, I_bgr2gray_flip_crop_sse, true);
973 filename =
vpIoTools::createFilePath(opath, "I_bgr2gray_flip_crop_sse.pgm");
974 std::cout << " Resulting image saved in: " << filename << std::endl;
975 vpImageIo::write(I_bgr2gray_flip_crop_sse, filename);
979 std::cout << "\n BGR to Grayscale + Flip + Crop + No continuous Mat" << std::endl;
980 vpImage<
unsigned char> I_bgr2gray_flip_crop_no_continuous_sse(I_color_crop.getHeight(),
981 I_color_crop.getWidth());
982 vpImageConvert::convert(colorMat_crop, I_bgr2gray_flip_crop_no_continuous_sse, true);
984 filename =
vpIoTools::createFilePath(opath, "I_bgr2gray_flip_crop_no_continuous_sse.pgm");
985 std::cout << " Resulting image saved in: " << filename << std::endl;
986 vpImageIo::write(I_bgr2gray_flip_crop_no_continuous_sse, filename);
989 std::cout <<
"Test succeed" << std::endl;
995 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)