January 2018
Intermediate to advanced
268 pages
6h 20m
English
Due to the use of overlay images, we should keep in mind that a layer might be built on black pixels, which will produce an undesired effect on the outcome of our code. Aiming to avoid that problem, the following code removes the alpha channel layer from your overlay images, and therefore allows us to obtain good results on the sample codes we have in this chapter:
import numpy as np import cv2 def remove_alpha_channel(source, background_color): source_img = cv2.cvtColor(source[:,:,:3], cv2.COLOR_BGR2GRAY) source_mask = source[:,:,3] * (1 / 255.0) bg_part = (255 * (1 / 255.0)) * (1.0 - source_mask) weight = (source_img * (1 / 255.0)) * (source_mask) dest = np.uint8(cv2.addWeighted(bg_part, ...
Read now
Unlock full access