Vishal Tewatia
Vishal Tewatia

Reputation: 75

Opencv[python] imread reads wrong color

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:

opencv_logo.png

output image:

opencv_output_logo.png

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

Answers (1)

eyllanesc
eyllanesc

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

Related Questions