DHEIVER commited on
Commit
5a3b5bc
1 Parent(s): 23fe0a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
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
- # Adicione espa莽o para o r贸tulo de previs茫o na parte inferior da imagem
53
- output_image = cv2.copyMakeBorder(output_image, 0, 50, 0, 0, cv2.BORDER_CONSTANT, value=(255, 255, 255))
54
 
55
- # Desenhe um ret芒ngulo branco como fundo para o r贸tulo
56
  label_background = np.ones((50, output_image.shape[1], 3), dtype=np.uint8) * 255
57
 
58
- # Coloque o texto do r贸tulo e a caixa dentro do fundo branco
59
  output_image[-50:] = label_background
60
 
61
- # Escreva o r贸tulo de previs茫o na imagem
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
- # Calcule as coordenadas para centralizar a caixa azul no centro da imagem
68
- image_height, image_width, _ = output_image.shape
69
- box_size = 100 # Tamanho da caixa azul (ajuste conforme necess谩rio)
70
- box_x = (image_width - box_size) // 2
71
- box_y = (image_height - box_size) // 2
72
 
73
- # Desenhe uma caixa de identifica莽茫o de objeto (ret芒ngulo azul) centralizada
74
- object_box_color = (255, 0, 0) # Azul (BGR)
 
 
 
 
 
 
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