I have a folder with about 10,000 images, I have a huge *.txt
file as follows. The txt file has 30,000 lines. Each image has three lines, line (1) contains the image name for example "04406_8_074402.jpeg". Line (2) contains the image category, in this case, it is a cat, and --- to separate that information from the next line. It contains image file name/ path and image category:
for example:
Analysing Image: /path to image folder/images/04406_8_074402.jpeg
Object Class Presented: cat
----------------------------------
Analysing Image: /path to image folder/images/00009_8_071203.jpeg
Object Class Presented: dog
----------------------------------
Analysing Image: /path to image folder/images/04440_8_045244.jpeg
Object Class Presented: box
----------------------------------
Analysing Image: /path to image folder/images/00045_8_051505.jpeg
Object Class Presented: unclassified
.
.
.
.
.
----------------------------------
Analysing Image: /path to image folder/images/02290_8_073302.jpeg
Object Class Presented: panda
----------------------------------
I need to categorize those images into different folders based on their class names. I know I can read the txt file using:
with open('file.txt') as f:
line = f.readline()
while line:
line = f.readline()
print(line)
My question is how do I put those images into different folders based on their class names?