File size: 849 Bytes
679c5ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2
import numpy as np
import gradio as gr
from ocr import OCR

ocr = OCR()

def visualize_img(image, boxes):
    for box in boxes:
        points = np.array(box, dtype=np.int32).reshape((-1, 1, 2))
        image = cv2.polylines(image, [points], True, (255, 0, 0), 1)
    return image

def process_ocr(input_img):
    result = ocr.ocr_image(input_img)
    boxes, txts, scores = ocr.extract_output(result)
    
    # Visualize image and boxes
    image_drawed = visualize_img(input_img, boxes)
    
    # Marger txts
    text = ' '.join([i for i in txts])
    return image_drawed, text

title = "OCR License Plate Indonesia"
css = ".image-preview {height: auto !important;}"


iface = gr.Interface(
    title   = title,
    fn      = process_ocr, 
    inputs  = [gr.Image()], 
    outputs = [gr.Image(), 'text'],
    css=css
)

iface.launch()