我在这里做的是对一个图像进行编码,然后将其添加到一个列表中,其中包含数据库变量中原始图像的路径,如下所示
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")