简体   繁体   中英

Combine more than 1 openCV images and show them in CV2.Imshow() in OpenCV Python

I am having 3 to 4 images and I am trying to combine them all into one image (put into one window) and then show them through CV2.imshow() function. But the problem is that every solution to this problem is for exactly the same dimension images, which is not my case. My images are all of different dimensions. Kindly help me out how to solve this problem? I have four images with different dimension and want output like this

|||||||||||||||||||||||||||||||||

|| Image1 || Image2 ||

||||||||||||||||||||||||||||||||||

|| Image1 || Image2 ||

||||||||||||||||||||||||||||||||||

Currently, I have code like this for two images which work on only equally sized Images

im = cv2.imread('1.png')
img = cv2.imread('2.jpg')
both = np.hstack((im,im))
cv2.imshow('imgc',both)
cv2.waitKey(10000)

Use im.resize() function of opencv to resize the image and then do the combining task. Always use a reference dimension such as 1000 x 800 (you can change it)

import cv2

import numpy as np

list_of_img_paths = [path2,path3,path4]

im = cv2.imread(path1)

imstack = cv2.resize(im,(1000,800))

for path in list_of_img_paths:
    im = cv2.imread(path)
    im = cv2.resize(im,(1000,800))
    imstack = np.hstack(imstack,im)

cv2.imshow('stack',imstack)
cv2.waitKey(0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM