简体   繁体   中英

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 

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM