Esempio n. 1
0
        def center_on_blob(b, res):
            mapped_cx, mapped_cy = get_mapped_centroid(b)

            # Switch to the res (if res was unchanged this does nothing).
            sensor.set_framesize(res)

            # Construct readout window. x/y are offsets from the center.
            x = int(mapped_cx - (sensor_w / 2.0))
            y = int(mapped_cy - (sensor_h / 2.0))
            w = sensor.width()
            h = sensor.height()

            # Focus on the centroid.
            sensor.ioctl(sensor.IOCTL_SET_READOUT_WINDOW, (x, y, w, h))

            # See if we are hitting the edge.
            new_x, new_y, w, h = sensor.ioctl(sensor.IOCTL_GET_READOUT_WINDOW)

            # You can use these error values to drive servos to move the camera if you want.
            x_error = x - new_x
            y_error = y - new_y

            if x_error < 0: print("-X Limit Reached ", end="")
            if x_error > 0: print("+X Limit Reached ", end="")
            if y_error < 0: print("-Y Limit Reached ", end="")
            if y_error > 0: print("+Y Limit Reached ", end="")
Esempio n. 2
0
    def get_thermal_statistics(self):

        string = ""
        fpa_temp = sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)
        aux_temp = sensor.ioctl(sensor.IOCTL_LEPTON_GET_AUX_TEMPERATURE)

        string += "FPA {:.2f} AUX {:.2f}".format(fpa_temp, aux_temp)
        string += "\n {:.2f} {:.2f} {:.2f}".format(self.temperature_mean,
                                                   self.temperature_max,
                                                   self.temperature_min)

        return string
Esempio n. 3
0
        def get_mapped_centroid(b):
            # By default the readout window is set the whole sensor pixel array with x/y==0.
            # The resolution you see if produced by taking pixels from the readout window on
            # the camera. The x/y location is relative to the sensor center.
            x, y, w, h = sensor.ioctl(sensor.IOCTL_GET_READOUT_WINDOW)

            # The camera driver will try to scale to fit whatever resolution you pass to max
            # width/height that fit on the sensor while keeping the aspect ratio.
            ratio = min(w / float(sensor.width()), h / float(sensor.height()))

            # Reference cx() to the center of the viewport and then scale to the readout.
            mapped_cx = (b.cx() - (sensor.width() / 2.0)) * ratio
            # Since we are keeping the aspect ratio there might be an offset in x.
            mapped_cx += (w - (sensor.width() * ratio)) / 2.0
            # Add in our displacement from the sensor center
            mapped_cx += x + (sensor_w / 2.0)

            # Reference cy() to the center of the viewport and then scale to the readout.
            mapped_cy = (b.cy() - (sensor.height() / 2.0)) * ratio
            # Since we are keeping the aspect ratio there might be an offset in y.
            mapped_cy += (h - (sensor.height() * ratio)) / 2.0
            # Add in our displacement from the sensor center
            mapped_cy += y + (sensor_h / 2.0)

            return (mapped_cx, mapped_cy) # X/Y location on the sensor array.
Esempio n. 4
0
    def get_spotmeter_values(self):
        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4ED0, 4)
        radSpotmeterValue, radSpotmeterMaxValue, radSpotmeterMinValue, radSpotmeterPopulation = struct.unpack(
            "<HHHH", data)

        self.temperature_mean = self.tlinear2celcius(radSpotmeterValue)
        self.temperature_max = self.tlinear2celcius(radSpotmeterMaxValue)
        self.temperature_min = self.tlinear2celcius(radSpotmeterMinValue)
Esempio n. 5
0
 def receive_gain_mode(self):
     # TODO switch modes
     data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x0248, 2)
     self.gain_mode = struct.unpack("<I", data)[0]
     #LEP_SYS_GAIN_MODE_HIGH = 0,
     #LEP_SYS_GAIN_MODE_LOW,
     #LEP_SYS_GAIN_MODE_AUTO,
     self.logger.info("SYS Gain Mode", self.gain_mode)
