Not too long ago, I wanted so as to add a white background to a few photographs with a clear background. Naturally, I used Python with OpenCV to automate the method, I wasn’t going to open a picture editor for every of those photographs. On my first try at implementing this, I didn’t fairly succeed and needed to iterate, so I believed I might share the method with you.
If you wish to observe alongside, make certain to put in the opencv-python and numpy package deal in your native Python surroundings. You should use the next clear picture of an equation for experimentation, you possibly can obtain it from right here.
Load Picture with Alpha Channel
In a primary step, we have to load the clear picture together with the alpha channel. If we load the picture usually with cv2.imread with out the required parameter, it can simply ignore the alpha channel and the picture can be fully black on this case.
img = cv2.imread("equation.png")cv2.imshow("Picture", img)
cv2.waitKey(0)
cv2.destroyAllWindows()