Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,30 @@ recog_interpreter.allocate_tensors()
|
|
17 |
input_details = interpreter.get_input_details()
|
18 |
output_details = interpreter.get_output_details()
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def execute_text_recognition_tflite( boxes, frame, interpreter, input_details, output_details):
|
23 |
x1, x2, y1, y2 = boxes[1], boxes[3], boxes[0], boxes[2]
|
@@ -56,6 +79,9 @@ def execute_text_recognition_tflite( boxes, frame, interpreter, input_details, o
|
|
56 |
return text,cv2.resize(save_frame,(94,24))
|
57 |
|
58 |
def greet(image):
|
|
|
|
|
|
|
59 |
resized = cv2.resize(image, (320,320), interpolation=cv2.INTER_LINEAR)
|
60 |
input_data = resized.astype(np.float32) # Set as 3D RGB float array
|
61 |
input_data /= 255. # Normalize
|
|
|
17 |
input_details = interpreter.get_input_details()
|
18 |
output_details = interpreter.get_output_details()
|
19 |
|
20 |
+
|
21 |
+
def unsharp_mask(image, kernel_size=(5, 5), sigma=1.0, amount=1.0, threshold=0):
|
22 |
+
"""Return a sharpened version of the image, using an unsharp mask."""
|
23 |
+
blurred = cv2.GaussianBlur(image, kernel_size, sigma)
|
24 |
+
sharpened = float(amount + 1) * image - float(amount) * blurred
|
25 |
+
sharpened = np.maximum(sharpened, np.zeros(sharpened.shape))
|
26 |
+
sharpened = np.minimum(sharpened, 255 * np.ones(sharpened.shape))
|
27 |
+
sharpened = sharpened.round().astype(np.uint8)
|
28 |
+
if threshold > 0:
|
29 |
+
low_contrast_mask = np.absolute(image - blurred) < threshold
|
30 |
+
np.copyto(sharpened, image, where=low_contrast_mask)
|
31 |
+
return sharpened
|
32 |
+
|
33 |
+
def increase_brightness(img, value):
|
34 |
+
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
35 |
+
h, s, v = cv2.split(hsv)
|
36 |
+
|
37 |
+
lim = 255 - value
|
38 |
+
v[v > lim] = 255
|
39 |
+
v[v <= lim] += value
|
40 |
+
|
41 |
+
final_hsv = cv2.merge((h, s, v))
|
42 |
+
img = cv2.cvtColor(final_hsv, cv2.COLOR_HSV2BGR)
|
43 |
+
return img
|
44 |
|
45 |
def execute_text_recognition_tflite( boxes, frame, interpreter, input_details, output_details):
|
46 |
x1, x2, y1, y2 = boxes[1], boxes[3], boxes[0], boxes[2]
|
|
|
79 |
return text,cv2.resize(save_frame,(94,24))
|
80 |
|
81 |
def greet(image):
|
82 |
+
sharpened = unsharp_mask(image)
|
83 |
+
image = increase_brightness(sharpened, value=10) # 60 ->5qoOk.png #10 -> if8nC.png
|
84 |
+
|
85 |
resized = cv2.resize(image, (320,320), interpolation=cv2.INTER_LINEAR)
|
86 |
input_data = resized.astype(np.float32) # Set as 3D RGB float array
|
87 |
input_data /= 255. # Normalize
|