SamiKhokhar commited on
Commit
865d375
·
verified ·
1 Parent(s): 65f7d8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -15,7 +15,7 @@ reader = easyocr.Reader(['en'])
15
  # Directory to save images of non-helmet riders
16
  os.makedirs("non_helmet_riders", exist_ok=True)
17
 
18
- # Function to enhance the image for better number plate recognition
19
  def preprocess_image_for_ocr(image):
20
  gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
21
  _, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
@@ -27,13 +27,13 @@ def detect_non_helmet_and_plate(image):
27
  results = model(image)
28
 
29
  helmet_status = "Pass"
30
- license_plate_text = "I can't detect image"
31
  license_plate_image = None
32
-
33
  non_helmet_detected = False
 
34
  for *xyxy, conf, cls in results.xyxy[0]:
35
  class_id = int(cls)
36
- if class_id == 0: # Class 0 is 'person' in YOLOv5s
37
  non_helmet_detected = True
38
  helmet_status = "Fail"
39
  cv2.rectangle(img_np, (int(xyxy[0]), int(xyxy[1])),
 
15
  # Directory to save images of non-helmet riders
16
  os.makedirs("non_helmet_riders", exist_ok=True)
17
 
18
+ # Function to preprocess image for better OCR performance
19
  def preprocess_image_for_ocr(image):
20
  gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
21
  _, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
 
27
  results = model(image)
28
 
29
  helmet_status = "Pass"
30
+ license_plate_text = "No license plate detected"
31
  license_plate_image = None
 
32
  non_helmet_detected = False
33
+
34
  for *xyxy, conf, cls in results.xyxy[0]:
35
  class_id = int(cls)
36
+ if class_id == 0: # Class 0 is 'person'
37
  non_helmet_detected = True
38
  helmet_status = "Fail"
39
  cv2.rectangle(img_np, (int(xyxy[0]), int(xyxy[1])),