-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.py
40 lines (32 loc) · 1.23 KB
/
results.py
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
29
30
31
32
33
34
35
36
37
38
39
40
import os
import cv2
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
# Directory containing the inference results
inference_dir = '/home/agrosavia/Documents/rs_agrosavia/yolo_cocoa_2/runs/detect/train2'
# Collect all image paths with .png or .jpg extensions
paths2 = []
for dirname, _, filenames in os.walk(inference_dir):
for filename in filenames:
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
paths2.append(os.path.join(dirname, filename))
paths2 = sorted(paths2)
print(f"Total images found: {len(paths2)}")
print("Sample image paths:", paths2[:3])
# Iterate through each image and display it
for path in paths2:
try:
# Open and convert the image to RGB (in case it's in a different mode)
image = Image.open(path).convert('RGB')
image_np = np.array(image)
# Create a figure with specified size
plt.figure(figsize=(20, 10))
# Display the image
plt.imshow(image_np)
plt.axis('off') # Hide axis for better visualization
plt.title(os.path.basename(path), fontsize=15) # Optional: Add image title
# Show the plot
plt.show()
except Exception as e:
print(f"Error loading image {path}: {e}")