wangjin2000 commited on
Commit
acc2d5c
·
verified ·
1 Parent(s): eaf05c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -73,13 +73,17 @@ def detect_objects(image_path):
73
  #return results, dicom_image
74
  return results, dicom_image, dicom_meta
75
 
76
- def draw_bounding_boxes(img, results):
77
  dets = []
78
  for (x1, y1, x2, y2), conf, cls in results:
79
- x1, y1, x2, y2, cls = map(int, [x1, y1, x2, y2, cls])
 
 
80
  conf = round(conf.detach().item(), 4)
81
  print("results in draw_bounding box:",[(x1, y1, x2, y2), conf, cls])
82
- dets.append([(x1, y1, x2, y2), conf, cls])
 
 
83
  cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 2)
84
  cv2.putText(img, f'{model.names[int(cls)]} {conf:.2f}', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (36, 255, 12), 2)
85
  return img, dets
@@ -87,7 +91,7 @@ def draw_bounding_boxes(img, results):
87
  def show_preds_image(filepath):
88
  results, img0, dicom_meta = detect_objects(filepath)
89
  img_with_boxes, results = draw_bounding_boxes(img0, results)
90
- print("In show_preds_image:Intance Number=", dicom_meta.loc[dicom_meta.Key == 'Instance Number', 'Value'].iloc[0])
91
  #return cv2.cvtColor(img_with_boxes, cv2.COLOR_BGR2RGB)
92
  return cv2.cvtColor(img_with_boxes, cv2.COLOR_BGR2RGB), results, dicom_meta
93
 
 
73
  #return results, dicom_image
74
  return results, dicom_image, dicom_meta
75
 
76
+ def draw_bounding_boxes(img, results, dicom_meta):
77
  dets = []
78
  for (x1, y1, x2, y2), conf, cls in results:
79
+ xc = x1+(x2-x1)/2
80
+ yc = y1+(y2-y1)/2
81
+ x1, y1, x2, y2, xc, yc, cls = map(int, [x1, y1, x2, y2, xc, yc, cls])
82
  conf = round(conf.detach().item(), 4)
83
  print("results in draw_bounding box:",[(x1, y1, x2, y2), conf, cls])
84
+ zc = dicom_meta.loc[dicom_meta.Key == 'Instance Number', 'Value'].iloc[0]
85
+ #dets.append([(x1, y1, x2, y2), conf, cls])
86
+ dets.append([(xc, yc, zc), conf, cls])
87
  cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 2)
88
  cv2.putText(img, f'{model.names[int(cls)]} {conf:.2f}', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (36, 255, 12), 2)
89
  return img, dets
 
91
  def show_preds_image(filepath):
92
  results, img0, dicom_meta = detect_objects(filepath)
93
  img_with_boxes, results = draw_bounding_boxes(img0, results)
94
+ #print("In show_preds_image:Intance Number=", dicom_meta.loc[dicom_meta.Key == 'Instance Number', 'Value'].iloc[0])
95
  #return cv2.cvtColor(img_with_boxes, cv2.COLOR_BGR2RGB)
96
  return cv2.cvtColor(img_with_boxes, cv2.COLOR_BGR2RGB), results, dicom_meta
97