【问题标题】:OpenCV strip sRGB profile when imdecode image Python当imdecode图像Python时OpenCV剥离sRGB配置文件
【发布时间】:2018-11-04 19:19:52
【问题描述】:

我正在阅读从互联网上获取的图像,然后立即在 python 中读入 OpenCV,如下所示:

# read in image as bytes from page
image = page.raw_stream.read()
frame = cv2.imdecode(np.asarray(bytearray(image)), 0)

我收到了 libpng 警告:

libpng warning: iCCP: known incorrect sRGB profile

如何在读取前剥离 sRGB 配置文件?人们建议在阅读它们之前通过 png 文件上的 imagemagick 来执行此操作,但这对我来说是不可能的。有没有办法直接在python中做到这一点?

编辑:

如果我使用https://uploadfiles.io/m1w2l 的文件运行它并使用代码,我无法获得以下答案中的代码来解决我的问题:

import cv2
import numpy as np

with open('data/47.png', 'rb') as test:
   image = np.asarray(bytearray(test.read()), dtype="uint8")
   image = cv2.imdecode(image, cv2.IMREAD_COLOR)

我收到同样的警告

【问题讨论】:

  • 你能下载其中一个文件到磁盘上然后用cv2.imread阅读吗?同时发布指向这些文件之一的链接。
  • 我以前这样做过,但它显着减慢了代码必须保存和读取具有我正在处理的大量图像的文件的速度,这是其中一个文件:imgur.com/a/3w21Mrh

标签: python-3.x opencv image-processing libpng srgb


【解决方案1】:

使用urllib

import cv2
import urllib

resp = urllib.request.urlopen('https://i.imgur.com/QMPkIkZ.png')
image = np.asarray(bytearray(resp.read()), dtype="uint8")
image = cv2.imdecode(image, cv2.IMREAD_COLOR)

使用skimage

import cv2
from skimage import io

image = io.imread('https://i.imgur.com/QMPkIkZ.png')
image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA)

如果您使用 OpenCV cv2.imshow 得到一个奇怪的显示,请记住 OpenCV 不显示 alpha 通道。

【讨论】:

  • 感谢您的帮助,但我认为 imgur 实际上修复了他们服务器上的 sRGB。您能否使用此文件进行测试以及我更新问题的代码:uploadfiles.io/m1w2l 谢谢!
猜你喜欢
  • 1970-01-01
  • 2018-11-28
  • 2018-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-08
  • 1970-01-01
相关资源
最近更新 更多