Spaces:
Running
Running
File size: 1,272 Bytes
74c6580 a8d57c0 29b171e 74c6580 a8d57c0 74c6580 a8d57c0 74c6580 29b171e 74c6580 29b171e 74c6580 29b171e 74c6580 a8d57c0 b555fe0 a8d57c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import os
import gradio as gr
from PIL import Image
import pytesseract
import yolov5
# load model
model = yolov5.load('keremberke/yolov5m-license-plate')
# set model parameters
model.conf = 0.5 # NMS confidence threshold
model.iou = 0.25 # NMS IoU threshold
model.agnostic = False # NMS class-agnostic
model.multi_label = False # NMS multiple labels per box
model.max_det = 1000 # maximum number of detections per image
def license_plate_detect(img):
results = model(img, size=640)
# parse results
if len(results.pred):
predictions = results.pred[0]
boxes = predictions[:, :4] # x1, y1, x2, y2
return boxes
def read_license_number(img):
boxes = license_plate_detect(img)
if len(boxes[0]):
image = Image.fromarray(img)
return [pytesseract.image_to_string(
image.crop(bbox.tolist()))
for bbox in boxes]
def greet(img):
boxes = license_plate_detect(img)
image = Image.fromarray(img)
r = 'greet'
if len(boxes[0]):
r = [pytesseract.image_to_string(
image.crop(bbox.tolist()))
for bbox in boxes]
return "Hello " + str(r) + "!!"
iface = gr.Interface(fn=greet, inputs="image", outputs="text")
iface.launch() |