DHEIVER commited on
Commit
17b5eb0
·
1 Parent(s): 00f8749

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -21,8 +21,8 @@ def classify_image_with_overlay(img):
21
  # Convert the numpy array image to a PIL image
22
  img_pil = Image.fromarray(img)
23
 
24
- # Predict the label
25
- label = classifier.predict_image(img=img_pil)
26
 
27
  # Load the image using OpenCV
28
  image = cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR)
@@ -33,11 +33,11 @@ def classify_image_with_overlay(img):
33
  font_scale = 1
34
  color = (255, 255, 255) # White color
35
  thickness = 2
36
- text_size = cv2.getTextSize(label, font, font_scale, thickness)[0]
37
  cv2.rectangle(image, (org[0] - 10, org[1] - text_size[1] - 10), (org[0] + text_size[0], org[1]), color, cv2.FILLED)
38
 
39
  # Put the label text on the white rectangle
40
- cv2.putText(image, label, org, font, font_scale, (0, 0, 0), thickness, cv2.LINE_AA)
41
 
42
  # Resize the image to a larger size
43
  image = cv2.resize(image, (800, 800)) # Defina o tamanho desejado aqui
 
21
  # Convert the numpy array image to a PIL image
22
  img_pil = Image.fromarray(img)
23
 
24
+ # Predict the label and probability
25
+ label, probability = classifier.predict_image(img=img_pil)
26
 
27
  # Load the image using OpenCV
28
  image = cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR)
 
33
  font_scale = 1
34
  color = (255, 255, 255) # White color
35
  thickness = 2
36
+ text_size = cv2.getTextSize(f"{label}: {probability:.2f}", font, font_scale, thickness)[0]
37
  cv2.rectangle(image, (org[0] - 10, org[1] - text_size[1] - 10), (org[0] + text_size[0], org[1]), color, cv2.FILLED)
38
 
39
  # Put the label text on the white rectangle
40
+ cv2.putText(image, f"{label}: {probability:.2f}", org, font, font_scale, (0, 0, 0), thickness, cv2.LINE_AA)
41
 
42
  # Resize the image to a larger size
43
  image = cv2.resize(image, (800, 800)) # Defina o tamanho desejado aqui