zoukankan      html  css  js  c++  java
  • C++&OpenCV中读取灰度图像到数组的两种

    如标题所言,此处是对于灰度图像而言
    ///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;
  • 相关阅读:
    JavaScript的性能优化:加载和执行
    JS获取图片的原始尺寸
    深入理解js构造函数
    Revit二次开发 获取缩略图
    WPF listbox分页
    WPF ListBox 图片显示及分页
    Revit禁用RibbonPanel
    C# excel 单元格居中
    WPF TreeView
    WPF ListView绑定数据
  • 原文地址:https://www.cnblogs.com/xiaopanlyu/p/5335061.html
Copyright © 2011-2022 走看看