Esempio n. 6
0
 def receive_flux_parameters(self):
     data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4EBC, 8)
     self.sceneEmissivity, self.TBkgK, self.tauWindow, self.TWindowK, self.tauAtm, self.TAtmK, self.reflWindow, self.TReflK = struct.unpack(
         "<HHHHHHHH", data)
     self.logger.info(
         "RAD Flux Linear Parameters:",
         "\nsceneEmissivity",
         self.sceneEmissivity,
         "\nTBkgK",
         self.TBkgK,
         "\ntauWindow",
         self.tauWindow,
         "\nTWindowK",
         self.TWindowK,
         "\ntauAtm",
         self.tauAtm,
         "\nTAtmK",
         self.TAtmK,
         "\nreflWindow",
         self.reflWindow,
         "\nTReflK",
         self.TReflK,
     )
Esempio n. 7
0
def setup():
    # Color Tracking Thresholds (Grayscale Min, Grayscale Max)
    global threshold_list
    threshold_list = [(200, 255)]

    # Set the target temp range here
    min_temp_in_celsius = 0.0
    max_temp_in_celsius = 64.0

    print("Resetting Lepton...")
    # These settings are applied on reset
    sensor.reset()
    sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
    sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE,
                 min_temp_in_celsius, max_temp_in_celsius)
    print("Lepton Res (%dx%d)" %
          (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
           sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
    print("Radiometry Available: " + (
        "Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))

    # FPS clock
    global clock
    clock = time.clock()
# Himax motion detection example.

import sensor, image, time, pyb
from pyb import Pin, ExtInt

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)

# The sensor is less noisy with lower FPS.
sensor.set_framerate(15)

# Configure and enable motion detection
sensor.ioctl(sensor.IOCTL_HIMAX_MD_THRESHOLD, 0x01)
sensor.ioctl(sensor.IOCTL_HIMAX_MD_WINDOW, (0, 0, 320, 240))
sensor.ioctl(sensor.IOCTL_HIMAX_MD_CLEAR)
sensor.ioctl(sensor.IOCTL_HIMAX_MD_ENABLE, True)

motion_detected = False


def on_motion(line):
    global motion_detected
    motion_detected = True


led = pyb.LED(3)
# Configure external interrupt pin. When motion is detected, this pin is pulled high
ext = ExtInt(Pin("PC15"), ExtInt.IRQ_RISING, Pin.PULL_DOWN, on_motion)
# This example shows off single color RGB565 tracking using the OpenMV Cam using the FLIR LEPTON.

# FLIR Lepton Shutter Note: FLIR Leptons with radiometry and a shutter will pause the video often
# as they heatup to re-calibrate. This will happen less and less often as the sensor temperature
# stablizes. You can force the re-calibration to not happen if you need to via the lepton API.
# However, it is not recommended because the image will degrade overtime.

import sensor, image, time, math

# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
threshold_list = [( 70, 100,  -30,   40,   20,  100)]

print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
                              sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))
# Make the color palette cool
sensor.set_color_palette(sensor.PALETTE_IRONBOW)

sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=5000)
clock = time.clock()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.

while(True):
import sensor, image, time, math

# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
threshold_list = [(100, 255)]  # track very hot objects

# Set the target temp range here
# 500C is the maximum the Lepton 3.5 sensor can measure
# At room temperature it's max is ~380C
min_temp_in_celsius = 0.0
max_temp_in_celsius = 400.0

print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
# Enable measurement mode with high temp
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius,
             max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
                              sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " +
      ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))

sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=5000)
clock = time.clock()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
# leptons don't have radiometry support or they don't activate their calibration process often
# enough to deal with temperature changes (FLIR 2.5).

import sensor, image, time, math

# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
threshold_list = [(200, 255)]

# Set the target temp range here
min_temp_in_celsius = 25
max_temp_in_celsius = 42

print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
                              sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))

sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=5000)
clock = time.clock()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.
i = 0
Esempio n. 12
0
 def thermal_fcc(self):
     self.logger.info("SYS Run FFC Normalization")
     sensor.ioctl(sensor.IOCTL_LEPTON_RUN_COMMAND, 0x0242)
     self.logger.info("RAD FFC Normalization")
     sensor.ioctl(sensor.IOCTL_LEPTON_RUN_COMMAND, 0x4E2E)
Esempio n. 13
0
 def send_gain_mode(self):
     data = struct.pack("<I", self.gain_mode)
     sensor.ioctl(sensor.IOCTL_LEPTON_SET_ATTRIBUTE, 0x0249, data)
     self.logger.info("Setting: SYS Gain Mode to ", self.gain_mode)
     self.receive_gain_mode()
Esempio n. 14
0
 def send_flux_parameters(self):
     data = struct.pack("<HHHHHHHH", self.sceneEmissivity, self.TBkgK,
                        self.tauWindow, self.TWindowK, self.tauAtm,
                        self.TAtmK, self.reflWindow, self.TReflK)
     sensor.ioctl(sensor.IOCTL_LEPTON_SET_ATTRIBUTE, 0x4EBD, data)
     self.receive_flux_parameters()
# This example shows off single color grayscale tracking using the OpenMV Cam using the FLIR LEPTON.

# FLIR Lepton Shutter Note: FLIR Leptons with radiometry and a shutter will pause the video often
# as they heatup to re-calibrate. This will happen less and less often as the sensor temperature
# stablizes. You can force the re-calibration to not happen if you need to via the lepton API.
# However, it is not recommended because the image will degrade overtime.

import sensor, image, time, math, lcd

# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
threshold_list = [(220, 255)]

print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
                              sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " +
      ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))

sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.LCD)
sensor.skip_frames(time=5000)
clock = time.clock()
lcd.init()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.

while (True):
# leptons don't have radiometry support or they don't activate their calibration process often
# enough to deal with temperature changes (FLIR 2.5).

import sensor, image, time, math

# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
threshold_list = [(200, 255)]

# Set the target temp range here
min_temp_in_celsius = 20.0
max_temp_in_celsius = 35.0

print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE, min_temp_in_celsius, max_temp_in_celsius)
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
                              sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) else "No"))

sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=5000)
clock = time.clock()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.

def map_g_to_temp(g):
Esempio n. 17
0
 def send_thermal_static_range(self):
     sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE,
                  self.static_minimum, self.static_maximum)
Esempio n. 18
0
# Global Shutter Triggered Mode Example
#
# This example shows off setting the global shutter camera into triggered mode. In triggered mode
# snapshot() controls EXACTLY when integration of the camera pixels start such that you can sync
# taking pictures to some external movement. Since the camera captures all pixels at the same time
# (as it is a global shutter camera versus a rolling shutter camera) movement in the image will
# only be captured for the integration time and not the integration time multipled by the number
# of rows in the image. Additionally, sensor noise is reduced in triggered mode as the camera will
# not read out rows until after exposing which results in a higher quality image.
#
# That said, your maximum frame rate will be reduced by 2 to 3 as camera are no longer generated
# continously by the camera and because you have to wait for the integration to finish before
# readout of the frame.

import sensor, image, time

sensor.reset()  # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE)  # Set pixel format to GRAYSCALE
sensor.set_framesize(sensor.VGA)  # Set frame size to VGA (640x480)
sensor.skip_frames(time=2000)  # Wait for settings take effect.
clock = time.clock()  # Create a clock object to track the FPS.

sensor.ioctl(sensor.IOCTL_SET_TRIGGERED_MODE, True)

while (True):
    clock.tick()  # Update the FPS clock.
    img = sensor.snapshot()  # Take a picture and return the image.
    print(
        clock.fps())  # Note: OpenMV Cam runs about half as fast when connected
    # to the IDE. The FPS should increase once disconnected.
