///method 1 Read the image dataone by one for (int row = 0, i = 0;row < imgdst.rows;row++) {for (int col = 0;co L < imgdst.cols;col++) {cout << setw (3) << (int) imgdst.at<uchar> (row, col) << ""; Arr[i] =imgds T.at<uchar> (Row, col),//cout << (int) arr[i] << ""; i++;} cout << Endl;} Test to printfor (int q = 0;q < imgdst.rows;q++) {for (int k = 0;k < imgdst.cols;k++) {int pos = Q*imgdst.cols + K;cou T << setw (3) << (int) arr[pos] << "";} cout << Endl;}
///method 2 memcpy The image data to Uchar arr in rowsunsigned char *imgdata = new unsigned char[vec_num];//directly images The data is copied into the array; memcpy (Imgdata, Imgdst.data, imgdst.rows*imgdst.cols*sizeof (unsigned char)); for (int i = 0;i < vec_num;i++) {Arr[i] = (float) (imgdata[i])/255;} Test to printfor (int q = 0;q < imgdst.rows;q++) {for (int k = 0;k < imgdst.cols;k++) {int pos = Q*imgdst.cols + k;c Out << SETW (3) << (int) arr[pos] << "";} cout << Endl;} cout << Endl;
The two types of C++&OPENCV that read an image to an array