showManyImage
Posted 松子茶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了showManyImage相关的知识,希望对你有一定的参考价值。
/************************************************************************
* Copyright(c) 2012 Gavin Liu
* All rights reserved.
*
* File: showManyImage.cpp
* Brief:
* Version: 1.0
* Author: Gavin Liu
* Email: gavinliuyi@msn.com
* Date: 2012/08/28
* History:
************************************************************************/
#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;
// w - Maximum number of images in a row
// h - Maximum number of images in a column
int w, h;
// scale - How much we have to resize the image
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);
以上是关于showManyImage的主要内容,如果未能解决你的问题,请参考以下文章