Home > Software design >  Adding images from a file to a dictionary
Adding images from a file to a dictionary

Time:12-06

I am trying to add files to a dictionary.

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
}

Please ignore the first half of the code, it was one of my many failed attempts. I am trying to get all the images in one file into the dictionary. I have over 700 files so it is not possible to manually type them all. Is there a way to do this?

CodePudding user response:

I think you wanted to do the following:

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
}

But glob.glob it return a list already, so you can do:

queries = glob.glob('/content/drive/MyDrive/AI_FACIAL/QUERY/*.jpeg')
frames = glob.glob('/content/drive/MyDrive/AI_FACIAL/frames/*.png')
  • Related