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

前端 未结 4 2021
南旧
南旧 2020-12-05 08:35

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?

4条回答
  •  抹茶落季
    2020-12-05 08:56

    Small improvement to the code with modern writing

    concatenate

    instead of

    hstack

    that is discontinued (stack can also be used)

    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.concatenate((im,imgc), axis=1)   #1 : horz, 0 : Vert. 
    
    cv2.imshow('imgc',both)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

提交回复
热议问题