图像要求:尺寸大小一致
void procImg(float alpha)
{
QString imgPath1 = "girl1.jpg";
Mat imgSrc1 = imread(imgPath1.toLatin1().data());
cvtColor(imgSrc1 ,imgSrc1 ,COLOR_BGR2RGB);
QString imgPath2 = "girl2.jpg";
Mat imgSrc2 = imread(imgPath2.toLatin1().data());
cvtColor(imgSrc2,imgSrc2,COLOR_BGR2RGB);
Mat imgDst;
//根据两种原图和alpha值,用插值算法合成一张新图
addWeighted(imgSrc2,alpha,imgSrc1,1-alpha,0,imgDst);
QImage img = QImage((const unsigned char*)(imgDst.data),imgDst.cols,imgDst.rows,QImage::Format_RGB888);
imgShow(img);
}
效果图:
报错信息:
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.3) Error: Sizes of input arguments do not match (The operation is neither 'array op array'
(where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array')
in arithm_op, file D:\OpenCV_3.4.3-Source\modules\core\src\arithm.cpp, line 656
原因:
两幅图的size不一致