如标题所言,此处是对于灰度图像而言
///method 1 read the image data one by one
	for (int row = 0, i = 0;row < imgDst.rows;row++)
	{
		for (int col = 0;col < imgDst.cols;col++)
		{
			cout << setw(3) << (int)imgDst.at<uchar>(row, col) << " ";
			arr[i] =imgDst.at<uchar>(row, col) ;
			//cout << (int)arr[i] << " ";
			i++;
		}
		cout << endl;
	}

	//test to print
	for (int q = 0;q < imgDst.rows;q++)
	{
		for (int k = 0;k < imgDst.cols;k++)
		{
			int pos = q*imgDst.cols + k;
			cout << setw(3) << (int)arr[pos] << " ";
		}
		cout << endl;
	}

 

///method 2 memcpy the image data to uchar arr in rows
	unsigned char *imgData = new unsigned char[vec_Num];//直接将图像数据拷贝到数组中;
	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 print
	for (int q = 0;q < imgDst.rows;q++)
	{
		for (int k = 0;k < imgDst.cols;k++)
		{
			int pos = q*imgDst.cols + k;
			cout << setw(3) << (int)arr[pos] << " ";
		}
		cout << endl;
	}
	cout << endl;

相关文章:

  • 2022-12-23
  • 2021-12-20
  • 2022-02-06
  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-04-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2021-12-29
  • 2022-12-23
  • 2022-02-25
  • 2021-05-16
相关资源
相似解决方案