my
Browse files
app.py
CHANGED
|
@@ -39,15 +39,15 @@ def calculate_iou(bbox1, bbox2):
|
|
| 39 |
return iou
|
| 40 |
|
| 41 |
|
| 42 |
-
cropped_dir = "./
|
| 43 |
if os.path.exists(cropped_dir):
|
| 44 |
shutil.rmtree(cropped_dir)
|
| 45 |
os.makedirs(cropped_dir, exist_ok=True)
|
| 46 |
|
| 47 |
-
output_dir1 = "./
|
| 48 |
-
output_dir2 = "./
|
| 49 |
-
output_dir3 = "./
|
| 50 |
-
UPLOAD_FOLDER = "./
|
| 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 = "./
|
| 92 |
-
files = os.listdir('./
|
| 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('./
|
| 99 |
-
random_image_data1 = cv2.imread('./
|
| 100 |
-
results = model(source='./
|
| 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 = "./
|
| 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 /
|
| 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(
|