# Path: navigation/ObjectDetector.py
# class ObjectDetector(metaclass=abc.ABCMeta):
#     def __init__(self):
#         self._detected = False
#         self._circle_coordonates = None
# 
#     @abc.abstractmethod
#     def process(self, image):
#         pass
# 
#     @property
#     def detected(self):
#         return self._detected
# 
#     @property
#     def circle_coordonates(self):
#         return self._circle_coordonates
# 
#     @detected.setter
#     def detected(self, value):
#         self._detected = value
# 
#     @circle_coordonates.setter
#     def circle_coordonates(self, value):
#         self._circle_coordonates = value
# 
# Path: navigation/FaceRecognitionProcessWrapper.py
# class FaceRecognitionProcessWrapper:
#     QUEUE_SIZE = 2
# 
#     def __init__(self, face_recognition: FaceRecognition, nr_threads: int) -> None:
#         self.__face_recognition = face_recognition
#         self.__nr_threads = nr_threads
#         self.__input_queue = None
#         self.__output_queue = None
# 
#     def start(self):
#         self.__input_queue = Queue(maxsize=self.QUEUE_SIZE)
#         self.__output_queue = Queue(maxsize=self.QUEUE_SIZE)
#         process = FaceRecognitionProcess(self.__face_recognition, self.__input_queue, self.__output_queue)
#         process.daemon = True
#         process.start()
# 
#     def put_image(self, image):
#         self.__empty_input_queue()
#         try:
#             self.__input_queue.put(image, block=False)
#         except:
#             pass
# 
#     def get_result(self) -> tuple:
#         if self.__output_queue.qsize() > 0:
#             try:
#                 return self.__output_queue.get(block=False)
#             except:
#                 return None, None
# 
#         return None, None
# 
#     def __empty_input_queue(self):
#         while not self.__input_queue.empty():
#             try:
#                 self.__input_queue.get(block=False)
#             except:
#                 return


import cv2
from navigation.ObjectDetector import ObjectDetector
from navigation.FaceRecognitionProcessWrapper import FaceRecognitionProcessWrapper
        self.__tracker = None
        self.__face_recognition = face_recognition
        super().__init__()

    def process(self, image):
        self.detected = False
        self.__face_recognition.put_image(image)
        original_image, coordonates = self.__face_recognition.get_result()
        if original_image is not None:
            x, y, x1, y1 = coordonates
            if not hasattr(cv2, 'TrackerCSRT_create') or not callable(getattr(cv2, 'TrackerCSRT_create')):
                self.circle_coordonates = self.__get_center_radius((x, y, x1, y1))
                self.detected = True
                return
            self.__tracker = cv2.TrackerCSRT_create()
            self.__tracker.init(original_image, (x, y, (x1 - x), abs(y1 - y)))
            return

        if self.__tracker is None:
            return

        (success, box) = self.__tracker.update(image)
        if success:
            (x, y, w, h) = [int(v) for v in box]
            self.circle_coordonates = self.__get_center_radius((x, y, x + w, y + h))
            self.detected = True

    def __get_center_radius(self, coordonates):
        left, top, right, bottom = coordonates
        center = (int(left + (right - left) / 2), int((top + (bottom - top) / 2)))

# Path: navigation/ObjectDetector.py
# class ObjectDetector(metaclass=abc.ABCMeta):
#     def __init__(self):
#         self._detected = False
#         self._circle_coordonates = None
# 
#     @abc.abstractmethod
#     def process(self, image):
#         pass
# 
#     @property
#     def detected(self):
#         return self._detected
# 
#     @property
#     def circle_coordonates(self):
#         return self._circle_coordonates
# 
#     @detected.setter
#     def detected(self, value):
#         self._detected = value
# 
#     @circle_coordonates.setter
#     def circle_coordonates(self, value):
#         self._circle_coordonates = value
# 
# Path: navigation/FaceRecognitionProcessWrapper.py
# class FaceRecognitionProcessWrapper:
#     QUEUE_SIZE = 2
# 
#     def __init__(self, face_recognition: FaceRecognition, nr_threads: int) -> None:
#         self.__face_recognition = face_recognition
#         self.__nr_threads = nr_threads
#         self.__input_queue = None
#         self.__output_queue = None
# 
#     def start(self):
#         self.__input_queue = Queue(maxsize=self.QUEUE_SIZE)
#         self.__output_queue = Queue(maxsize=self.QUEUE_SIZE)
#         process = FaceRecognitionProcess(self.__face_recognition, self.__input_queue, self.__output_queue)
#         process.daemon = True
#         process.start()
# 
#     def put_image(self, image):
#         self.__empty_input_queue()
#         try:
#             self.__input_queue.put(image, block=False)
#         except:
#             pass
# 
#     def get_result(self) -> tuple:
#         if self.__output_queue.qsize() > 0:
#             try:
#                 return self.__output_queue.get(block=False)
#             except:
#                 return None, None
# 
#         return None, None
# 
#     def __empty_input_queue(self):
#         while not self.__input_queue.empty():
#             try:
#                 self.__input_queue.get(block=False)
#             except:
#                 return


# Path: navigation/SpecificFaceDetector.py
import cv2
from navigation.ObjectDetector import ObjectDetector
from navigation.FaceRecognitionProcessWrapper import FaceRecognitionProcessWrapper

        self.__tracker = None
        self.__face_recognition = face_recognition
        super().__init__()

    def process(self, image):
        self.detected = False
        self.__face_recognition.put_image(image)
        original_image, coordonates = self.__face_recognition.get_result()
        if original_image is not None:
            x, y, x1, y1 = coordonates
            if not hasattr(cv2, 'TrackerCSRT_create') or not callable(getattr(cv2, 'TrackerCSRT_create')):
                self.circle_coordonates = self.__get_center_radius((x, y, x1, y1))
                self.detected = True
                return
            self.__tracker = cv2.TrackerCSRT_create()
            self.__tracker.init(original_image, (x, y, (x1 - x), abs(y1 - y)))
            return

        if self.__tracker is None:
            return

        (success, box) = self.__tracker.update(image)
        if success:
            (x, y, w, h) = [int(v) for v in box]
            self.circle_coordonates = self.__get_center_radius((x, y, x + w, y + h))
            self.detected = True

    def __get_center_radius(self, coordonates):
        left, top, right, bottom = coordonates
        center = (int(left + (right - left) / 2), int((top + (bottom - top) / 2)))

        radius = int((bottom - top) / 2)