Demo
int main(int argc, char* argv[]){
//读取大图片
Mat img1 = imread("c://01//01.jpg");
//读取小图片
Mat img2 = imread("c://01//02.jpg");
Mat combinationImg = Mat::zeros(Size(1028, 961), CV_8UC3);
Rect ROI(0, 0, 1024, 768);
Mat temp;
resize(img1, temp, Size(ROI.width , ROI.height ));
temp.copyTo(combinationImg(ROI));
for (int num = 0; num < 4 ;num++) {
Rect ROI2(1 + (256 * num), 769 ,256, 192);
Mat temp2; resize(img2, temp2, Size(ROI2.width, ROI2.height));
temp2.copyTo(combinationImg(ROI2));
}
string title = "Angelo";
namedWindow(title, 1);
imshow(title, combinationImg);
waitKey();
return 0;
}
运行结果:

public static void main(String[] args) {
URL url = ClassLoader.getSystemResource("opencv/x64/opencv_java430.dll");
System.load(url.getPath());
Mat img1 = imread("C:\\01\\03.jpg", 1);
Mat img2 = imread("C:\\01\\04.jpg", 1);
Mat dispImage = Mat.zeros(new Size(1028,980), CvType.CV_8UC3);
Rect ROI = new Rect(0, 0, 1024, 768);
Mat temp = new Mat();
Imgproc.resize(img1, temp, new Size(ROI.width , ROI.height));
temp.copyTo(dispImage.submat(ROI));
for (int num = 0; num < 4 ;num++) {
Rect ROI2 = new Rect(1 + (256 * num), 778 ,256, 192);
Mat temp2 = new Mat();
Imgproc.resize(img2, temp2,new Size(ROI2.width, ROI2.height));
temp2.copyTo(dispImage.submat(ROI2));
}
imshow("Angelo", dispImage);
waitKey();
}

需要合理处理xy坐标,以及图片的width和height
网友评论