lokesh341 commited on
Commit
8f53b3b
·
1 Parent(s): 5ba778e

Update services/crack_detection_service.py

Browse files
Files changed (1) hide show
  1. services/crack_detection_service.py +10 -10
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, 50, 150)
12
 
13
  # Morphological operations to enhance cracks and holes
14
  kernel = np.ones((3, 3), np.uint8)
15
- dilated = cv2.dilate(edges, kernel, iterations=1)
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 < 50:
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.1 < aspect_ratio < 10 and circularity < 0.5: # Long, thin shapes are cracks
39
  item_type = 'crack'
40
  # Check if it's an underlying crack (longer and thinner)
41
- if aspect_ratio > 5:
42
  severity = 'Underlying'
43
- elif area > 5000:
44
  severity = 'Severe'
45
- elif area > 1000:
46
  severity = 'Moderate'
47
  else:
48
  severity = 'Minor'
49
- elif circularity > 0.7: # Circular shapes are holes
50
  item_type = 'hole'
51
- if area > 5000:
52
  severity = 'Severe'
53
- elif area > 1000:
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'