Update my_model/object_detection.py
Browse files
my_model/object_detection.py
CHANGED
@@ -103,14 +103,18 @@ class ObjectDetector:
|
|
103 |
# Open the image from a file path
|
104 |
with Image.open(image_input) as image:
|
105 |
return image.convert("RGB")
|
106 |
-
|
107 |
-
#
|
108 |
return Image.open(image_input).convert("RGB")
|
|
|
|
|
|
|
109 |
except Exception as e:
|
110 |
print(f"Error processing image: {e}")
|
111 |
raise
|
112 |
|
113 |
|
|
|
114 |
def detect_objects(self, image, threshold=0.4):
|
115 |
"""
|
116 |
Detect objects in the given image using the loaded model.
|
|
|
103 |
# Open the image from a file path
|
104 |
with Image.open(image_input) as image:
|
105 |
return image.convert("RGB")
|
106 |
+
elif hasattr(image_input, 'read'):
|
107 |
+
# If image_input is a file-like object, open it as an image
|
108 |
return Image.open(image_input).convert("RGB")
|
109 |
+
else:
|
110 |
+
# If image_input is already a PIL Image, just convert it
|
111 |
+
return image_input.convert("RGB")
|
112 |
except Exception as e:
|
113 |
print(f"Error processing image: {e}")
|
114 |
raise
|
115 |
|
116 |
|
117 |
+
|
118 |
def detect_objects(self, image, threshold=0.4):
|
119 |
"""
|
120 |
Detect objects in the given image using the loaded model.
|