Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,29 +49,33 @@ def classify_image(input_image):
|
|
| 49 |
# Crie uma imagem composta com o r贸tulo de previs茫o
|
| 50 |
output_image = (input_image[0] * 255).astype('uint8')
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
output_image =
|
| 54 |
|
| 55 |
-
#
|
| 56 |
label_background = np.ones((50, output_image.shape[1], 3), dtype=np.uint8) * 255
|
| 57 |
|
| 58 |
-
#
|
| 59 |
output_image[-50:] = label_background
|
| 60 |
|
| 61 |
-
#
|
| 62 |
font = cv2.FONT_HERSHEY_SIMPLEX
|
| 63 |
font_scale = 0.4 # Tamanho da fonte reduzido
|
| 64 |
cv2.putText(output_image, f"Analysis Time: {current_time.strftime('%Y-%m-%d %H:%M:%S')}", (10, output_image.shape[0] - 30), font, font_scale, (0, 0, 0), 1)
|
| 65 |
cv2.putText(output_image, f"Predicted Class: {predicted_class}", (10, output_image.shape[0] - 10), font, font_scale, (0, 0, 0), 1) # Cor preta
|
| 66 |
|
| 67 |
-
#
|
| 68 |
-
|
| 69 |
-
box_size =
|
| 70 |
-
box_x = (image_width - box_size) // 2
|
| 71 |
-
box_y = (image_height - box_size) // 2
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
cv2.rectangle(output_image, (box_x, box_y), (box_x + box_size, box_y + box_size), object_box_color, 2) # Caixa centralizada
|
| 76 |
|
| 77 |
return output_image
|
|
|
|
| 49 |
# Crie uma imagem composta com o r贸tulo de previs茫o
|
| 50 |
output_image = (input_image[0] * 255).astype('uint8')
|
| 51 |
|
| 52 |
+
# Set output image dimensions to match input image
|
| 53 |
+
output_image = np.ones((input_image.shape[1], input_image.shape[2], 3), dtype=np.uint8) * 255
|
| 54 |
|
| 55 |
+
# Add space for the prediction label at the bottom of the image
|
| 56 |
label_background = np.ones((50, output_image.shape[1], 3), dtype=np.uint8) * 255
|
| 57 |
|
| 58 |
+
# Put the text label and box inside the white background
|
| 59 |
output_image[-50:] = label_background
|
| 60 |
|
| 61 |
+
# Write the prediction label on the image
|
| 62 |
font = cv2.FONT_HERSHEY_SIMPLEX
|
| 63 |
font_scale = 0.4 # Tamanho da fonte reduzido
|
| 64 |
cv2.putText(output_image, f"Analysis Time: {current_time.strftime('%Y-%m-%d %H:%M:%S')}", (10, output_image.shape[0] - 30), font, font_scale, (0, 0, 0), 1)
|
| 65 |
cv2.putText(output_image, f"Predicted Class: {predicted_class}", (10, output_image.shape[0] - 10), font, font_scale, (0, 0, 0), 1) # Cor preta
|
| 66 |
|
| 67 |
+
# Calculate the box size as a percentage of the image size
|
| 68 |
+
box_percentage = 0.1 # Adjust as needed
|
| 69 |
+
box_size = int(min(output_image.shape[1], output_image.shape[0]) * box_percentage)
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
# Calculate the box position both horizontally and vertically
|
| 72 |
+
box_x = (output_image.shape[1] - box_size) // 2
|
| 73 |
+
box_y = (output_image.shape[0] - box_size) // 2
|
| 74 |
+
|
| 75 |
+
# Color-code the object box based on the predicted class
|
| 76 |
+
object_box_color = (0, 255, 0) if predicted_class == "Normal" else (255, 0, 0) # Green for Normal, Red for Cataract
|
| 77 |
+
|
| 78 |
+
# Draw a centered object identification box (blue rectangle)
|
| 79 |
cv2.rectangle(output_image, (box_x, box_y), (box_x + box_size, box_y + box_size), object_box_color, 2) # Caixa centralizada
|
| 80 |
|
| 81 |
return output_image
|