CloudAnts commited on
Commit
6123b04
·
1 Parent(s): a711a5f
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -39,15 +39,15 @@ def calculate_iou(bbox1, bbox2):
39
  return iou
40
 
41
 
42
- cropped_dir = "./mnt/cropped_images/"
43
  if os.path.exists(cropped_dir):
44
  shutil.rmtree(cropped_dir)
45
  os.makedirs(cropped_dir, exist_ok=True)
46
 
47
- output_dir1 = "./mnt/Folder1"
48
- output_dir2 = "./mnt/Folder2"
49
- output_dir3 = "./mnt/Folder3"
50
- UPLOAD_FOLDER = "./mnt/data1"
51
  os.makedirs(output_dir1, exist_ok=True)
52
  os.makedirs(output_dir2, exist_ok=True)
53
  os.makedirs(output_dir3, exist_ok=True)
@@ -88,20 +88,20 @@ def process_image():
88
  )
89
  bounding_box_annotator = sv.BoundingBoxAnnotator()
90
  label_annotator = sv.LabelAnnotator()
91
- image_dir = "./mnt/data1"
92
- files = os.listdir('./mnt/data1')
93
  files.sort()
94
  files = files[0:100]
95
  print(files)
96
  counter = 0
97
  for ii in files:
98
- random_image_data = cv2.imread('./mnt/data1/' + ii)
99
- random_image_data1 = cv2.imread('./mnt/data1/' + ii)
100
- results = model(source='./mnt/data1/' + ii, conf=0.07)[0]
101
  detections = sv.Detections.from_ultralytics(results)
102
  annotated_image = bounding_box_annotator.annotate(scene=random_image_data, detections=detections)
103
  annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections)
104
- save_path = "./mnt/Folder1/" + "detection" + ii
105
  cv2.imwrite(save_path, annotated_image)
106
  print(f"Annotated image saved at {save_path}")
107
  bounding_boxes = results.boxes.xyxy.cpu().numpy()
@@ -117,7 +117,7 @@ def process_image():
117
  cropped_image_path = os.path.join(cropped_dir, f"cropped_object_{i + 1}.jpg")
118
  cv2.imwrite(cropped_image_path, cropped_image)
119
  print(f"Enhanced cropped image saved at {cropped_image_path}")
120
- print(f"Checking contents of /mnt/data: {bounding_box_save_path}")
121
  print(f"Directory listing: {os.listdir('/mnt/data')}")
122
  print(f"Bounding box coordinates saved at {bounding_box_save_path}")
123
  reader = easyocr.Reader(
 
39
  return iou
40
 
41
 
42
+ cropped_dir = "./app/cropped_images/"
43
  if os.path.exists(cropped_dir):
44
  shutil.rmtree(cropped_dir)
45
  os.makedirs(cropped_dir, exist_ok=True)
46
 
47
+ output_dir1 = "./app/Folder1"
48
+ output_dir2 = "./app/Folder2"
49
+ output_dir3 = "./app/Folder3"
50
+ UPLOAD_FOLDER = "./app/data1"
51
  os.makedirs(output_dir1, exist_ok=True)
52
  os.makedirs(output_dir2, exist_ok=True)
53
  os.makedirs(output_dir3, exist_ok=True)
 
88
  )
89
  bounding_box_annotator = sv.BoundingBoxAnnotator()
90
  label_annotator = sv.LabelAnnotator()
91
+ image_dir = "./app/data1"
92
+ files = os.listdir('./app/data1')
93
  files.sort()
94
  files = files[0:100]
95
  print(files)
96
  counter = 0
97
  for ii in files:
98
+ random_image_data = cv2.imread('./app/data1/' + ii)
99
+ random_image_data1 = cv2.imread('./app/data1/' + ii)
100
+ results = model(source='./app/data1/' + ii, conf=0.07)[0]
101
  detections = sv.Detections.from_ultralytics(results)
102
  annotated_image = bounding_box_annotator.annotate(scene=random_image_data, detections=detections)
103
  annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections)
104
+ save_path = "./app/Folder1/" + "detection" + ii
105
  cv2.imwrite(save_path, annotated_image)
106
  print(f"Annotated image saved at {save_path}")
107
  bounding_boxes = results.boxes.xyxy.cpu().numpy()
 
117
  cropped_image_path = os.path.join(cropped_dir, f"cropped_object_{i + 1}.jpg")
118
  cv2.imwrite(cropped_image_path, cropped_image)
119
  print(f"Enhanced cropped image saved at {cropped_image_path}")
120
+ print(f"Checking contents of /app/data: {bounding_box_save_path}")
121
  print(f"Directory listing: {os.listdir('/mnt/data')}")
122
  print(f"Bounding box coordinates saved at {bounding_box_save_path}")
123
  reader = easyocr.Reader(