m7mdal7aj commited on
Commit
5823810
1 Parent(s): 5df391c

Delete my_model/scratch/extract_objects.py

Browse files
Files changed (1) hide show
  1. my_model/scratch/extract_objects.py +0 -45
my_model/scratch/extract_objects.py DELETED
@@ -1,45 +0,0 @@
1
- from object_detection import ObjectDetector
2
- import os
3
-
4
- def detect_objects_for_image(image_name, detector):
5
-
6
- if os.path.exists(image_path):
7
- image = detector.process_image(image_path)
8
- detected_objects_str, _ = detector.detect_objects(image)
9
- return detected_objects_str
10
- else:
11
- return "Image not found"
12
-
13
- def add_detected_objects_to_dataframe(df, image_directory, detector):
14
- """
15
- Adds a column to the DataFrame with detected objects for each image specified in the 'image_name' column.
16
-
17
- Parameters:
18
- df (pd.DataFrame): DataFrame containing a column 'image_name' with image filenames.
19
- image_directory (str): Path to the directory containing images.
20
- detector (ObjectDetector): An instance of the ObjectDetector class.
21
-
22
- Returns:
23
- pd.DataFrame: The original DataFrame with an additional column 'detected_objects'.
24
- """
25
-
26
- # Ensure 'image_name' column exists in the DataFrame
27
- if 'image_name' not in df.columns:
28
- raise ValueError("DataFrame must contain an 'image_name' column.")
29
-
30
- image_path = os.path.join(image_directory, image_name)
31
-
32
- # Function to detect objects for a given image filename
33
-
34
-
35
- # Apply the function to each row in the DataFrame
36
- df['detected_objects'] = df['image_name'].apply(detect_objects_for_image)
37
-
38
- return df
39
-
40
- # Example usage (assuming the function will be used in a context where 'detector' is defined and configured):
41
- # df_images = pd.DataFrame({"image_name": ["image1.jpg", "image2.jpg", ...]})
42
- # image_directory = "path/to/image_directory"
43
- # updated_df = add_detected_objects_to_dataframe(df_images, image_directory, detector)
44
- # updated_df.head()
45
-