Get the App
SLTechnology News&Howtos  ›  Development  › 

How to display multiple images in the same window with OpenCV

Shulou Source: shulou.com Published: 2022-06-02 04:30:14 11月01日 Update

This article mainly explains "how to display multiple images in the same window by OpenCV". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how OpenCV can display multiple images in the same window.

The parameters that you need to provide are as follows:

1. Vector of Mat of image sequence

2. Subplot settings similar to matlab

3. The maximum size displayed in a single image. Default is cvSize (400,280).

Due to time constraints, this version of the code can only batch display images of the same size.

The code is as follows:

/ * Author: Xin Yang* Date: 2014 Address 03 * Address: Shenzhen Univ School of medicine.* Email: xinyang@szu.edu.cn* function: Show multiple images in one window****/#include "opencv2/opencv.hpp" using namespace cv Using namespace std;void MultiImage_OneWin (const std::string& MultiShow_WinName, const vector& SrcImg_V, CvSize SubPlot, CvSize ImgMax_Size = cvSize (400,280); int main (void) {vector imgs (4); imgs [0] = imread ("F:\\ SA.jpg"); imgs [1] = imread ("F:\\ SA.jpg"); imgs [2] = imread ("F:\\ SA.jpg") Imgs [3] = imread ("F:\\ SA.jpg"); MultiImage_OneWin ("Multiple Images", imgs, cvSize (2,2), cvSize (400280)); return 0;}

[modification Note 20141119] Note 39 lines in the following code, type of Disp_Img creation, CV_8UC3 (8-bit 3-channel, see http://blog.csdn.net/yang_xian521/article/details/7107786 for details). Readers can modify it according to their own image data types, or use parameters to pass in (CV_8UC3 is essentially an integer macro).

Void MultiImage_OneWin (const std::string& MultiShow_WinName, const vector& SrcImg_V, CvSize SubPlot, CvSize ImgMax_Size) {/ / Reference: http://blog.csdn.net/yangyangyang20092010/article/details/21740373 / / * Usage * / vector imgs (4); / / imgs [0] = imread ("F:\\ SA2014.jpg") / / imgs [1] = imread ("F:\\ SA2014.jpg"); / / imgs [2] = imread ("F:\\ SA2014.jpg"); / / imgs [3] = imread ("F:\\ SA2014.jpg"); / / MultiImage_OneWin ("T", imgs, cvSize (2,2), cvSize (400,280)); / / Window's image Mat Disp_Img / / Width of source image CvSize Img_OrigSize = cvSize (SrcImg_V [0] .cols, SrcImg_V [0] .rows); / / * Set the width for displayed image * / Width vs height ratio of source image float WH_Ratio_Orig = Img_OrigSize.width/ (float) Img_OrigSize.height CvSize ImgDisp_Size = cvSize (100,100); if (Img_OrigSize.width > ImgMax_Size.width) ImgDisp_Size = cvSize (ImgMax_Size.width, (int) ImgMax_Size.width/WH_Ratio_Orig); else if (Img_OrigSize.height > ImgMax_Size.height) ImgDisp_Size = cvSize ((int) ImgMax_Size.height*WH_Ratio_Orig, ImgMax_Size.height) Else ImgDisp_Size = cvSize (Img_OrigSize.width, Img_OrigSize.height); / / * Check Image numbers with Subplot layout * / / int Img_Num = (int) SrcImg_V.size () If (Img_Num > SubPlot.width * SubPlot.height) {cout

Tags: Image code content parameter size type learning practical deeper maximum interest practicality substance reality sequence simple operation data integer method time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Docker OPPO Reno Apple