Esempio n. 19
0
    def thermal_configure(self, static_range=None):
        self.logger.info(
            "##############################################################")
        self.logger.info("SETTINGS")
        if static_range is not None:
            self.static_range = static_range
        if self.static_range:
            sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
            sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_RANGE,
                         self.static_minimum, self.static_maximum)

        else:
            sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, False)
            self.logger.info("Setting: AGC Enable and Disable (Enable)")
            sensor.ioctl(sensor.IOCTL_LEPTON_SET_ATTRIBUTE, 0x0101,
                         struct.pack("<I", 1))

            self.logger.info("Setting: RAD Radiometry Control Enable")
            sensor.ioctl(sensor.IOCTL_LEPTON_SET_ATTRIBUTE, 0x4E11,
                         struct.pack("<I", 1))

        self.logger.info(
            "-------------------------------------------------------------")
        self.logger.info("AGC:")
        # TODO switch modes
        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x0100, 2)
        LEP_AGC_ENABLE_TAG = struct.unpack("<I", data)[0]
        #LEP_AGC_DISABLE=0,
        #LEP_AGC_ENABLE
        self.logger.info("AGC Enable and Disable", LEP_AGC_ENABLE_TAG)

        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x0148, 2)
        LEP_AGC_ENABLE_TAG = struct.unpack("<I", data)[0]
        #LEP_AGC_DISABLE=0,
        #LEP_AGC_ENABLE
        self.logger.info("AGC Calculation Enable State", LEP_AGC_ENABLE_TAG)

        self.receive_gain_mode()
        self.send_gain_mode()

        #typedef struct LEP_SYS_GAIN_MODE_OBJ_T_TAG
        #{
        #FLR_SYS_GAIN_MODE_ROI_T sysGainModeROI; /* Specified ROI to use for Gain Mode switching */
        #FLR_SYS_GAIN_MODE_THRESHOLDS_T sysGainModeThresholds; /* Set of threshold triggers */
        #FLR_UINT16 sysGainRoiPopulation; /* Population size in pixels within the ROI */
        #FLR_UINT16 sysGainModeTempEnabled; /* True if T-Linear is implemented */
        #FLR_UINT16 sysGainModeFluxThresholdLowToHigh; /* calculated from desired temp */
        #FLR_UINT16 sysGainModeFluxThresholdHighToLow; /* calculated from desired temp */
        #}LEP_SYS_GAIN_MODE_OBJ_T, *LEP_SYS_GAIN_MODE_OBJ_T_PTR;

        #typedef struct LEP_SYS_GAIN_MODE_ROI_T_TAG
        #{
        #LEP_UINT16 startCol;
        #LEP_UINT16 startRow;
        #LEP_UINT16 endCol;
        #LEP_UINT16 endRow;
        #}LEP_SYS_GAIN_MODE_ROI_T, *LEP_SYS_GAIN_MODE_ROI_T_PTR;
        #/* Gain Mode Support
        #*/
        #typedef struct LEP_SYS_GAIN_MODE_THRESHOLDS_T_TAG
        #{
        #LEP_SYS_THRESHOLD_T sys_P_high_to_low; /* Range: [0 - 100], percent */
        #LEP_SYS_THRESHOLD_T sys_P_low_to_high; /* Range: [0 - 100], percent */
        #LEP_SYS_THRESHOLD_T sys_C_high_to_low; /* Range: [0 - 600], degrees C */
        #LEP_SYS_THRESHOLD_T sys_C_low_to_high; /* Range: [0 - 600], degrees C */
        #LEP_SYS_THRESHOLD_T sys_T_high_to_low; /* Range: [0 - 900], Kelvin */
        #LEP_SYS_THRESHOLD_T sys_T_low_to_high; /* Range: [0 - 900], Kelvin */
        #}LEP_SYS_GAIN_MODE_THRESHOLDS_T, *LEP_SYS_GAIN_MODE_THRESHOLDS_T_PTR;

        #0x0250

        ###############################################################
        # RADIOMETRY
        self.logger.info(
            "-------------------------------------------------------------")
        self.logger.info("RADIOMETRY:")

        self.thermal_fcc()
        sensor.snapshot()
        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4E24, 2)
        FLR_RAD_TS_MODE_E_TAG = struct.unpack("<I", data)[0]
        #FLR_RAD_TS_USER_MODE = 0
        #FLR_RAD_TS_CAL_MODE = 1
        #FLR_RAD_TS_FIXED_MODE = 2
        #FLR_RAD_TS_END_TS_MODE = 3
        self.logger.info("RAD TShutter Mode", FLR_RAD_TS_MODE_E_TAG)

        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4E10, 2)
        LEP_RAD_ENABLE_E_TAG = struct.unpack("<I", data)[0]
        #LEP_RAD_DISABLE = 0,
        #LEP_RAD_ENABLE,
        self.logger.info("RAD Radiometry Control Enable", LEP_RAD_ENABLE_E_TAG)

        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4E28, 1)
        LEP_RAD_KELVIN_T = struct.unpack("<H", data)[0]
        self.logger.info("RAD TShutter Temperature", LEP_RAD_KELVIN_T)

        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4E30, 2)
        LEP_RAD_STATUS_E = struct.unpack("<I", data)[0]
        #LEP_RAD_STATUS_ERROR = -1,
        #LEP_RAD_STATUS_READY = 0,
        #LEP_RAD_STATUS_BUSY,
        #LEP_RAD_FRAME_AVERAGE_COLLECTING_FRAMES
        self.logger.info("RAD Run Status", LEP_RAD_STATUS_E)

        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4EC0, 2)
        LEP_RAD_ENABLE_E_TAG = struct.unpack("<I", data)[0]
        #LEP_RAD_DISABLE = 0,
        #LEP_RAD_ENABLE,
        self.logger.info("RAD T-Linear Enable State", LEP_RAD_ENABLE_E_TAG)

        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4EC8, 2)
        LEP_RAD_ENABLE_E_TAG = struct.unpack("<I", data)[0]
        #LEP_RAD_DISABLE = 0,
        #LEP_RAD_ENABLE,
        self.logger.info("RAD T-Linear Auto Resolution", LEP_RAD_ENABLE_E_TAG)

        startRow = 0
        startCol = 0
        endRow = sensor.height() - 1
        endCol = sensor.width() - 1
        data = struct.pack("<HHHH", startRow, startCol, endRow, endCol)
        sensor.ioctl(sensor.IOCTL_LEPTON_SET_ATTRIBUTE, 0x4ECD, data)

        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4ECC, 4)
        startRow_rx, startCol_rx, endRow_rx, endCol_rx = struct.unpack(
            "<HHHH", data)
        self.logger.info("Spotmeter {} {} {} {}".format(
            startRow_rx, startCol_rx, endRow_rx, endCol_rx))
        if startRow != startRow_rx or startCol != startCol_rx or endRow != endRow_rx or endCol != endCol_rx:
            raise ValueError("Spotmeter wrong window")

        data = sensor.ioctl(sensor.IOCTL_LEPTON_GET_ATTRIBUTE, 0x4EC4, 2)
        self.thermal_tlinear_resolution = 0.01 if struct.unpack(
            "<I", data)[0] else 0.1
        self.logger.info("thermal_tlinear_resolution",
                         self.thermal_tlinear_resolution)

        self.receive_flux_parameters()
        self.send_flux_parameters()
        self.logger.info(
            "##############################################################")
