How do I make an inverse filled transparent rectangle with OpenCV?

前端 未结 2 842
耶瑟儿~
耶瑟儿~ 2021-01-19 04:39

I want to make an inverse filled rectangle in this picture.

The code I have:

import cv2

lena = cv2.imread(\'lena.png\')

output = lena.copy         


        
2条回答
  •  既然无缘
    2021-01-19 05:33

    Here's what I would do:

    # initialize output
    output = np.zeros_like(lena, dtype=np.uint8)
    output[:,:,-1] = 255
    
    # this is your box top_x
    tx,ly,bx,ry = 100,100,200,200
    
    # copy lena to output
    output[tx:bx,ly:ry] = lena[tx:bx,ly:ry]
    
    cv2.addWeighted(lena, 0.5, output, 1 - .5, 0, output);
    

    OUtput:

提交回复
热议问题