Esempio n. 1
0
class CameraProcessingModule:
    def __init__(self):
        self.yolo = YoloExecutor()
        self.stream_processor = StreamProcessor(operation='add')

    def get_detections(self) -> dict:
        #   Launches the intelligent inventory collection
        self.stream_processor.process_stream()
        input_frame = Image.open('add_image.jpg')
        self.yolo.get_labels(input_frame)

        return self.yolo.post_process_stream()
Esempio n. 2
0
def start_stream(lan, hashtag):
    # This handles Twitter authentication and the connection to Twitter Streaming API
    processor = StreamProcessor(stream_name=__stream_name__,
                                storage_name=__s3_bucket_name__)
    processor.create_processor()

    l = Listener(stream_processor=processor)
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, l)

    # This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
    print("Start filtering... language : " + lan + " hashtag : " + hashtag)
    stream.filter(languages=[lan], track=[hashtag])
def test_processor_statistics() -> None:
    # Given range of 30 numbers and mapping function that append 'prime' flag
    numbers = range(30)

    # When I run the processor with 'only_primes' generator passed in
    processor = StreamProcessor(numbers, is_prime, only_primes)

    # And calculate the prime stream statistics
    raw, stats = itertools.tee(processor)
    calculated_stats = list(zip(raw, streaming_statistics(stats)))

    # Then I should see correct statistics along side the prime numbers
    expected_stats = [(2, {
        'mean': None,
        'std': None
    }), (3, {
        'mean': 2.5,
        'std': 0.7071067811865476
    }), (5, {
        'mean': 3.3333333333333335,
        'std': 1.5275252316519465
    }), (7, {
        'mean': 4.25,
        'std': 2.217355782608345
    }), (11, {
        'mean': 5.6,
        'std': 3.5777087639996634
    }), (13, {
        'mean': 6.833333333333333,
        'std': 4.400757510550504
    }), (17, {
        'mean': 8.285714285714286,
        'std': 5.55920515044749
    }), (19, {
        'mean': 9.625,
        'std': 6.3905622377288305
    }), (23, {
        'mean': 11.11111111111111,
        'std': 7.457285773732365
    }), (29, {
        'mean': 12.9,
        'std': 9.024041962077378
    })]

    for calculated, expected in zip(calculated_stats, expected_stats):
        assert calculated[0] == expected[0]
        if calculated[0] > 2 and expected[0] > 2:
            assert calculated[1]['mean'] - expected[1][
                'mean'] == pytest.approx(0)
            assert calculated[1]['std'] - expected[1]['std'] == pytest.approx(
                0)
Esempio n. 4
0
def __setup_processors():
    """
    Instantiates and schedules three stream processors for execution in localhost.
    :return the instantiated stream processors.
    """
    processors = {}
    for processor_id in [
            'standalone-processor-1', 'standalone-processor-2',
            'standalone-processor-3'
    ]:
        processors[processor_id] = StreamProcessor(host_name='localhost',
                                                   processor_id=processor_id)
        processors[processor_id].start()
    return processors
def test_only_primes_reduce_generator() -> None:
    # Given range of 100 numbers and mapping function that append 'prime' flag
    numbers = range(100)

    # When I run the processor with 'only_primes' generator passed in
    processor = StreamProcessor(numbers, is_prime, only_primes)

    # Then I should be able to slide 10 items from the result
    slice = list(itertools.islice(processor, 10))
    assert len(slice) == 10

    # And list of the slice should have 10 integers, each being a prime number
    for prime in slice:
        assert is_prime(prime)[0]
def test_processor_with_prime_mapper() -> None:
    # Given range of 100 numbers and mapping function that append 'prime' flag
    numbers = range(100)

    # When I run the processor
    processor = StreamProcessor(numbers, is_prime)

    # Then I should be able to slide 10 items from the result
    slice = list(itertools.islice(processor, 10))
    assert len(slice) == 10

    # And list of the slice should have 10 Tuples with boolean flag and the number as first and second items, respectively
    for item in list(slice):
        assert isinstance(item, tuple)
        assert isinstance(item[0], bool)
        assert isinstance(item[1], int)