Esempio n. 20
0
TRACKING_PIXEL_THRESHOLD = TRACKING_AREA_THRESHOLD

TRACKING_EDGE_TOLERANCE = 0.05 # Blob can move 5% away from the center.

sensor.reset()                         # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE
sensor.set_framesize(SEARCHING_RESOLUTION)
sensor.skip_frames(time = 1000)        # Wait for settings take effect.
clock = time.clock()                   # Create a clock object to track the FPS.

sensor.set_auto_gain(False)            # Turn off as it will oscillate.
sensor.set_auto_exposure(False, exposure_us=EXPOSURE_MICROSECONDS)
sensor.skip_frames(time = 1000)

# sensor_w and sensor_h are the image sensor raw pixels w/h (x/y are 0 initially).
x, y, sensor_w, sensor_h = sensor.ioctl(sensor.IOCTL_GET_READOUT_WINDOW)

while(True):
    clock.tick()
    img = sensor.snapshot()

    # We need to find an IR object to track - it's likely to be really bright.
    blobs = img.find_blobs(TRACKING_THRESHOLDS,
                           area_threshold=SEARCHING_AREA_THRESHOLD,
                           pixels_threshold=SEARCHING_PIXEL_THRESHOLD)

    if len(blobs):
        most_dense_blob = max(blobs, key = lambda x: x.density())
        img.draw_rectangle(most_dense_blob.rect())

        def get_mapped_centroid(b):
