int pixel[180*1500];
int i=0;
char filenametxt[150] = "inputimg.txt";
ifstream infile(filenametxt,ios::in);
//测试文件是否成功打开
if(!infile)
{
qDebug()<<"open error!";
exit(1);
}
//读取文件中的数据
while(!infile.eof())
{
infile>>pixel[i];
i++;
}
infile.close();
//将数据写到Mat矩阵中
Mat inputimg = Mat::zeros(180,1500,CV_8UC1);
int j=0;
for(int m=0;m<inputimg.rows;m++)
{
for(int n=0;n<inputimg.cols;n++)
{
inputimg.at<uchar>(m,n)=pixel[j];
j++;
}
}
//在界面label上显示
QImage Q_out_Img = MattoQImage.Mat2QImage(inputimg);
const QSize s_out = ui->label_outputImg->size() ;
ui->label_outputImg->setPixmap( QPixmap::fromImage( Q_out_Img ).scaled(s_out,Qt::KeepAspectRatio ) );
QT读取本地txt图像数据并在界面上显示该图像
猜你喜欢
转载自blog.csdn.net/weixin_38621214/article/details/84640268
今日推荐
周排行