将四张图合并在一起进行输出
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define IMG_HEIGHT (750)
#define IMG_WIDTH (900)
int main(int argc, char const *argv[]) {
Mat FourInOne = Mat::zeros(IMG_HEIGHT, IMG_WIDTH, CV_8UC3);
Mat OneImg = imread("./source/text/img/im2.png");
Mat TwoImg = imread("./source/text/img/im6.png");
Mat LeftImg;
Mat RightImg;
resize(OneImg, LeftImg, Size(IMG_WIDTH / 2, IMG_HEIGHT / 2), 0, 0, CV_INTER_LINEAR);
LeftImg.copyTo(FourInOne(Rect(0, 0, IMG_WIDTH / 2, IMG_HEIGHT / 2)));
resize(TwoImg, RightImg, Size(IMG_WIDTH / 2, IMG_HEIGHT / 2), 0, 0, CV_INTER_LINEAR);
RightImg.copyTo(FourInOne(Rect(IMG_WIDTH / 2, 0, IMG_WIDTH / 2, IMG_HEIGHT / 2)));
Mat ThreeImg = imread("./source/text/img/teddy1.png");
Mat LastImg = imread("./source/text/img/teddy2.png");
Mat Three_img;
Mat four_img;
resize(ThreeImg, Three_img, Size(IMG_WIDTH / 2, IMG_HEIGHT / 2), 0, 0, CV_INTER_LINEAR);
Three_img.copyTo(FourInOne(Rect(0, IMG_HEIGHT / 2, IMG_WIDTH / 2, IMG_HEIGHT / 2)));
resize(LastImg, four_img, Size(IMG_WIDTH / 2, IMG_HEIGHT / 2), 0, 0, CV_INTER_LINEAR);
four_img.copyTo(FourInOne(Rect(IMG_WIDTH / 2, IMG_HEIGHT / 2, IMG_WIDTH / 2, IMG_HEIGHT / 2)));
imshow("TWO_2_ONE", FourInOne);
waitKey(0);
return 0;
}
原理很简单, 主要是每次输出检测结果比较麻烦,合并一起显示方便观察.
|