예제 #1
0
def setup_devices():
    ipcon = IPConnection()  # Create IP connection
    stepper = SilentStepper(STEPPER_UID, ipcon)  # Create device object

    # ir
    ti = BrickletThermalImaging(IR_UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd

    # setup ir
    ti.set_image_transfer_config(ti.IMAGE_TRANSFER_MANUAL_TEMPERATURE_IMAGE)
    ti.set_resolution(BrickletThermalImaging.RESOLUTION_0_TO_655_KELVIN)
    # Don't use device before ipcon is connected

    stepper.set_motor_current(800)  # 800 mA
    stepper.set_step_configuration(stepper.STEP_RESOLUTION_1,
                                   True)  # 1/8 steps (interpolated)
    stepper.set_max_velocity(2000)  # Velocity 2000 steps/s

    # Slow acceleration (500 steps/s^2),
    # Fast deacceleration (5000 steps/s^2)
    stepper.set_speed_ramping(500, 5000)
    stepper.enable()
    return stepper, ti
    def super_loop(self):
        global ultimaFecha, images_queues, temperatures_queues, final_images, logging

        images_queues = LifoQueue()
        temperatures_queues = LifoQueue()

        ipconn = IPConnection()
        ipconn.connect(HOST, PORT)

        ti = BrickletThermalImaging(UID, ipconn)
        ti.set_resolution(ti.RESOLUTION_0_TO_655_KELVIN)
        ti.register_callback(ti.CALLBACK_HIGH_CONTRAST_IMAGE,
                             callback_image_constrant)
        ti.register_callback(ti.CALLBACK_TEMPERATURE_IMAGE,
                             callback_image_temperature)

        indexImage = 0

        while True:
            try:
                ultimaFecha = datetime.datetime.now()
                ti.set_image_transfer_config(
                    ti.IMAGE_TRANSFER_CALLBACK_HIGH_CONTRAST_IMAGE)
                image_queue = images_queues.get(True)
                #logging.debug(image_queue)
                ti.set_image_transfer_config(
                    ti.IMAGE_TRANSFER_CALLBACK_TEMPERATURE_IMAGE)
                temperatures = temperatures_queues.get(True)
                #logging.debug(temperatures)
                ti.set_image_transfer_config(
                    ti.IMAGE_TRANSFER_MANUAL_HIGH_CONTRAST_IMAGE)

                with images_queues.mutex as iq, temperatures_queues.mutex as tq:
                    images_queues.queue.clear()
                    temperatures_queues.queue.clear()

                if image_queue is not None:
                    image.putdata(image_queue)
                    img = np.asarray(image.convert())
                    img = cv2.rotate(img, cv2.ROTATE_180)
                    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
                    #cv2.imwrite("data/"+str(indexImage)+"_a.png", img)
                    img = cv2.flip(img, 1)
                    #cv2.imwrite("data/" + str(indexImage) + "_b.png", img)
                    #indexImage += 1

                    positions = detector.detect_face(img)
                    if len(positions) > 0:
                        img = fever.draw_temperatures(temperatures, positions,
                                                      img)
                    else:
                        img = cv2.resize(img, (800, 600))

                    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

                    final_images.put(img)

            except Exception as ex:
                print(ex)
            finally:
                # logging.debug("Main: Ventana actualizada")
                pass