在字典中存储和检索图像-python

var*_*lla 1 python dictionary image-processing

谁能告诉我如何将图像存储在字典中,以及如何根据键值从字典中检索图像。

提前致谢!

Ray*_*ger 5

最好将图像存储在文件中,然后使用文件名引用它们:

pictures = {'mary': '001.jpg', 'bob', '002.jpg'}
filename = pictures['mary']
with open(filename. 'rb') as f:
    image = f.read()
Run Code Online (Sandbox Code Playgroud)

也就是说,如果您要将图像直接存储在字典中,只需添加它们即可:

pictures = {}

with open('001.jpg', 'rb') as f:
     image = f.read()
pictures['mary'] = image
Run Code Online (Sandbox Code Playgroud)

图像并不特殊,它们只是数据。