current position:Home>Python opencv display multiple images in the same window
Python opencv display multiple images in the same window
2022-06-24 08:52:29【Coding leaves】
In order to compare the effects before and after image processing , Especially the rendering before and after the algorithm processing , We need to display multiple images at the same time . Here the opencv Image mosaic method to achieve the desired effect .
1 Defined function show_multi_img
Define picture display functions show_multi_img, Including 5 Parameters , The meanings and types of each parameter are as follows :
(1)scale:float type , Image scaling , That is to scale the image .
(2)imglist:list type , That is, a list of image data to be displayed .
(3)order:list or tuple type , Refers to the rows and columns of the image display window ,order[0] Said line ,order[1] The column . The default value is 1 That's ok N Column ,N by imglist The length of , That is, the number of images to be displayed .
(4)border:int type , That is, the minimum interval between images .
(5)border:tuple type , The color of the image space .
This function is compatible with displaying pictures of different sizes at the same time .
2 Sample code
# -*- coding: utf-8 -*-
"""
The official account of Lele perception school
@author: https://blog.csdn.net/suiyingy
"""
import cv2
import numpy as np
def show_multi_imgs(scale, imglist, order=None, border=10, border_color=(255, 255, 0)):
"""
:param scale: float Scale of original image scaling
:param imglist: list Image sequence to be displayed
:param order: list or tuple According to the order That's ok × Column
:param border: int Image spacing distance
:param border_color: tuple Bay area color
:return: Back to the spliced numpy Array
"""
if order is None:
order = [1, len(imglist)]
allimgs = imglist.copy()
ws , hs = [], []
for i, img in enumerate(allimgs):
if np.ndim(img) == 2:
allimgs[i] = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
allimgs[i] = cv2.resize(img, dsize=(0, 0), fx=scale, fy=scale)
ws.append(allimgs[i].shape[1])
hs.append(allimgs[i].shape[0])
w = max(ws)
h = max(hs)
# Splice the pictures to be displayed
sub = int(order[0] * order[1] - len(imglist))
# Judge the size relationship between the input display format and the number of images to be displayed
if sub > 0:
for s in range(sub):
allimgs.append(np.zeros_like(allimgs[0]))
elif sub < 0:
allimgs = allimgs[:sub]
imgblank = np.zeros(((h+border) * order[0], (w+border) * order[1], 3)) + border_color
imgblank = imgblank.astype(np.uint8)
for i in range(order[0]):
for j in range(order[1]):
imgblank[(i * h + i*border):((i + 1) * h+i*border), (j * w + j*border):((j + 1) * w + j*border), :] = allimgs[i * order[1] + j]
return imgblank
if __name__ == '__main__':
image = cv2.imread('lena.jpg')
img = show_multi_imgs(0.9, [image, image, image, image, image, image], (2, 3))
cv2.namedWindow('multi', 0)
cv2.imshow('multi', img)
cv2.waitKey(0)
3 The test results
The test results are shown in the following figure :
More 3D 、 Please pay attention to two-dimensional perception algorithm and financial quantitative analysis algorithm “ Lele perception school ” WeChat official account , And will continue to update .
copyright notice
author[Coding leaves],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/175/202206240628079145.html
The sidebar is recommended
- Writing sample code for functions in Python
- Summary of operation methods of Python set (about 20 operation methods), with sample code attached
- Python -- functions
- Anonymous and recursive functions in Python
- How to query the methods (member functions) of a class or an object in Python [using the function dir()]
- Summary of operation methods of Python Dictionary (dict) (about 18 operation methods), with sample code attached
- Collect hot search lists in Python at work, which can be called a fishing artifact
- Running Django and Vue on docker
- Data classification in pandas
- About Python: docxtpl is embedded by default when inserting pictures
guess what you like
How to solve the problem of CSV? (Language Python)
Installation and use of redis (Python)
Python implements sending mail (implements single / group mail verification code)
On the built-in object type of Python -- number (one of the differences between py2 and PY3)
Python God uses a problem to help you solve the problems of formal and actual parameters in Python functions
"Project Euler Python Mini tutorial" 001-010 solution introduction
Most beginners learn Python and web automation. In this way, they learn and give up
Python matrices and numpy arrays
Exciting challenge: Python crawler crawls the cover picture of station B
After installing python3, use the yum command to report an error?
Random recommended
- New features of python3.6, 3.7, 3.8 and 3.9
- Application of Python simplehttpserver
- Python sending mail (single / group) - yagmail module
- After learning these English words, mom doesn't have to worry that I can't learn Python any more
- 1-python+ selenium automated test (detailed tutorial) in the series of exercises of "teach you by hand"
- Cannot unmarshal array into go value of type main
- Analysis of the principle of Python import
- Python quickly saves pictures in wechat official account articles (multiple articles can be specified)
- Python error reporting series (14) -- selenium support for phantom JS has been deprecated
- Python variable data type
- Advanced Python Programming - functions and modules
- Python conditional judgment and loop statements
- Python dictionary nesting
- I want to use Python to write a census management software. I want to ask about the ideas and software involved
- I want to use Python to write a census management software. I want to consult the ideas and software involved.
- Python program has no idea
- How to set the initial position of the cursor in Python Tkinter
- The scrapy framework only gets a set of results. I don't know why (Language Python)
- Code problems in Python
- Python automation framework
- Vscode - offline extension installation tutorial (take Python plug-in installation as an example)
- _ What are the application scenarios in Python
- Python writing yaml file
- On the strange phenomenon of Python objects
- System learning Python -- unit test unittest: Test Report
- Learn Python in this way, and the boss licks back the resume in the trash can: 25K per month
- Guess the age of American mathematician Wiener
- Python machine learning day03
- Random seed()
- Programming science | you may be wrong about Python
- Is Python really worth learning
- What is the charm of python, which is warmly pursued by countless programmers?
- Python is popular for several reasons: These data tell you
- Picture to character drawing in Python, so easy!
- Data type conversion in pandas module
- Python Basics - (1) overview of Python
- Data Science Library Python -- learning of time series data
- Django project - error reporting
- [run the script framework in Django and store the data in the database]
- Complete Python exception handling in ten minutes