-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsee_ellipses.py
51 lines (42 loc) · 1.92 KB
/
see_ellipses.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
41
42
43
44
45
46
47
48
49
50
51
decision = input("X. Make only the image in PARAMETERS.py\n2. Make ALL images in real_imgs\n-> ")
from ultralytics import YOLO as Yolo
from os import path, listdir, remove, mkdir
import cv2
from PARAMETERS import TEST_IMAGE, IMGSZ, CONFIDENCE, MAX_DETECT
from data_management.get_boxes import get_boxes
import imageio.v2 as imageio
def numerically(string : str):
number = ""
for character in string:
if character in "0123456789":
number += character
return int(number)
if not path.exists(path.join("imgs", "results")):
mkdir(path.join("imgs", "results"))
if decision == "2":
image_paths = [path.join("imgs", "real_imgs", f)
for f in listdir(path.join("imgs", "real_imgs"))
if path.isfile(path.join("imgs", "real_imgs", f))]
else:
image_paths = [path.join("imgs", "real_imgs", TEST_IMAGE)]
for image_path in image_paths:
image_name = image_path.split("\\")[-1]
output_dir = path.join("imgs", "results", image_name.split(".")[0])
if not path.exists(output_dir):
mkdir(output_dir)
weights_dir = "weights"
weights_paths = [path.join(weights_dir, f) for f in listdir(weights_dir) if path.isfile(path.join(weights_dir, f))]
weights_paths = sorted(weights_paths, key=numerically)
final_images_paths = []
for weight in weights_paths:
model = Yolo(weight)
results = model.predict(image_path, imgsz = IMGSZ, conf=CONFIDENCE, max_det=MAX_DETECT, verbose=False)
img = cv2.imread(image_path)
output_path = get_boxes(results, img, image_name, weight)
final_images_paths.append(output_path)
frames = [imageio.imread(image_file) for image_file in final_images_paths]
frames.append(frames[-1])
frames.append(frames[-1])
imageio.mimsave(path.join(output_dir, "history.gif"), frames, duration=len(weights_paths)*90, loop=0)
for image_path in final_images_paths[:-1]:
remove(image_path)