Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ from PIL import Image, ImageEnhance, ImageOps
|
|
| 4 |
import torch
|
| 5 |
import re
|
| 6 |
import easyocr
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Initialize EasyOCR Reader
|
| 9 |
reader = easyocr.Reader(['en'])
|
|
@@ -31,12 +33,17 @@ def extract_details(text):
|
|
| 31 |
|
| 32 |
def extract_meter_reading(image):
|
| 33 |
try:
|
| 34 |
-
#
|
| 35 |
image = Image.fromarray(image)
|
| 36 |
enhanced_image = enhance_image(image)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Use EasyOCR to get better results
|
| 39 |
-
result = reader.readtext(
|
| 40 |
text = " ".join([item[1] for item in result])
|
| 41 |
|
| 42 |
# Extract details from the OCR text
|
|
|
|
| 4 |
import torch
|
| 5 |
import re
|
| 6 |
import easyocr
|
| 7 |
+
from io import BytesIO
|
| 8 |
+
import numpy as np
|
| 9 |
|
| 10 |
# Initialize EasyOCR Reader
|
| 11 |
reader = easyocr.Reader(['en'])
|
|
|
|
| 33 |
|
| 34 |
def extract_meter_reading(image):
|
| 35 |
try:
|
| 36 |
+
# Convert NumPy array to PIL Image
|
| 37 |
image = Image.fromarray(image)
|
| 38 |
enhanced_image = enhance_image(image)
|
| 39 |
|
| 40 |
+
# Convert PIL image to bytes for EasyOCR
|
| 41 |
+
img_byte_arr = BytesIO()
|
| 42 |
+
enhanced_image.save(img_byte_arr, format='PNG')
|
| 43 |
+
img_byte_arr = img_byte_arr.getvalue()
|
| 44 |
+
|
| 45 |
# Use EasyOCR to get better results
|
| 46 |
+
result = reader.readtext(img_byte_arr)
|
| 47 |
text = " ".join([item[1] for item in result])
|
| 48 |
|
| 49 |
# Extract details from the OCR text
|