Error record:
msvc-version.conf loaded but QMAKE_MSC_VER isn't set
Solution: Delete all generated files and recompile
step:
- read two images
- Uniform image size
- to fuse
- qt display
Effect:
Code:
.h:
// opencv
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
// file
#include <QFileDialog>
// qt
#include <QDebug>
// 读文件
Mat img_1, img_2;
QString filename = QFileDialog::getOpenFileName(this, QString("src img"),
QString("./file"),
QString("File(*.*)"));
img_1 = imread(filename.toStdString().c_str());
filename = QFileDialog::getOpenFileName(this, QString("src img"),
QString("./file"),
QString("File(*.*)"));
img_2 = imread(filename.toStdString().c_str());
if(img_1.empty() || img_2.empty()) {
qDebug() << "Img read error";
return;
}
// 统一大小
if(img_1.size > img_2.size) {
cv::resize(img_2, img_2, Size(img_1.cols, img_1.rows));
} else {
cv::resize(img_1, img_1, Size(img_2.cols, img_2.rows));
}
// 融合
double alpha = 0.5;
double beta = 1 - alpha;
double gamma = 0;
Mat dst;
// 图片1,权重,图片2,权重,显示权重,图片3
addWeighted(img_1, alpha, img_2, beta, gamma, dst);
imshow("dst", dst);
// qt显示
cvtColor(dst, dst, COLOR_BGR2RGB);//BGR convert to RGB
QImage Qtemp = QImage((const unsigned char *)(dst.data), dst.cols, dst.rows, dst.step,
QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(Qtemp));
ui->label->resize(Qtemp.size());
ui->label->show();