class App(object):
    """
    Facade object to manage detectors, image capture devices and
    OpenCV display's manager.
    Source can be either a number or an IP adress where IPWebcam is connected

    """

    def __init__(self, source,
                 epoch_size = 10, detectors = None,
                 storage_handler = None, display = False):


        if "." in source and ":" in source:
            self.cap = WifiCapturer(source)
        else:
            self.cap = cv2.VideoCapture(int(source))

        self.detectors = [] or detectors
        self.storage_handler = storage_handler
        self.epoch_size = epoch_size
        self.display = display


    def run(self, source = 0):
        # TODO: run asyncronously
        i = 0
        entities = []
        try:
            while True:
                # Capture frame-by-frame
                ret, im = self.cap.read()
                if not ret:
                    break

                if i % self.epoch_size == 0:
                    if self.detectors:
                        entities = sum(
                            [d.scan(im) for d in self.detectors], []
                        )

                for ent in entities:

                    if self.storage_handler is not None:
                        self.storage_handler.handle(ent)

                    if self.display:
                        ent.draw(im)


                cv2.imshow('frame',im)
                entities = []
                if cv2.waitKey(1) & 0xFF == ord('q'):
                    break
                sys.stdout.flush() ## avoid holding the print
                i += 1
        finally:
            # When everything done, release the capture
            self.cap.release()
            cv2.destroyAllWindows()
Beispiel #2
0
class App(object):
    """
    Facade object to manage detectors, image capture devices and
    OpenCV display's manager.
    Source can be either a number or an IP adress where IPWebcam is connected

    """
    def __init__(self,
                 source,
                 epoch_size=10,
                 detectors=None,
                 storage_handler=None,
                 display=False):

        if "." in source and ":" in source:
            self.cap = WifiCapturer(source)
        else:
            self.cap = cv2.VideoCapture(int(source))

        self.detectors = [] or detectors
        self.storage_handler = storage_handler
        self.epoch_size = epoch_size
        self.display = display

    def run(self, source=0):
        # TODO: run asyncronously
        i = 0
        entities = []
        try:
            while True:
                # Capture frame-by-frame
                ret, im = self.cap.read()
                if not ret:
                    break

                if i % self.epoch_size == 0:
                    if self.detectors:
                        entities = sum([d.scan(im) for d in self.detectors],
                                       [])

                for ent in entities:

                    if self.storage_handler is not None:
                        self.storage_handler.handle(ent)

                    if self.display:
                        ent.draw(im)

                cv2.imshow('frame', im)
                entities = []
                if cv2.waitKey(1) & 0xFF == ord('q'):
                    break
                sys.stdout.flush()  ## avoid holding the print
                i += 1
        finally:
            # When everything done, release the capture
            self.cap.release()
            cv2.destroyAllWindows()
Beispiel #3
0
    def __init__(self,
                 source,
                 epoch_size=10,
                 detectors=None,
                 storage_handler=None,
                 display=False):

        if "." in source and ":" in source:
            self.cap = WifiCapturer(source)
        else:
            self.cap = cv2.VideoCapture(int(source))

        self.detectors = [] or detectors
        self.storage_handler = storage_handler
        self.epoch_size = epoch_size
        self.display = display
    def __init__(self, source,
                 epoch_size = 10, detectors = None,
                 storage_handler = None, display = False):


        if "." in source and ":" in source:
            self.cap = WifiCapturer(source)
        else:
            self.cap = cv2.VideoCapture(int(source))

        self.detectors = [] or detectors
        self.storage_handler = storage_handler
        self.epoch_size = epoch_size
        self.display = display