When working on my beer recognition project BiBirra I’ve encountered problems loading images that had a transparent background. OpenCV by default mess this images up, and this is especially problematic when we extract SURF features from the loaded image.
The key idea is to load the image with the flag cv2.IMREAD_UNCHANGED that tells OpenCV to keep the alpha (transparency) channel. Then we save separately the alpha channel as a binary mask for latter use.
Notice that when the original image has no alpha channel the mask will be simply returned as None.
Now it is possible to correctly extract SURF features from the masked image