#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
void imshowMany(
const std::
string& _winName,
const vector<Mat>& _imgs);
int main(
void)
{
vector<Mat> imgs(
6);
imgs[
0] = imread(
"cm.png");
imgs[
1] = imread(
"wr.png");
imgs[
2] = imread(
"lina.png");
imgs[
3] = imread(
"dr.png");
imgs[
4] = imread(
"pom.png");
imgs[
5] = imread(
"qop.png");
imshowMany(
"DOTA2_Hero", imgs);
waitKey();
return 0;
}
void imshowMany(
const std::
string& _winName,
const vector<Mat>& _imgs)
{
int nImg = (
int)_imgs.size();
Mat dispImg;
int size;
int x, y;
int w, h;
float scale;
int max;
if (nImg <=
0)
{
printf(
"Number of arguments too small....\n");
return;
}
else if (nImg >
12)
{
printf(
"Number of arguments too large....\n");
return;
}
else if (nImg ==
1)
{
w = h =
1;
size =
300;
}
else if (nImg ==
2)
{
w =
2; h =
1;
size =
300;
}
else if (nImg ==
3 || nImg ==
4)
{
w =
2; h =
2;
size =
300;
}
else if (nImg ==
5 || nImg ==
6)
{
w =
3; h =
2;
size =
200;
}
else if (nImg ==
7 || nImg ==
8)
{
w =
4; h =
2;
size =
200;
}
else
{
w =
4; h =
3;
size =
150;
}
dispImg.create(Size(
100 + size*w,
60 + size*h), CV_8UC3);
for (
int i=
0, m=
20, n=
20; i<nImg; i++, m+=(
20+size))
{
x = _imgs[i].cols;
y = _imgs[i].rows;
max = (x > y)? x: y;
scale = (
float) ( (
float) max / size );
if (i%w==
0 && m!=
20)
{
m =
20;
n +=
20+size;
}
Mat imgROI = dispImg(Rect(m, n, (
int)(x/scale), (
int)(y/scale)));
resize(_imgs[i], imgROI, Size((
int)(x/scale), (
int)(y/scale)));
}
namedWindow(_winName);
imshow(_winName, dispImg);
}
转载请注明原文地址: https://ju.6miu.com/read-1298883.html