shamimjony1000 commited on
Commit
e3a2ad8
·
1 Parent(s): 0e01414

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -22,16 +22,13 @@ def detect_objects_on_image(image_path):
22
  results = model.predict(image_path)
23
  result = results[0]
24
  output = []
 
25
  for box in result.boxes:
26
- x1, y1, x2, y2 = [
27
- round(x) for x in box.xyxy[0].tolist()
28
-
29
- ]
30
  class_id = box.cls[0].item()
31
  prob = round(box.conf[0].item(), 2)
32
- output.append([
33
- x1, y1, x2, y2, result.names[class_id], prob
34
- ])
35
  cv2.rectangle(
36
  image,
37
  (x1, y1),
@@ -40,10 +37,15 @@ def detect_objects_on_image(image_path):
40
  thickness=2,
41
  lineType=cv2.LINE_AA
42
  )
43
-
44
- cv2.putText(image,result.names[class_id], (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (36,255,12), 2)
 
 
 
 
45
  return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
46
 
 
47
  inputs_image = [
48
  gr.components.Image(type="filepath", label="Input Image"),
49
  ]
 
22
  results = model.predict(image_path)
23
  result = results[0]
24
  output = []
25
+
26
  for box in result.boxes:
27
+ x1, y1, x2, y2 = [round(x) for x in box.xyxy[0].tolist()]
 
 
 
28
  class_id = box.cls[0].item()
29
  prob = round(box.conf[0].item(), 2)
30
+ output.append([x1, y1, x2, y2, result.names[class_id], prob])
31
+
 
32
  cv2.rectangle(
33
  image,
34
  (x1, y1),
 
37
  thickness=2,
38
  lineType=cv2.LINE_AA
39
  )
40
+
41
+ # Change font and size
42
+ font = cv2.FONT_HERSHEY_SIMPLEX
43
+ font_size = 0.5 # Adjust the font size as needed
44
+ cv2.putText(image, result.names[class_id], (x1, y1), font, font_size, (36, 255, 12), 1)
45
+
46
  return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
47
 
48
+
49
  inputs_image = [
50
  gr.components.Image(type="filepath", label="Input Image"),
51
  ]