4

我想在左侧显示原始图像,在右侧显示灰度图像。下面是我的代码,我创建灰度图像并创建窗口,但我无法将灰度图像放在右侧。我怎样才能做到这一点?

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()
4

2 回答 2

8

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

于 2019-09-04T16:06:10.350 回答
1

据我所知,一个窗口,一个图像。所以用imgW*2创建一个新图像,并在从(originalimage.width,0)开始的区域复制灰度图像的内容。ROI 功能可能对您有所帮助。

于 2013-03-05T10:31:59.993 回答