Reputation: 75
My question is not duplicate of OpenCV giving wrong color to colored images on loading or questions linked to above question.
I recently started learning opencv library and I am doing it in Python.
I am loading a opencv logo with white background , and doing nothing with img variable and still getting image with black background. Please explain me , what is happening.
input image:
output image:
import cv2
import numpy as np
img = cv2.imread('opencv_logo.png') // loaded a opencv logo with white background
cv2.imwrite('output_logo.png',img) // in output image , got it with black background
Upvotes: 1
Views: 1680
Reputation: 244292
The problem is that the transparency is not being read correctly, to do so you must use the flag cv2.IMREAD_UNCHANGED
:
import cv2
import numpy as np
img = cv2.imread('opencv_logo.png', cv2.IMREAD_UNCHANGED)
cv2.imwrite('output_logo.png',img)
Upvotes: 4