Esempio n. 21
0
# Global Shutter Triggered Mode Example
#
# This example shows off setting the global shutter camera into triggered mode. In triggered mode
# snapshot() controls EXACTLY when integration of the camera pixels start such that you can sync
# taking pictures to some external movement. Since the camera captures all pixels at the same time
# (as it is a global shutter camera versus a rolling shutter camera) movement in the image will
# only be captured for the integration time and not the integration time multipled by the number
# of rows in the image. Additionally, sensor noise is reduced in triggered mode as the camera will
# not read out rows until after exposing which results in a higher quality image.
#
# That said, your maximum frame rate will be reduced by 2 to 3 as frames are no longer generated
# continously by the camera and because you have to wait for the integration to finish before
# readout of the frame.

import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE
sensor.set_framesize(sensor.VGA)    # Set frame size to VGA (640x480)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

sensor.ioctl(sensor.IOCTL_SET_TRIGGERED_MODE, True)

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.
Esempio n. 22
0
KEY = Pin('C13', Pin.IN, Pin.PULL_DOWN)
lcd.init(type=2, refresh=120)

clock = time.clock()
keycount = 0
while (True):
    clock.tick()
    img = sensor.snapshot()
    print(clock.fps())
    lcd.display(img)
    if sensor.get_id() == sensor.OV5640:
        if KEY.value() == 1:
            while KEY.value() == 1:
                blue_led.on()
                sleep(0.05)
                blue_led.off()
                sleep(0.05)
                keycount += 1
                if keycount > 3:
                    sensor.ioctl(sensor.IOCTL_RESET_AUTO_FOCUS)
                    while KEY.value() == 1:
                        blue_led.on()
                        sleep(0.1)
                        blue_led.off()
                        sleep(0.1)
            if keycount <= 3:
                sensor.ioctl(sensor.IOCTL_TRIGGER_AUTO_FOCUS)
        if keycount != 0:
            sensor.ioctl(sensor.IOCTL_WAIT_ON_AUTO_FOCUS)
            keycount = 0
# This examples shows how to use the Himax Motion Detection feature
# to wake up from low-power Stop Mode on motion detection interrupts.

import sensor, image, time, pyb, machine
from pyb import Pin, ExtInt

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.set_framerate(15)

sensor.ioctl(sensor.IOCTL_HIMAX_MD_THRESHOLD, 10)
sensor.ioctl(sensor.IOCTL_HIMAX_MD_WINDOW, (0, 0, 320, 240))
sensor.ioctl(sensor.IOCTL_HIMAX_MD_CLEAR)
sensor.ioctl(sensor.IOCTL_HIMAX_MD_ENABLE, True)


def on_motion(line):
    pass


led = pyb.LED(3)
ext = ExtInt(Pin("PC15"), ExtInt.IRQ_RISING, Pin.PULL_DOWN, on_motion)

while (True):
    led.off()
    sensor.ioctl(sensor.IOCTL_HIMAX_OSC_ENABLE, True)  # Switch to internal OSC
    sensor.ioctl(sensor.IOCTL_HIMAX_MD_CLEAR)  # Clear MD flag
    machine.sleep()  # Enter low-power mode, will wake up on MD interrupt.
    sensor.ioctl(sensor.IOCTL_HIMAX_OSC_ENABLE, False)  # Switch back to MCLK
    led.on()