Is it possible to have black and white and color image on same window by using opencv?

mvr950 picture mvr950 · Jun 17, 2012 · Viewed 10.4k times · Source

Is it possible to have black-and-white and color image on same window by using opencv libraray? How can I have both of these images on same window?

Answer

Abid Rahman K picture Abid Rahman K · Jun 17, 2012

fraxel's answer has solved the problem with old cv interface. I would like to show it using cv2 interface, just to understand how this easy in new cv2 module. (May be it would be helpful for future visitors). Below is the code:

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

And below is the output I got:

enter image description here