AMMICO/ammico/objects.py
GwydionJon 44e5a987b1
Improve documentation (#89)
* updated documentation in cropposts

* updated documentation in display

* updated documentation in faces

* added comments to objects.py

* updated utils.py docs

* updated text.py docs

* improve doc display

* fix doc for display and remove redundant variable

* removed documentation from cropposts.py

* removed unused imports

* get rid of ipywidgets dependency

* remove unused imports, improve type hints

* improve doc in utils

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Inga Ulusoy <inga.ulusoy@uni-heidelberg.de>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-14 22:17:20 +02:00

55 строки
1.6 KiB
Python

from ammico.utils import AnalysisMethod
from ammico.objects_cvlib import ObjectCVLib
from ammico.objects_cvlib import init_default_objects
class ObjectDetectorClient(AnalysisMethod):
def __init__(self):
# The detector is set to CVLib by default
self.detector = ObjectCVLib()
def set_client_to_cvlib(self):
"""Set the object detection client to use CVLib."""
self.detector = ObjectCVLib()
def analyse_image(self, subdict=None):
"""Localize objects in the given image.
Args:
subdict (dict): The dictionary for an image expression instance.
Returns:
dict: The updated dictionary with object detection results.
"""
return self.detector.analyse_image(subdict)
class ObjectDetector(AnalysisMethod):
od_client = ObjectDetectorClient()
def __init__(self, subdict: dict):
super().__init__(subdict)
self.subdict.update(self.set_keys())
def set_keys(self):
"""Set the default object keys for analysis.
Returns:
dict: The dictionary with default object keys.
"""
return init_default_objects()
def analyse_image(self):
"""Perform object detection on the image.
Returns:
dict: The updated dictionary with object detection results.
"""
self.subdict = ObjectDetector.od_client.analyse_image(self.subdict)
return self.subdict
@staticmethod
def set_client_to_cvlib():
"""Set the object detection client to use CVLib."""
ObjectDetector.od_client.set_client_to_cvlib()