Spaces:
Runtime error
Runtime error
Update services/crack_detection_service.py
Browse files
services/crack_detection_service.py
CHANGED
@@ -8,11 +8,11 @@ def detect_cracks_and_holes(frame):
|
|
8 |
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
|
9 |
|
10 |
# Edge detection using Canny
|
11 |
-
edges = cv2.Canny(blurred,
|
12 |
|
13 |
# Morphological operations to enhance cracks and holes
|
14 |
kernel = np.ones((3, 3), np.uint8)
|
15 |
-
dilated = cv2.dilate(edges, kernel, iterations=
|
16 |
eroded = cv2.erode(dilated, kernel, iterations=1)
|
17 |
|
18 |
# Find contours
|
@@ -22,7 +22,7 @@ def detect_cracks_and_holes(frame):
|
|
22 |
for contour in contours:
|
23 |
# Filter small contours (noise)
|
24 |
area = cv2.contourArea(contour)
|
25 |
-
if area <
|
26 |
continue
|
27 |
|
28 |
# Get bounding box
|
@@ -35,22 +35,22 @@ def detect_cracks_and_holes(frame):
|
|
35 |
circularity = 4 * np.pi * area / (perimeter * perimeter) if perimeter > 0 else 0
|
36 |
|
37 |
# Classify as crack or hole
|
38 |
-
if 0.
|
39 |
item_type = 'crack'
|
40 |
# Check if it's an underlying crack (longer and thinner)
|
41 |
-
if aspect_ratio >
|
42 |
severity = 'Underlying'
|
43 |
-
elif area >
|
44 |
severity = 'Severe'
|
45 |
-
elif area >
|
46 |
severity = 'Moderate'
|
47 |
else:
|
48 |
severity = 'Minor'
|
49 |
-
elif circularity > 0.
|
50 |
item_type = 'hole'
|
51 |
-
if area >
|
52 |
severity = 'Severe'
|
53 |
-
elif area >
|
54 |
severity = 'Moderate'
|
55 |
else:
|
56 |
severity = 'Minor'
|
|
|
8 |
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
|
9 |
|
10 |
# Edge detection using Canny
|
11 |
+
edges = cv2.Canny(blurred, 30, 100) # Lower thresholds to detect more cracks
|
12 |
|
13 |
# Morphological operations to enhance cracks and holes
|
14 |
kernel = np.ones((3, 3), np.uint8)
|
15 |
+
dilated = cv2.dilate(edges, kernel, iterations=2)
|
16 |
eroded = cv2.erode(dilated, kernel, iterations=1)
|
17 |
|
18 |
# Find contours
|
|
|
22 |
for contour in contours:
|
23 |
# Filter small contours (noise)
|
24 |
area = cv2.contourArea(contour)
|
25 |
+
if area < 30: # Reduced threshold to catch smaller cracks
|
26 |
continue
|
27 |
|
28 |
# Get bounding box
|
|
|
35 |
circularity = 4 * np.pi * area / (perimeter * perimeter) if perimeter > 0 else 0
|
36 |
|
37 |
# Classify as crack or hole
|
38 |
+
if 0.05 < aspect_ratio < 20 and circularity < 0.4: # Adjusted for more crack detection
|
39 |
item_type = 'crack'
|
40 |
# Check if it's an underlying crack (longer and thinner)
|
41 |
+
if aspect_ratio > 8:
|
42 |
severity = 'Underlying'
|
43 |
+
elif area > 4000:
|
44 |
severity = 'Severe'
|
45 |
+
elif area > 800:
|
46 |
severity = 'Moderate'
|
47 |
else:
|
48 |
severity = 'Minor'
|
49 |
+
elif circularity > 0.6: # Circular shapes are holes
|
50 |
item_type = 'hole'
|
51 |
+
if area > 4000:
|
52 |
severity = 'Severe'
|
53 |
+
elif area > 800:
|
54 |
severity = 'Moderate'
|
55 |
else:
|
56 |
severity = 'Minor'
|