Пример #1
0
    def find(self):
        with self.lock:
            # Ensure tracker is not running.
            if self.thread is not None:
                return None

            # Reset.
            self.event.clear()
            self.found = False
            self.position = None
            self.center = None
            self.oculus = Oculus()

        # Locate the moving object.
        blob = None
        frame = None

        # Loop until capture.
        while blob is None and not self.event.is_set():
            mask, frame = Theia.get_foreground(self.eye, 100, self.event)

            # Check early exit condition.
            if mask is not None:
                blob = Theia.bound_blobs(mask, 1)
            else:
                return None

        # Check early exit condition.
        if blob is None:
            return None

        # Blob exists.
        bb = blob[0]

        # Initialize tracker with bounding box.
        success = self.oculus.initialize(frame, bb)

        if not success:
            logger.error('Unable to initialize tracker. Stopping Theia.')
            return None
        else:
            if not self.start_track(frame):
                return None
            else:
                return bb
Пример #2
0
class SuperTheia:
    def __init__(self):
        self.eye = Eye(Android.camera)
        self.oculus = None

        # Current status.
        self.found = False
        self.position = None
        self.center = None

        # Event and lock.
        self.event = Event()
        self.lock = Lock()

        # Start.
        self.thread = None

    def get(self):
        return self.eye.get_base64()

    def start_track(self, frame):
        with self.lock:
            if self.thread is None:
                self.thread = Thread(target=self._track)
                self.thread.start()
                return True

        return False

    def find(self):
        with self.lock:
            # Ensure tracker is not running.
            if self.thread is not None:
                return None

            # Reset.
            self.event.clear()
            self.found = False
            self.position = None
            self.center = None
            self.oculus = Oculus()

        # Locate the moving object.
        blob = None
        frame = None

        # Loop until capture.
        while blob is None and not self.event.is_set():
            mask, frame = Theia.get_foreground(self.eye, 100, self.event)

            # Check early exit condition.
            if mask is not None:
                blob = Theia.bound_blobs(mask, 1)
            else:
                return None

        # Check early exit condition.
        if blob is None:
            return None

        # Blob exists.
        bb = blob[0]

        # Initialize tracker with bounding box.
        success = self.oculus.initialize(frame, bb)

        if not success:
            logger.error('Unable to initialize tracker. Stopping Theia.')
            return None
        else:
            if not self.start_track(frame):
                return None
            else:
                return bb

    def stop(self):
        with self.lock:
            self.event.set()

            if self.thread is not None:
                self.thread.join()
                self.thread = None
                self.event.clear()
                return True

        return False

    def get_status(self):
        return self.found, self.position, self.center

    def _track(self):
        while not self.event.is_set():
            frame = self.eye.get_color_frame()
            self.found, self.position, self.center = self.oculus.track(frame)
Пример #3
0
import cv2
from cerebral import logger as l
from theia.main import Oculus, Theia
from theia.eye import Eye, Camera
from concurrent.futures import ThreadPoolExecutor
from cerebral.pack1.hippocampus import Android
from agility.main import Agility

executor = ThreadPoolExecutor(max_workers=1)

# agility = Agility(Android.robot)
camera = Camera(0, 100, 100)
eye = Eye(camera)
oculus = Oculus()

# agility.zero()

while True:
    frame = eye.get_color_frame()
    cv2.imshow("preview", frame)
    k = cv2.waitKey(1)

    if not k == -1:
        break

frame = eye.get_color_frame()
tl, br = Theia.get_rect(frame)
bb = (tl[0], tl[1], br[0] - tl[0], br[1] - tl[1])

oculus.initialize(frame, bb)