1. Problem phenomenon:
Compiler reports an error: Unhandled exception at 0x00007FFE8CCFCD29 (in photo mix.exe): Microsoft C++ exception: cv::Exception at memory location 0x000000F60319F020.
2. Problem analysis:
The source code is as follows:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main() {
Mat srcImage1 = imread("卧室智能家居总图.jpg");
Mat logoImage = imread("智能家居.jpg");
if (!srcImage1.data) {
printf("读取srcImage1错误!\n");
return 0;
}
if (!logoImage.data) {
printf("读取logoImage错误!\n");
return 0;
}
Mat imageROI = srcImage1(Rect(200, 150, logoImage.cols, logoImage.rows));
Mat mask = imread("智能家居.jpg", 0);
logoImage.copyTo(imageROI, mask);
namedWindow("<1>利用ROI实现图像叠加示例窗口");
imshow("<1>利用ROI实现图像叠加示例窗口", srcImage1);
waitKey(0);
return 1;
}
After debugging, it can be found that there is a problem with this sentence.
Since one of the pictures I chose is 790*1141 and the other is 800*680, the selected ROI exceeds the range of the original image, which eventually leads to an abnormal interruption.
3. Solution:
Adjust the parameters of ROI interception or adjust the pixels of the picture (according to the size of the picture selected by the individual).