File size: 1,582 Bytes
a90ebdc
 
3029115
a90ebdc
 
 
 
 
319a527
 
 
 
69fa2c9
319a527
3029115
 
319a527
 
a90ebdc
 
 
 
 
 
 
3029115
 
 
 
319a527
3029115
319a527
3029115
 
 
 
 
 
 
 
 
319a527
 
3029115
319a527
 
3029115
 
 
 
a90ebdc
 
3029115
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
49
50
51
52
53
54
import gradio as gr
from paddleocr import PaddleOCR
from PIL import Image, ImageOps
import numpy as np

# Initialize PaddleOCR
ocr = PaddleOCR(use_angle_cls=True, lang='en')

# Function to process captured images
def process_image(image, camera_type="rear"):
    if image is None:
        return "No image captured."

    # Flip the image horizontally for the rear camera
    if camera_type == "rear":
        image = ImageOps.mirror(image)
    
    # Perform OCR on the corrected image
    result = ocr.ocr(np.array(image))
    extracted_text = []
    for line in result[0]:
        extracted_text.append(line[1][0])
    return "\n".join(extracted_text)

# Gradio Interface
def create_app():
    with gr.Blocks() as app:
        gr.Markdown("## OCR Processor with Rear Camera Fix")
        
        # Inputs for image capture and camera type selection
        with gr.Row():
            image_input = gr.Image(type="pil", label="Capture Image")  # For image capture
            camera_type = gr.Dropdown(
                choices=["rear", "front"],
                value="rear",
                label="Camera Type"
            )
        
        # Output for extracted text
        extracted_text = gr.Textbox(label="Extracted Text")
        
        # Button to process the captured image
        process_button = gr.Button("Process Image")
        process_button.click(
            fn=process_image,
            inputs=[image_input, camera_type],
            outputs=extracted_text
        )
        
    return app

if __name__ == "__main__":
    create_app().launch(share=True)