使用opencv可以在同一窗口上显示黑白和彩色图像吗?

mvr*_*950 13 opencv window image colors grayscale

是否可以使用opencv libraray在同一窗口上显示黑白和彩色图像?如何在同一窗口上同时显示这两种图像?

Abi*_*n K 34

fraxel的答案解决了旧的cv界面的问题.我想用cv2接口来展示它,只是为了理解这在新的cv2模块中是如何容易的.(可能对未来的访客有帮助).以下是代码:

import cv2
import numpy as np

im = cv2.imread('kick.jpg')
img = cv2.imread('kick.jpg',0)

# Convert grayscale image to 3-channel image,so that they can be stacked together    
imgc = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
both = np.hstack((im,imgc))

cv2.imshow('imgc',both)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

以下是我得到的输出:

在此输入图像描述


fra*_*xel 9

是的,这是一个例子,在评论中表达:

在此输入图像描述

import cv
#open color and b/w images
im = cv.LoadImageM('1_tree_small.jpg')
im2 = cv.LoadImageM('1_tree_small.jpg',cv.CV_LOAD_IMAGE_GRAYSCALE)
#set up our output and b/w in rgb space arrays:
bw = cv.CreateImage((im.width,im.height), cv.IPL_DEPTH_8U, 3)
new = cv.CreateImage((im.width*2,im.height), cv.IPL_DEPTH_8U, 3)
#create a b/w image in rgb space
cv.Merge(im2, im2, im2, None, bw)
#set up and add the color image to the left half of our output image
cv.SetImageROI(new, (0,0,im.width,im.height))
cv.Add(new, im, new)
#set up and add the b/w image to the right half of output image
cv.SetImageROI(new, (im.width,0,im.width,im.height))
cv.Add(new, bw, new)
cv.ResetImageROI(new)
cv.ShowImage('double', new)
cv.SaveImage('double.jpg', new)
cv.WaitKey(0)
Run Code Online (Sandbox Code Playgroud)

它在python中,但很容易转换为任何..