-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
58 lines (45 loc) · 1.95 KB
/
Copy pathconfig.py
File metadata and controls
58 lines (45 loc) · 1.95 KB
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
52
53
54
55
56
57
58
#config.py
#overall system manager
import os
import cv2
# Paths
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
MODEL_DIR = os.path.join(BASE_DIR, "models")
DATA_DIR = os.path.join(BASE_DIR, "data")
TEST_IMAGE_PATH = os.path.join(DATA_DIR, "finalTest", "image_016.jpg")
LENET_MODEL_PATH = os.path.join(MODEL_DIR, "lenet5_model.h5")
YOLO_MODEL_PATH = os.path.join(MODEL_DIR, "best.pt")
PROCESSED_IMAGES_DIR = os.path.join(DATA_DIR, "processed_images")
LICENSE_PLATE_CLASS_ID = 0
MINIBUS_CLASS_ID = 1
# YOLO Detection Settings
CONFIDENCE_THRESHOLD = 0.3 # Minimum confidence for YOLO detections
IOU_THRESHOLD = 0.4 # Intersection-over-Union threshold for YOLO
# Double-line Plates
DOUBLE_LINE_PLATES = True # Enable or disable double-line plate handling
# Utility Functions
def save_results(segmented_characters, license_plate_number):
"""
Save segmented characters and recognition results to the processed images directory.
Args:
segmented_characters (list): List of segmented character images.
license_plate_number (str): Recognized license plate number.
"""
os.makedirs(PROCESSED_IMAGES_DIR, exist_ok=True)
# Save segmented characters
for idx, char_img in enumerate(segmented_characters):
char_path = os.path.join(PROCESSED_IMAGES_DIR, f"char_{idx + 1}.png")
cv2.imwrite(char_path, char_img)
# Atomic write with proper format
temp_path = os.path.join(PROCESSED_IMAGES_DIR, "temp_result.txt")
final_path = os.path.join(PROCESSED_IMAGES_DIR, "result.txt")
try:
with open(temp_path, "w", encoding="utf-8") as f:
# Write in the expected format with prefix
f.write(f"{license_plate_number}\n")
# Atomic rename to prevent partial reads
os.replace(temp_path, final_path)
except Exception as e:
if os.path.exists(temp_path):
os.remove(temp_path)
raise RuntimeError(f"Failed to save results: {str(e)}")