我正在尝试向字典中添加文件。
query = []
for image in glob.glob('/content/drive/MyDrive/AI_FACIAL/QUERY/*.jpeg'):
query = image.append()
for image in glob.glob('/content/drive/MyDrive/AI_FACIAL/frames/*.png'):
frames = image.append()
id = {
"Ali": [query], #Query images from person 1
"Frames": [frames] #the extracted frames
}
请忽略代码的前半部分,这是我多次失败的尝试之一。我试图得到所有的图像在一个文件到字典。我有超过700个文件,所以不可能手动输入它们。有办法做到这一点吗?
我认为你想做以下事情:
queries = []
for image in glob.glob('/content/drive/MyDrive/AI_FACIAL/QUERY/*.jpeg'):
queries.append(image) #append to the list queries
frames = []
for frame in glob.glob('/content/drive/MyDrive/AI_FACIAL/frames/*.png'):
frames.append(frame) #append to the list frames
id = {
"Ali": queries[0], #Query images from person 1
"Frames": frames[0] #the extracted frames
}
但是glob.glob
已经返回了一个列表,所以你可以这样做:
queries = glob.glob('/content/drive/MyDrive/AI_FACIAL/QUERY/*.jpeg')
frames = glob.glob('/content/drive/MyDrive/AI_FACIAL/frames/*.png')