npc0 commited on
Commit
74c6580
1 Parent(s): c96a2eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -1,4 +1,7 @@
 
1
  import gradio as gr
 
 
2
  import yolov5
3
 
4
  # load model
@@ -11,10 +14,30 @@ model.agnostic = False # NMS class-agnostic
11
  model.multi_label = False # NMS multiple labels per box
12
  model.max_det = 1000 # maximum number of detections per image
13
 
14
- def greet(img):
15
  results = model(img, size=640)
16
 
17
- return "Hello " + str(results.pred) + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  iface = gr.Interface(fn=greet, inputs="image", outputs="text")
20
  iface.launch()
 
1
+ import os
2
  import gradio as gr
3
+ from PIL import Image
4
+ import pytesseract
5
  import yolov5
6
 
7
  # load model
 
14
  model.multi_label = False # NMS multiple labels per box
15
  model.max_det = 1000 # maximum number of detections per image
16
 
17
+ def license_plate_detect(img):
18
  results = model(img, size=640)
19
 
20
+ # parse results
21
+ if len(results.pred):
22
+ predictions = results.pred[0]
23
+ boxes = predictions[:, :4] # x1, y1, x2, y2
24
+ return boxes
25
+
26
+
27
+ def read_license_number(img):
28
+ boxes = license_plate_detect(img)
29
+ if len(boxes[0]):
30
+ return [pytesseract.image_to_string(
31
+ Image.crop(bbox.tolist()))
32
+ for bbox in boxes]
33
+
34
+
35
+ def greet(img):
36
+ boxes = license_plate_detect(img)
37
+ return "Hello " + str([pytesseract.image_to_string(
38
+ Image.crop(bbox.tolist()))
39
+ for bbox in boxes]) + "!!"
40
+
41
 
42
  iface = gr.Interface(fn=greet, inputs="image", outputs="text")
43
  iface.launch()