从TXT读取快速读取像素值数据,并显示成为图像

const int maxs = 1544 * 2304 * 2;

void analyse(char *buf_src, unsigned short *buff_dst, int len = maxs)
{
int i;
buff_dst[i = 0] = 0;
for (char *p = buf_src; *p && p - buf_src < len; p++)
{
if (*p == ' ')
{
/*cout << numbers[i] << endl;*/
buff_dst[++i] = 0;
}

else
buff_dst[i] = buff_dst[i] * 10 + *p - '0';
}
}

int main(int argc, char* argv[])
{
ifstream filestr;
filestr.open("test.txt", ios::binary);

filebuf *pbuf = filestr.rdbuf();
const long size = pbuf->pubseekoff(0, ios::end, ios::in);
pbuf->pubseekpos(0, ios::in);
auto* buffer = new char[size];
pbuf->sgetn(buffer, size);
filestr.close();
//cout.write(buffer, size);
auto*buff_dst = new unsigned short[1544 * 2304];
analyse(buffer, buff_dst, size);

const Mat image = Mat(1544, 2304, CV_16UC1);
memcpy(image.data, buff_dst, 1544*2304*2);
delete[]buffer;
return 0;
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页