opencv 读取图片并提取Mat中data数据

uchar* pImageData = (uchar*)malloc(width*height* 3 * sizeof(uchar));

Mat MyImage = imread(file_name,IMREAD_COLOR);

              if(!MyImage.data){

                     cout<< "读取不到图片" << endl;

                     return0;

              }

 

              for(int i = 0; i < height; i++)

              {

                     constuchar* current = MyImage.ptr(i);

                     for(int j = 0; j < width; j++)

                     {

                            pImageData[i*width* 3 + 3 * j + 0] = current[3 * j + 0];

                           pImageData[i*width * 3+ 3 * j + 1] = current[3 * j + 1];

                           pImageData[i*width * 3+ 3 * j + 2] = current[3 * j + 2];

                     }

              }

你可能感兴趣的:(图像处理)