Sho*_*uri 5 c++ cimg python-imaging-library python-2.7 phash
我试图将使用PIL加载的iamge转换为Cimg图像对象.据我所知,Cimg是一个c ++库,PIL是一个python成像库.给定一个图像网址,我的目的是计算图像的pHash而不将其写入磁盘.pHash模块与Cimg图像对象一起使用,它已在C++中实现.所以我打算使用python扩展绑定将我的python程序中所需的图像数据发送到c ++程序.在下面的代码片段中,我将从给定的URL加载图像:
//python code sniplet
import PIL.Image as pil
file = StringIO(urlopen(url).read())
img = pil.open(file).convert("RGB")
Run Code Online (Sandbox Code Playgroud)
我需要构建的Cimg图像对象如下所示:
CImg ( const t *const values,
const unsigned int size_x,
const unsigned int size_y = 1,
const unsigned int size_z = 1,
const unsigned int size_c = 1,
const bool is_shared = false
)
Run Code Online (Sandbox Code Playgroud)
我可以使用img.size获取width(size_x)和height(size_y)并将其传递给c ++.我不确定如何填充Cimg对象的'values'字段?使用什么样的数据结构将图像数据从python传递到c ++代码?
另外,还有其他方法将PIL图像转换为Cimg吗?