Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,25 +6,25 @@ from openai import OpenAI
|
|
| 6 |
|
| 7 |
# Image Preprocessing Function
|
| 8 |
def preprocess_image(image_path):
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Apply
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
| 25 |
|
| 26 |
# Return the preprocessed image
|
| 27 |
-
return
|
| 28 |
|
| 29 |
# Function to encode the image to base64
|
| 30 |
def encode_image(image_file):
|
|
|
|
| 6 |
|
| 7 |
# Image Preprocessing Function
|
| 8 |
def preprocess_image(image_path):
|
| 9 |
+
# Convert the file to an OpenCV image
|
| 10 |
+
file_bytes = np.asarray(bytearray(image_file.read()), dtype=np.uint8)
|
| 11 |
+
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
| 12 |
+
|
| 13 |
+
# Resize the image, if necessary
|
| 14 |
+
# image = cv2.resize(image, (desired_width, desired_height))
|
| 15 |
+
|
| 16 |
+
# Convert to grayscale
|
| 17 |
+
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 18 |
+
|
| 19 |
+
# Apply Gaussian blur to reduce noise and improve OCR accuracy
|
| 20 |
+
blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0)
|
| 21 |
+
|
| 22 |
+
# Adaptive Histogram Equalization
|
| 23 |
+
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
|
| 24 |
+
equalized_image = clahe.apply(blurred_image)
|
| 25 |
|
| 26 |
# Return the preprocessed image
|
| 27 |
+
return image_path
|
| 28 |
|
| 29 |
# Function to encode the image to base64
|
| 30 |
def encode_image(image_file):
|