从OpenCV到PIL的转换不准确 [英] Conversion from OpenCV to PIL is not accurate

查看:255
本文介绍了从OpenCV到PIL的转换不准确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将图像从PIL转换为OpenCV时,颜色会略有变化.

When I convert an image from PIL to OpenCV, colors change slightly.

from PIL import Image
import cv2
import numpy as np
image = cv2.imread('1.jpg')
image1=Image.open('1.jpg')
image1 = cv2.cvtColor(np.array(image1), cv2.COLOR_RGB2BGR)
print(image[79])
print(image1[79])

前四行是:

[144 151 148]
[101 108 105]
[121 128 125]
[108 118 112]

[140 152 146]
[ 97 109 103]
[117 129 123]
[104 118 112]

我认为索引可能会偏离一个,但事实并非如此.有没有办法来解决这个问题? 这是图片(但其他图片也一样):

I thought the indexing may be off by one but it isn't. Is there a way to fix this? This is the image (but it's the same on others too):

推荐答案

这表明PIL和OpenCV使用的libjpeg版本不同或具有不同的参数.同样,如果您不要求OpenCV不尝试使用libjpeg-turbo,请参阅此处的代码:

That suggests PIL and OpenCV are using different versions of libjpeg or using it with different parameters. Also it seems OpenCV tries to use libjpeg-turbo if you don't ask it not to do so, see the code here: https://github.com/opencv/opencv/blob/master/cmake/OpenCVFindLibsGrfmt.cmake#L39

这篇关于从OpenCV到PIL的转换不准确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