【发布时间】:2019-02-08 04:52:01
【问题描述】:
我在这里所做的是对图像进行编码,然后将其添加到一个列表中,其中包含数据库变量中原始图像的路径,如下所示
database.append[path, encoding]
然后我想将此数据库变量保存到 pickle 中以供其他程序使用。我该怎么做呢,因为我还没有正确保存文件的运气。 任何帮助,将不胜感激。 这是我用来生成要保存的变量的方法
def embedDatabase(imagePath, model, metadata):
#Get the metadata
#Perform embedding
# calculated by feeding the aligned and scaled images into the pre-trained network.
'''
#Go through the database and get the embedding for each image
'''
database = []
embedded = np.zeros((metadata.shape[0], 128))
print("Embedding")
for i, m in enumerate(metadata):
img = imgUtil.loadImage(m.image_path())
_,img = imgUtil.alignImage(img)
# scale RGB values to interval [0,1]
if img is not None:
img = (img / 255.).astype(np.float32)
#Get the embedding vectors for the image
embedded[i] = model.predict(np.expand_dims(img, axis=0))[0]
database.append([m.image_path(), embedded[i]])
#return the array of embedded images from the database
return embedded, database
这是加载图片的方法
def loadImage(path):
img = cv2.imread(path, 1)
if img is not None:
# OpenCV loads images with color channels
# in BGR order. So we need to reverse them
return img[...,::-1]
else:
pass
print("There is no Image avaliable")
【问题讨论】:
-
我很困惑。我看不到问题。并且标题谈到了 Pickle,但没有与 Pickle 相关的代码。问题是您要保存不是数据库的数据库。请在您的问题下单击
edit并澄清事情。谢谢。 -
好的,我重做了,希望这能阐明我想要做什么。
标签: python-3.x image-processing pickle opencv3.0