Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show multiple images in same window with Python OpenCV?

I want to display original image left side and grayscale image on right side. Below is my code, I create grayscale image and create window, but I couldn't put grayscale image to right side. How can I do this?

import cv
import time
from PIL import Image
import sys

filePath = raw_input("file path: ")
filename = filePath

img = cv.LoadImage(filename)
imgGrayScale = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_GRAYSCALE) # create grayscale image

imgW = img.width
imgH = img.height

cv.NamedWindow("title", cv.CV_WINDOW_AUTOSIZE)
cv.ShowImage("title", img )
cv.ResizeWindow("title", imgW * 2, imgH)

cv.WaitKey()
like image 721
vtokmak Avatar asked Jan 15 '23 01:01

vtokmak


1 Answers

First concatenate the images either horizontally (across columns) or vertically (across rows) and then display it as a single image.

import numpy as np
import cv2
from skimage.data import astronaut
import scipy.misc as misc
img=cv2.cvtColor(astronaut(),cv2.COLOR_BGR2RGB)
numpy_horizontal_concat = np.concatenate((img, img), axis=1)
cv2.imshow('Numpy Horizontal Concat', numpy_horizontal_concat)

enter image description here

like image 121
Khan Avatar answered Jan 31 '23 02:01

Khan