Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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 = "
|
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'
|
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])),
|