Sakibrumu commited on
Commit
581d1f5
·
verified ·
1 Parent(s): 1f93a9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -1,25 +1,20 @@
1
- import os
2
- import pytesseract
3
-
4
- # Tesseract path from environment variable
5
- pytesseract.pytesseract.tesseract_cmd = os.getenv("TESSERACT_PATH", "/usr/bin/tesseract")
6
-
7
-
8
  import gradio as gr
9
  import torch
10
  import cv2
11
- import pytesseract
12
  import numpy as np
13
  from PIL import Image
 
14
  from ultralytics import YOLO
15
 
16
-
17
  # Load model
18
  model = YOLO("/home/user/app/best.pt")
19
 
20
  # Label map
21
  label_map = {0: "Analog", 1: "Digital", 2: "Non-LP"}
22
 
 
 
 
23
  def process_frame(frame):
24
  # Resize to YOLO input shape
25
  input_img = cv2.resize(frame, (640, 640))
@@ -43,12 +38,13 @@ def process_frame(frame):
43
  cv2.putText(input_img, f"{label}: {percent}", (x1, y1 - 10),
44
  cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
45
 
46
- # OCR
47
  cropped = frame[y1:y2, x1:x2] # Use original frame for OCR
48
  if cropped.size > 0:
49
- gray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
50
- text = pytesseract.image_to_string(gray, config="--psm 6 -l ben")
51
- extracted_texts.append(text.strip())
 
52
  confidences.append(percent)
53
 
54
  # Convert to PIL
@@ -84,9 +80,7 @@ interface = gr.Interface(
84
  gr.Textbox(label="Confidence (%)")
85
  ],
86
  title="YOLOv10n License Plate Detector (Bangla)",
87
- description="Upload an image or video. Detects license plates and extracts Bangla text using OCR."
88
  )
89
 
90
  interface.launch()
91
-
92
-
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import torch
3
  import cv2
 
4
  import numpy as np
5
  from PIL import Image
6
+ from paddleocr import PaddleOCR # Import PaddleOCR
7
  from ultralytics import YOLO
8
 
 
9
  # Load model
10
  model = YOLO("/home/user/app/best.pt")
11
 
12
  # Label map
13
  label_map = {0: "Analog", 1: "Digital", 2: "Non-LP"}
14
 
15
+ # Initialize PaddleOCR (for Bangla OCR)
16
+ ocr = PaddleOCR(use_angle_cls=True, lang='bn') # For Bangla language
17
+
18
  def process_frame(frame):
19
  # Resize to YOLO input shape
20
  input_img = cv2.resize(frame, (640, 640))
 
38
  cv2.putText(input_img, f"{label}: {percent}", (x1, y1 - 10),
39
  cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
40
 
41
+ # OCR using PaddleOCR
42
  cropped = frame[y1:y2, x1:x2] # Use original frame for OCR
43
  if cropped.size > 0:
44
+ # Convert to RGB and run OCR
45
+ result = ocr.ocr(cropped, cls=True)
46
+ for line in result[0]:
47
+ extracted_texts.append(line[1]) # Get the detected text
48
  confidences.append(percent)
49
 
50
  # Convert to PIL
 
80
  gr.Textbox(label="Confidence (%)")
81
  ],
82
  title="YOLOv10n License Plate Detector (Bangla)",
83
+ description="Upload an image or video. Detects license plates and extracts Bangla text using PaddleOCR."
84
  )
85
 
86
  interface.launch()