Spaces:
Running
Running
ocr updated
Browse files
Layoutlmv3_inference/ocr.py
CHANGED
@@ -63,11 +63,7 @@ def enhance_txt(img, intensity_increase=20, bilateral_filter_diameter=9, bilater
|
|
63 |
# Convert image to grayscale
|
64 |
grayscale_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
65 |
|
66 |
-
#
|
67 |
-
contours, _ = cv2.findContours(
|
68 |
-
grayscale_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
69 |
-
|
70 |
-
# # Apply Gaussian blur
|
71 |
blurred = cv2.GaussianBlur(grayscale_img, (1, 1), 0)
|
72 |
|
73 |
edged = 255 - cv2.Canny(blurred, 100, 150, apertureSize=7)
|
@@ -76,8 +72,7 @@ def enhance_txt(img, intensity_increase=20, bilateral_filter_diameter=9, bilater
|
|
76 |
img = np.clip(img + intensity_increase, 0, 255).astype(np.uint8)
|
77 |
|
78 |
# Apply bilateral filter to reduce noise
|
79 |
-
img = cv2.bilateralFilter(img, bilateral_filter_diameter,
|
80 |
-
bilateral_filter_sigma_color, bilateral_filter_sigma_space)
|
81 |
|
82 |
_, binary = cv2.threshold(blurred, threshold, 255, cv2.THRESH_BINARY)
|
83 |
return binary
|
|
|
63 |
# Convert image to grayscale
|
64 |
grayscale_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
65 |
|
66 |
+
# Apply Gaussian blur
|
|
|
|
|
|
|
|
|
67 |
blurred = cv2.GaussianBlur(grayscale_img, (1, 1), 0)
|
68 |
|
69 |
edged = 255 - cv2.Canny(blurred, 100, 150, apertureSize=7)
|
|
|
72 |
img = np.clip(img + intensity_increase, 0, 255).astype(np.uint8)
|
73 |
|
74 |
# Apply bilateral filter to reduce noise
|
75 |
+
img = cv2.bilateralFilter(img, bilateral_filter_diameter, bilateral_filter_sigma_color, bilateral_filter_sigma_space)
|
|
|
76 |
|
77 |
_, binary = cv2.threshold(blurred, threshold, 255, cv2.THRESH_BINARY)
|
78 |
return binary
|