Esempio n. 7
0
    def run(self):
        """ Main Challenge method. Has to exist and is the
            start point for the threaded challenge. """
        # Startup sequence
        if self.core_module is None:
            # Initialise GPIO
            GPIO.setwarnings(False)
            GPIO.setmode(GPIO.BCM)

            # Instantiate CORE / Chassis module and store in the launcher.
            self.core_module = core.Core(GPIO)
            # Limit motor speeds in AutoMode
            self.core_module.set_speed_factor(0.6)  # 0.6 on old motors
            self.core_module.enable_motors(True)

        # wait for the user to enable motors
        while not self.core_module.motors_enabled():
            time.sleep(0.25)

        # Load our previously learned arena colour order
        self.camera = picamera.PiCamera()
        self.processor = StreamProcessor(self.core_module, self.camera)
        print('Wait ...')
        time.sleep(2)

        filename = "arenacolours.txt"
        if os.path.isfile(filename):
            with open(filename) as f:
                content = f.readlines()
            if len(content) > 0:
                self.processor.arenacolours = [x.strip() for x in content]
                self.processor.state = State.ORIENTING
            f.close()

        # Setup the camera
        frameRate = 30  # Camera image capture frame rate
        self.camera.resolution = (self.processor.imageWidth,
                                  self.processor.imageHeight)
        self.camera.framerate = frameRate
        self.camera.awb_mode = 'off'

        # Load the exposure calibration
        redgain = 1.5  # Default Gain values
        bluegain = 1.5
        filename = "rbgains.txt"
        if os.path.isfile(filename):
            with open(filename) as f:
                content = f.readlines()
            content = [x.strip() for x in content]
            redgain = float(content[0][2:])
            bluegain = float(content[1][2:])
            f.close()
        self.camera.awb_gains = (redgain, bluegain)

        self.captureThread = ImageCapture(self.camera, self.processor)

        try:
            # Loop indefinitely until we are no longer running
            while self.processor.state != State.FINISHED:
                # Wait for the interval period
                #
                time.sleep(0.1)
        except KeyboardInterrupt:
            print("User shutdown\n")
        except Exception as e:
            print(e)

        self.core_module.enable_motors(False)
        self.processor.state = State.FINISHED
        self.captureThread.join()
        self.processor.terminated = True
        self.processor.join()
        self.camera.close()  # Ensure camera is release
        # del self.camera
        self.camera = None
        print("Challenge terminated")
Esempio n. 8
0
class Rainbow:
    def __init__(self, core_module, oled):
        """Class Constructor"""
        self.killed = False
        self.core_module = core_module
        self.ticks = 0
        self.oled = oled
        self.camera = None
        self.captureThread = None

    def show_state(self):
        """ Show motor/aux config on OLED display """
        if self.oled is not None:
            # Format the speed to 2dp
            if self.core_module and self.core_module.motors_enabled():
                message = "Rainbow: %0.2f" % (
                    self.core_module.get_speed_factor())
            else:
                message = "Rainbow: NEUTRAL"

            self.oled.cls()  # Clear Screen
            self.oled.canvas.text((10, 10), message, fill=1)
            # Now show the mesasge on the screen
            self.oled.display()

    def stop(self):
        """Simple method to stop the RC loop"""
        self.killed = True
        if self.processor:
            self.processor.state = State.FINISHED
        if self.captureThread:
            self.captureThread.stop()

    def run(self):
        """ Main Challenge method. Has to exist and is the
            start point for the threaded challenge. """
        # Startup sequence
        if self.core_module is None:
            # Initialise GPIO
            GPIO.setwarnings(False)
            GPIO.setmode(GPIO.BCM)

            # Instantiate CORE / Chassis module and store in the launcher.
            self.core_module = core.Core(GPIO)
            # Limit motor speeds in AutoMode
            self.core_module.set_speed_factor(0.6)  # 0.6 on old motors
            self.core_module.enable_motors(True)

        # wait for the user to enable motors
        while not self.core_module.motors_enabled():
            time.sleep(0.25)

        # Load our previously learned arena colour order
        self.camera = picamera.PiCamera()
        self.processor = StreamProcessor(self.core_module, self.camera)
        print('Wait ...')
        time.sleep(2)

        filename = "arenacolours.txt"
        if os.path.isfile(filename):
            with open(filename) as f:
                content = f.readlines()
            if len(content) > 0:
                self.processor.arenacolours = [x.strip() for x in content]
                self.processor.state = State.ORIENTING
            f.close()

        # Setup the camera
        frameRate = 30  # Camera image capture frame rate
        self.camera.resolution = (self.processor.imageWidth,
                                  self.processor.imageHeight)
        self.camera.framerate = frameRate
        self.camera.awb_mode = 'off'

        # Load the exposure calibration
        redgain = 1.5  # Default Gain values
        bluegain = 1.5
        filename = "rbgains.txt"
        if os.path.isfile(filename):
            with open(filename) as f:
                content = f.readlines()
            content = [x.strip() for x in content]
            redgain = float(content[0][2:])
            bluegain = float(content[1][2:])
            f.close()
        self.camera.awb_gains = (redgain, bluegain)

        self.captureThread = ImageCapture(self.camera, self.processor)

        try:
            # Loop indefinitely until we are no longer running
            while self.processor.state != State.FINISHED:
                # Wait for the interval period
                #
                time.sleep(0.1)
        except KeyboardInterrupt:
            print("User shutdown\n")
        except Exception as e:
            print(e)

        self.core_module.enable_motors(False)
        self.processor.state = State.FINISHED
        self.captureThread.join()
        self.processor.terminated = True
        self.processor.join()
        self.camera.close()  # Ensure camera is release
        # del self.camera
        self.camera = None
        print("Challenge terminated")
Esempio n. 9
0
 def __init__(self):
     self.yolo = YoloExecutor()
     self.stream_processor = StreamProcessor(operation='add')