leo-bourrel commited on
Commit
58ddda3
·
1 Parent(s): 9195caf

feat: set back add_image_to_folder to yolo

Browse files
src/data_models/image_manager.py CHANGED
@@ -98,32 +98,3 @@ class ImageManager:
98
  def close_connection(self):
99
  """Close the connection."""
100
  self.session.close()
101
-
102
-
103
- def add_image_to_db(result, image_manager, park_id):
104
- """
105
- Adds an image to the database.
106
-
107
- Args:
108
- result: YOLO result object containing the image details.
109
- image_manager (ImageManager): Instance of ImageManager to interact with the database.
110
- park_id (int): The ID of the associated park.
111
-
112
- Returns:
113
- int: The ID of the added image.
114
- """
115
- image_name = result.path.split("/")[-1]
116
- current_datetime = datetime.now()
117
- created_at = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
118
-
119
- try:
120
- print(f"Adding image '{image_name}' to the database...")
121
- image = image_manager.add_image(
122
- name=image_name, created_at=created_at, park_id=park_id
123
- )
124
- image_id = image_manager.get_image_id(image_name)
125
- print(f"Image '{image_name}' added with ID: {image_id}")
126
- return image_id
127
- except Exception as e:
128
- print(f"Error adding image '{image_name}' to the database: {e}")
129
- return None
 
98
  def close_connection(self):
99
  """Close the connection."""
100
  self.session.close()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/yolo_predictions.py CHANGED
@@ -1,9 +1,44 @@
 
 
1
  from data_models.bbox_manager import BoundingBoxManager, add_bboxes_to_db
2
- from data_models.image_manager import ImageManager, add_image_to_db
3
- from data_models.park_manager import ParkManager
4
  from ultralytics import YOLO
5
 
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def load_model(model_file):
8
  """
9
  Load the YOLO model.
 
1
+ from datetime import datetime
2
+
3
  from data_models.bbox_manager import BoundingBoxManager, add_bboxes_to_db
4
+ from data_models.image_manager import ImageManager
 
5
  from ultralytics import YOLO
6
 
7
 
8
+ model = None
9
+ bbox_manager = BoundingBoxManager()
10
+ image_manager = ImageManager()
11
+
12
+
13
+ def add_image_to_db(result, image_manager, park_id):
14
+ """
15
+ Adds an image to the database.
16
+
17
+ Args:
18
+ result: YOLO result object containing the image details.
19
+ image_manager (ImageManager): Instance of ImageManager to interact with the database.
20
+ park_id (int): The ID of the associated park.
21
+
22
+ Returns:
23
+ int: The ID of the added image.
24
+ """
25
+ image_name = result.path.split("/")[-1]
26
+ current_datetime = datetime.now()
27
+ created_at = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
28
+
29
+ try:
30
+ print(f"Adding image '{image_name}' to the database...")
31
+ image = image_manager.add_image(
32
+ name=image_name, created_at=created_at, park_id=park_id
33
+ )
34
+ image_id = image_manager.get_image_id(image_name)
35
+ print(f"Image '{image_name}' added with ID: {image_id}")
36
+ return image_id
37
+ except Exception as e:
38
+ print(f"Error adding image '{image_name}' to the database: {e}")
39
+ return None
40
+
41
+
42
  def load_model(model_file):
43
  """
44
  Load the YOLO model.