def main():

    print('Human detection')

    # Turn on the LED so we know the box is ready
    leds.pattern = Pattern.breathe(1000)
    leds.update(Leds.rgb_pattern(RED))

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    with PiCamera() as camera:
        # Forced sensor mode, 1640x1232, full FoV. See:
        # https://picamera.readthedocs.io/en/release-1.13/fov.html#sensor-modes
        # This is the resolution inference run on.
        camera.sensor_mode = 4
        # Set camera to match
        camera.resolution = (1640, 1232)
        camera.framerate = 30

        with CameraInference(object_detection.model()) as inference:
            for i, result in enumerate(inference.run()):
                for i, obj in enumerate(
                        object_detection.get_objects(result, 0.3)):
                    if obj.score > 0.7 and obj.kind == 1:  # Person
                        print('Human detected #%d: %s' % (i, str(obj)))
                        x, y, width, height = obj.bounding_box
                        squirt((x + (width / 2) - (1640 / 2)) / 1640)
Exemplo n.º 2
0
 def _run(self):
     while not self._done.is_set():
         joy_score = self._joy_score.value
         if self._danger:
             self._leds.update(Leds.rgb_pattern(RED))
             self._danger = False
         elif joy_score > 0:
             self._leds.update(Leds.rgb_on(blend(JOY_COLOR, SAD_COLOR, joy_score)))
         else:
             self._leds.update(Leds.rgb_off())
def squirt(position):
    angle = math.degrees(math.atan((position / 2.9) * 2.5))
    bus.write_byte_data(slaveAddress, 2, angle)
    time.sleep(0.1)

    while bus.read_word_data(slaveAddress, 1) != 0:
        time.sleep(0.1)

    leds.update(Leds.rgb_on(RED))
    solenoid.on()
    time.sleep(1)
    solenoid.off()
    leds.update(Leds.rgb_pattern(RED))
Exemplo n.º 4
0
    leds.update(Leds.privacy_off())
    time.sleep(1)

for _ in range(3):
    print('Privacy: On (brightness=5)')
    leds.update(Leds.privacy_on(5))
    time.sleep(1)
    print('Privacy: Off')
    leds.update(Leds.privacy_off())
    time.sleep(1)

print('Set blink pattern: period=500ms (2Hz)')
leds.pattern = Pattern.blink(500)

print('RGB: Blink RED for 5 seconds')
leds.update(Leds.rgb_pattern(RED))
time.sleep(5)

print('RGB: Blink GREEN for 5 seconds')
leds.update(Leds.rgb_pattern(GREEN))
time.sleep(5)

print('RGB: Blink BLUE for 5 seconds')
leds.update(Leds.rgb_pattern(BLUE))
time.sleep(5)

print('Set breathe pattern: period=1000ms (1Hz)')
leds.pattern = Pattern.breathe(1000)

print('RGB: Breathe RED for 5 seconds')
leds.update(Leds.rgb_pattern(RED))
Exemplo n.º 5
0
camera.start_preview()

while True:
    try:
        if button.is_held is True:
            raise KeyboardInterrupt
        else:
            leds.update(Leds.rgb_on(Color.GREEN))
            button.wait_for_press()
            leds.pattern = Pattern.blink(2000)
            leds.update(Leds.privacy_on(5))
            for i in camera.capture_continuous(
                    '/home/pi/images/' +
                    'tire{timestamp:%Y-%m-%d-%H-%M-%S}.jpg'):
                print('Captured %s' % i)
                if button.is_held is True:
                    leds.pattern = Pattern.blink(300)
                    leds.update(Leds.privacy_off())
                    leds.update(Leds.rgb_pattern(Color.RED))
                    sleep(2)
                    leds.update(Leds.rgb_on(Color.GREEN))
                    break
                else:
                    leds.update(Leds.rgb_pattern(Color.WHITE))
                    sleep(2)
                    continue
    except KeyboardInterrupt:
        leds.reset()
        camera.stop_preview()
        break
Exemplo n.º 6
0
def check_mic_works():
    temp_file, temp_path = tempfile.mkstemp(suffix='.wav')
    print(temp_file, temp_path)
    os.close(temp_file)

    ah = '3fa2f6d6-d7c2-4799-b97c-8b5789f9c898'
    bh = 'df211582-f284-42ef-b676-2a0592b45783'
    ma = 'f07dce9f-0f84-43dd-85e7-592ea4a9d0e0'
    yj = '4338b960-0de8-413e-b22b-8e3630f8553f'

    headers = {
        # Request headers
        #'Content-Type': 'multipart/form-data',
        'Content-type': 'multipart/form-data',
        'Sample-Rate': '16000',
        'Ocp-Apim-Subscription-Key': 'b7a5dab14dd54627b39b00a4e0a8d051',
    }
    headers2 = {
        'Ocp-Apim-Subscription-Key': 'b7a5dab14dd54627b39b00a4e0a8d051'
    }

    params = urllib.parse.urlencode({
        # Request parameters
        'shortAudio': 'true',
    })

    #    try:
    input("When you're ready, press enter and say 'Testing, 1 2 3'...")
    print('Recording...')
    aiy.audio.record_to_wave(temp_path, RECORD_DURATION_SECONDS)

    leds = Leds()
    leds.reset()
    try:
        url = 'westus.api.cognitive.microsoft.com'
        conn = http.client.HTTPSConnection(url)
        body = open(temp_path, 'rb')
        conn.request(
            "POST",
            "/spid/v1.0/identify?identificationProfileIds=3fa2f6d6-d7c2-4799-b97c-8b5789f9c898&%s"
            % params, body, headers)
        response = conn.getresponse()
        print(response.status)
        #print(response.headers)
        #data = response.read()
        #print(data)
        print(response.headers.get("Operation-Location"))
        conn.close()
        res = 0
        print("=========================identirying...======")
        next_string = response.headers.get("Operation-Location")
        next_url = next_string[len(url) + 8:]
        while res == 0:
            time.sleep(3)
            conn = http.client.HTTPSConnection(url)
            print(next_string)

            conn.request("GET", next_url, "body", headers2)
            response = conn.getresponse()
            print(response.status)
            myres = response.read()
            my_json_res = json.loads(myres.decode())
            print(my_json_res.get("status"))
            api_status = my_json_res.get("status")
            if api_status != "running" and api_status != "notstarted":
                json_res = my_json_res.get("processingResult")
                owner = json_res.get("identifiedProfileId")
                print(owner)
                print(ah)
                if owner == ah:
                    RED = (0xff, 0x00, 0x00)
                    leds.pattern = Pattern.blink(300)
                    leds.update(Leds.rgb_pattern(RED))
                    aiy.audio.say("hello ah Hyoung")
                    time.sleep(3)
                    leds.reset()
                else:
                    aiy.audio.say("Who Are You?")
                res = 1
            conn.close()

    except Exception as e:
        print("[Errno {0}] {1}".format(e.errno, e.strerror))