Opencv 多图片同显示c++代码

//head.h

void ShowImgs(const std::string& _winName, const std::vector& _imgs, cv::Size size_form , cv::Size size_img = cv::Size(300, 300));



//func.cpp

//定义一个大的Mat类型,将小的Mat一个个贴上去


void ShowImgs(const std::string& _winName, const std::vector& _imgs,cv::Size size_form,cv::Size size_img)
{
	int w = 20;            //宽间距
	int h = 20;            //高间距

	int cols = size_form.width;            //排版显示    每行显示图片个数
	int rows = size_form.height;           //排版显示    每列显示图片个数

	cv::Mat img = cv::Mat(cv::Size(20 * (cols + 1) + size_img.width * cols, 20 * (rows + 1) + size_img.height * rows), CV_32F, cv::Scalar(255, 255, 255));


	int x = 0, y = 0;       //位置
	for (int j = 0; j < rows; j++)
	{
		for (int i = 0; i < cols; i++)
		{
			cv::Mat temp = cv::Mat(_imgs[i+j*rows].size(), CV_32F);
			cv::resize(_imgs[i+j*rows], temp, size_img);
			cv::Mat imgROI = img(cv::Rect(x + (i + 1) * w + i * size_img.width, y + (j + 1) * h + j * size_img.height, size_img.width, size_img.height));
			temp.copyTo(imgROI);
		}
	}

	cv::imshow(_winName, img);

}

//main.cpp

ShowImgs("img", imgs,cv::Size(3,2));

cv::waitKey(0);

 

你可能感兴趣的:(OpenCV)