问题是你的图像不包含任何非零的红、绿或蓝像素,它完全是黑色的。{PNG的背景显示出黑色和透明性,这是因为它显示了透明性。在
如果你用ImageMagick的identify来观察它,你会看到:identify -verbose a.png | more
Image: a.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 203x50+0+0
Resolution: 37.79x37.79
Print size: 5.37179x1.3231
Units: PixelsPerCentimeter
Colorspace: sRGB
Type: Bilevel
Base type: Undefined
Endianess: Undefined
Depth: 8-bit
Channel depth:
Red: 1-bit
Green: 1-bit
Blue: 1-bit
Alpha: 8-bit
Channel statistics:
Pixels: 10150
Red:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: -3
skewness: 0
entropy: 0
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: -3
skewness: 0
entropy: 0
Blue:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: -3
skewness: 0
entropy: 0
Alpha:
min: 0 (0)
max: 255 (1)
mean: 16.477 (0.0646159)
standard deviation: 58.73 (0.230314)
kurtosis: 10.7342
skewness: 3.50997
entropy: 0.128008
...
...
Background color: white
...
...
答案是用cv2.IMREAD_UNCHANGED读取所有四个通道,只需使用第四个/alpha通道:
^{pr2}$
从here提取的代码。在