File size: 851 Bytes
328aad1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from PIL import Image
import os

# Function to create a list of cars with their images
def create_car_list(image_folder):
    car_list = []
    for image_name in os.listdir(image_folder):
        if image_name.endswith(('.png', '.jpg', '.jpeg')):
            car_name = os.path.splitext(image_name)[0]  # Extract the car name from the image file name
            image_path = os.path.join(image_folder, image_name)
            car_image = Image.open(image_path)
            
            car_list.append({
                'name': car_name,
                'image': car_image
            })
    
    return car_list

# Example usage
image_folder = 'path/to/your/car/images'
car_list = create_car_list(image_folder)

# Displaying the cars' names and showing their images
for car in car_list:
    print(f"Car Name: {car['name']}")
    car['image'].show()