Spaces:
Runtime error
Runtime error
Update services/operations_maintenance/crack_detection.py
Browse files
services/operations_maintenance/crack_detection.py
CHANGED
@@ -6,7 +6,7 @@ import random
|
|
6 |
|
7 |
# Load YOLOv8m-seg model for crack detection
|
8 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
9 |
-
MODEL_PATH = os.path.join(BASE_DIR, "../../models/yolov8m-seg.pt")
|
10 |
model = YOLO(MODEL_PATH)
|
11 |
|
12 |
def detect_cracks_and_objects(frame):
|
@@ -21,7 +21,6 @@ def detect_cracks_and_objects(frame):
|
|
21 |
results = model(frame)
|
22 |
|
23 |
detected_items = []
|
24 |
-
line_counter = 1 # Initialize counter for numbered labels
|
25 |
|
26 |
# Process detections
|
27 |
for r in results:
|
@@ -41,11 +40,8 @@ def detect_cracks_and_objects(frame):
|
|
41 |
if label == "crack":
|
42 |
severity = random.choice(["low", "medium", "high"])
|
43 |
|
44 |
-
# Add numbered label
|
45 |
-
detection_label = f"Line {line_counter} - {label.capitalize()} (Conf: {conf:.2f})"
|
46 |
item = {
|
47 |
"type": label,
|
48 |
-
"label": detection_label,
|
49 |
"confidence": conf,
|
50 |
"coordinates": [x_min, y_min, x_max, y_max]
|
51 |
}
|
@@ -54,6 +50,4 @@ def detect_cracks_and_objects(frame):
|
|
54 |
|
55 |
detected_items.append(item)
|
56 |
|
57 |
-
line_counter += 1
|
58 |
-
|
59 |
return detected_items
|
|
|
6 |
|
7 |
# Load YOLOv8m-seg model for crack detection
|
8 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
9 |
+
MODEL_PATH = os.path.abspath(os.path.join(BASE_DIR, "../../models/yolov8m-seg.pt"))
|
10 |
model = YOLO(MODEL_PATH)
|
11 |
|
12 |
def detect_cracks_and_objects(frame):
|
|
|
21 |
results = model(frame)
|
22 |
|
23 |
detected_items = []
|
|
|
24 |
|
25 |
# Process detections
|
26 |
for r in results:
|
|
|
40 |
if label == "crack":
|
41 |
severity = random.choice(["low", "medium", "high"])
|
42 |
|
|
|
|
|
43 |
item = {
|
44 |
"type": label,
|
|
|
45 |
"confidence": conf,
|
46 |
"coordinates": [x_min, y_min, x_max, y_max]
|
47 |
}
|
|
|
50 |
|
51 |
detected_items.append(item)
|
52 |
|
|
|
|
|
53 |
return detected_items
|