上代码
Mat mat = imread(filename.toStdString(), CV_LOAD_IMAGE_UNCHANGED);
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
//在MyWindow的窗中中显示存储在img中的图片
imshow("MyWindow", mat);
//等待直到有键按下
waitKey(0);
/*OpenCV读取的像素值范围为0-255,DX的shader读取的值为0-1*/
MatIterator_<Vec3b> it, end;
for (it = mat.begin<Vec3b>(), end = mat.end<Vec3b>(); it != end; it++)
{
float tmp = (*it)[0]/255.0;
(*it)[0] = (tmp > 0.0f ? pow(tmp, gamma) : tmp)*255.0;
tmp = (*it)[1]/255.0;
(*it)[1] = (tmp > 0.0f ? pow(tmp, gamma) : tmp)*255.0;
tmp = (*it)[2]/255.0;
(*it)[2] = (tmp > 0.0f ? pow(tmp, gamma) : tmp)*255.0;
}
/*mat转换为QImage*/
cvtColor(mat, mat, CV_BGR2RGB);//Qt中支持的是RGB图像, OpenCV中支持的是BGR
QImage image = QImage((uchar*)(mat.data), mat.cols, mat.rows, QImage::Format_RGB888);
QImage * img = ℑ
/*图像缩放--增加图片质量的缩放*/
QImage* imgScaled = new QImage;
*imgScaled = img->scaled(ui.ImageDisplayLabel->width(), ui.ImageDisplayLabel->height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);/*保持长宽比例*/
ui.ImageDisplayLabel->setPixmap(QPixmap::fromImage(*imgScaled)); // 将图片显示到label上
/*将mat一帧一帧写入本地路径*/
string str = "E:/0_video_result/shabu/result";
imwrite(str+to_string(count2)+".jpg", frame);