sensor — camera sensor¶
Deprecated since version 4.5: The sensor module is deprecated. Use the new csi module
(see csi — camera sensors) instead. No new features will be added to this module
and it may be removed in a future release.
The sensor module is the legacy module-level interface to the
primary camera sensor on an OpenMV Cam. Every call is a free function
that operates on a single hidden CSI instance, which limits
support for boards with more than one camera. It is preserved for
backwards compatibility with older OpenMV scripts; new code should
use the object-oriented csi module instead.
The function names follow the older set_pixformat /
set_framesize style. Each function corresponds one-to-one to a
method on csi.CSI; see the csi module for the
complete capability set and per-argument descriptions.
Example usage:
import sensor
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
while True:
img = sensor.snapshot()
Functions¶
- sensor.sleep(enable: bool) None¶
Puts the camera to sleep if
enableisTrue. Otherwise, wakes it back up.
- sensor.shutdown(enable: bool) None¶
Puts the camera into a lower power mode than sleep. The camera must be reset on being woken up.
- sensor.snapshot() image.Image¶
Takes a picture using the camera and returns an
image.Imageobject.If
sensor.set_auto_rotation()is enabled this method returns a new already rotatedimage.Imageobject.
- sensor.skip_frames(n: int | None = None, time: int = 300) None¶
Skips
nframes ortimemilliseconds (whichever is specified) to let the camera image stabilize after changing camera settings.If neither
nnortimeis specified this method skips frames for 300 milliseconds.If both are specified this method skips
nframes but will timeout aftertimemilliseconds.
- sensor.get_fb() image.Image | None¶
Returns the image object returned by a previous call of
sensor.snapshot(). ReturnsNoneifsensor.snapshot()has not been called before.
- sensor.get_frame_available() bool¶
Returns
Trueif a frame is available to read by callingsensor.snapshot().
- sensor.alloc_extra_fb(width: int, height: int, pixformat: int) image.Image¶
Deprecated since version 4.5: This function is deprecated and will raise
OSError. Use the newcsimodule instead.
- sensor.dealloc_extra_fb() None¶
Deprecated since version 4.5: This function is deprecated and will raise
OSError. Use the newcsimodule instead.
- sensor.set_pixformat(pixformat: int) None¶
Sets the pixel format for the camera module.
pixformatis one of:sensor.JPEG(only for the OV2640/OV5640)
- sensor.set_framesize(framesize: int) None¶
Sets the frame size for the camera module. See the framesize constants below for valid values.
- sensor.set_windowing(roi: Tuple[int, int] | Tuple[int, int, int, int] | List[int]) None¶
Sets the resolution of the camera to a sub-resolution inside of the current resolution.
roiis a rect tuple/list(x, y, w, h). You may also pass(w, h)and theroiwill be centered on the frame. The arguments may also be passed unpacked as positional integers.
- sensor.get_windowing() Tuple[int, int, int, int]¶
Returns the
roituple(x, y, w, h)previously set withsensor.set_windowing().
- sensor.set_gainceiling(gainceiling: int) bool¶
Set the camera image gain ceiling. Valid values are
2,4,8,16,32,64, or128. ReturnsTrueon success.
- sensor.set_contrast(contrast: int) bool¶
Set the camera image contrast. Valid range is
-3to+3. ReturnsTrueon success.
- sensor.set_brightness(brightness: int) bool¶
Set the camera image brightness. Valid range is
-3to+3. ReturnsTrueon success.
- sensor.set_saturation(saturation: int) bool¶
Set the camera image saturation. Valid range is
-3to+3. ReturnsTrueon success.
- sensor.set_quality(quality: int) bool¶
Set the camera image JPEG compression quality. Valid range is
0to100. ReturnsTrueon success. Only for the OV2640/OV5640 cameras.
- sensor.set_colorbar(enable: bool) bool¶
Turns color bar test mode on (
True) or off (False). ReturnsTrueon success.
- sensor.set_auto_gain(enable: int, gain_db: float | None = None, gain_db_ceiling: float | None = None) None¶
enableturns auto gain control on (1) or off (0).If
enableis0you may set a fixed gain in decibels withgain_db.If
enableis non-zero you may set the maximum gain ceiling in decibels withgain_db_ceilingfor the automatic gain control algorithm.gain_dbandgain_db_ceilingare keyword-only arguments.
- sensor.set_auto_exposure(enable: int, exposure_us: int = -1) None¶
enableturns auto exposure control on (1) or off (0).If
enableis0you may set a fixed exposure time in microseconds withexposure_us.exposure_usis a keyword-only argument.
- sensor.set_auto_whitebal(enable: int, rgb_gain_db: Tuple[float, float, float] | None = None) None¶
enableturns auto white balance on (1) or off (0).If
enableis0you may set a fixed gain in decibels for the red, green, and blue channels respectively withrgb_gain_db.rgb_gain_dbis a keyword-only argument.
- sensor.get_rgb_gain_db() Tuple[float, float, float]¶
Returns a tuple with the current camera red, green, and blue gain values in decibels.
- sensor.set_auto_blc(enable: int, regs: List[int] | None = None) None¶
Sets the auto black level calibration (BLC) control on the camera.
enableis1to enable or0to disable.regsif disabled, you can manually set the BLC register values via the values previously read fromsensor.get_blc_regs(). The list length must match the sensor’s BLC register count.
- sensor.get_blc_regs() List[int]¶
Returns the sensor BLC registers as a list of integers. For use with
sensor.set_auto_blc().
- sensor.set_hmirror(enable: bool) None¶
Turns horizontal mirror mode on (
True) or off (False). Defaults to off.
- sensor.set_vflip(enable: bool) None¶
Turns vertical flip mode on (
True) or off (False). Defaults to off.
- sensor.set_transpose(enable: bool) None¶
Turns transpose mode on (
True) or off (False). Defaults to off.vflip=False, hmirror=False, transpose=False -> 0 degree rotation
vflip=True, hmirror=False, transpose=True -> 90 degree rotation
vflip=True, hmirror=True, transpose=False -> 180 degree rotation
vflip=False, hmirror=True, transpose=True -> 270 degree rotation
- sensor.set_auto_rotation(enable: bool) None¶
Turns auto rotation mode on (
True) or off (False). Defaults to off. Only works when the OpenMV Cam has animuinstalled.
- sensor.set_framebuffers(count: int) None¶
Sets the number of frame buffers used to receive image data.
countmay be1(single buffer),2(double buffer),3(triple buffer), or4or greater to put the sensor driver into video FIFO mode where received frames are stored in a FIFO ofcountbuffers.
- sensor.disable_delays(disable: bool | None = None) bool | None¶
If
disableisTruethen disable all settling time delays in the sensor module.If called with no arguments returns
Trueif delays are disabled.
- sensor.disable_full_flush(disable: bool | None = None) bool | None¶
If
disableisTruethen automatic framebuffer flushing on frame drop is disabled.If called with no arguments returns
Trueif automatic flushing is disabled.
- sensor.set_special_effect(sde: int) bool¶
Sets the special digital effect (SDE) on the sensor.
sdeis one ofsensor.NORMALorsensor.NEGATIVE. ReturnsTrueon success.
- sensor.set_lens_correction(enable: bool, radi: int, coef: int) bool¶
enableTrueto enable,Falseto disable.radiinteger radius of pixels to correct.coefpower of correction.Returns
Trueon success.
- sensor.set_vsync_callback(cb: Callable[[int], None] | None) None¶
Registers callback
cbto be executed (in interrupt context) whenever the camera module generates a new frame (but before the frame is received).cbtakes one argument: the current state of the vsync pin after changing.Pass a non-callable (e.g.
None) to unregister.
- sensor.set_frame_callback(cb: Callable[[], None] | None) None¶
Registers callback
cbto be executed (in interrupt context) whenever the camera module generates a new frame and the frame is ready to be read viasensor.snapshot().cbtakes no arguments.Pass a non-callable (e.g.
None) to unregister.
- sensor.ioctl(request: int, *args: Any) Any¶
Execute a sensor-specific request.
requestis one of theIOCTL_*constants; the remaining positional arguments and the return value depend on the request. The supported requests are grouped by sensor family below.Generic (any sensor):
ioctl(IOCTL_SET_READOUT_WINDOW, (x, y, w, h))ioctl(IOCTL_SET_READOUT_WINDOW, (w, h))Set the sensor readout window. A smaller window raises the frame rate at the cost of field-of-view.
ioctl(IOCTL_GET_READOUT_WINDOW)Returns the current readout window as an
(x, y, w, h)tuple.ioctl(IOCTL_SET_TRIGGERED_MODE, enable)Enable (
True) or disable (False) triggered mode on the MT9V034.ioctl(IOCTL_GET_TRIGGERED_MODE)Returns the current triggered-mode state as a
bool.ioctl(IOCTL_SET_FOV_WIDE, enable)When
True, instructset_framesize()to optimize for field-of-view rather than frame rate.ioctl(IOCTL_GET_FOV_WIDE)Returns the current FOV-wide state as a
bool.ioctl(IOCTL_SET_NIGHT_MODE, enable)Enable (
True) or disable (False) the sensor’s low-light “night mode”. OV7725 and OV5640 only.ioctl(IOCTL_GET_NIGHT_MODE)Returns the current night-mode state as a
bool.ioctl(IOCTL_GET_RGB_STATS)Returns a 4-tuple of raw RGB-channel statistics
(r, gb, gr, b)read from the sensor (typically used for white-balance tuning).
OV5640 FPC – auto-focus:
ioctl(IOCTL_TRIGGER_AUTO_FOCUS)Start an auto-focus sweep on the OV5640 FPC module.
ioctl(IOCTL_PAUSE_AUTO_FOCUS)Pause an in-progress auto-focus sweep.
ioctl(IOCTL_RESET_AUTO_FOCUS)Reset the auto-focus position to the default.
ioctl(IOCTL_WAIT_ON_AUTO_FOCUS)ioctl(IOCTL_WAIT_ON_AUTO_FOCUS, timeout_ms)Block until the current auto-focus sweep finishes.
timeout_msdefaults to 5000 if omitted.
FLIR Lepton:
ioctl(IOCTL_LEPTON_GET_WIDTH)Returns the Lepton image width in pixels.
ioctl(IOCTL_LEPTON_GET_HEIGHT)Returns the Lepton image height in pixels.
ioctl(IOCTL_LEPTON_GET_RADIOMETRY)Returns the Lepton’s type (radiometric or not) as an int.
ioctl(IOCTL_LEPTON_GET_REFRESH)Returns the Lepton’s refresh rate in Hz.
ioctl(IOCTL_LEPTON_GET_RESOLUTION)Returns the Lepton’s ADC resolution in bits.
ioctl(IOCTL_LEPTON_RUN_COMMAND, cmd)Run a FLIR Lepton SDK command.
cmdis the 16-bit command id defined by the SDK.ioctl(IOCTL_LEPTON_SET_ATTRIBUTE, attr_id, payload)Write a Lepton SDK attribute.
attr_idis the 16-bit attribute id;payloadis abytes/bytearraywhose length must be a multiple of 16 bits.ioctl(IOCTL_LEPTON_GET_ATTRIBUTE, attr_id, words)Read a Lepton SDK attribute.
attr_idis the 16-bit attribute id;wordsis the number of 16-bit words to read. Returns abytearray.ioctl(IOCTL_LEPTON_GET_FPA_TEMP)Returns the Lepton focal-plane-array temperature in degrees Celsius.
ioctl(IOCTL_LEPTON_GET_AUX_TEMP)Returns the Lepton auxiliary temperature in degrees Celsius.
ioctl(IOCTL_LEPTON_SET_MODE, measurement_enabled)ioctl(IOCTL_LEPTON_SET_MODE, measurement_enabled, high_temp_enabled)Switch the Lepton between AGC and direct-temperature output.
measurement_enabled=Trueenables direct temperature output. The optionalhigh_temp_enabledflag selects the high-temperature range.ioctl(IOCTL_LEPTON_GET_MODE)Returns a 2-tuple
(measurement_enabled, high_temp_enabled).ioctl(IOCTL_LEPTON_SET_RANGE, min_temp_c, max_temp_c)Set the temperature range mapped to
0..255when measurement mode is enabled.ioctl(IOCTL_LEPTON_GET_RANGE)Returns the current
(min_celsius, max_celsius)range.
Himax HM01B0 – motion detection:
ioctl(IOCTL_HIMAX_MD_ENABLE, enable)Enable (
True) or disable (False) the HM01B0’s on-sensor motion-detection block.ioctl(IOCTL_HIMAX_MD_WINDOW, (x, y, w, h))ioctl(IOCTL_HIMAX_MD_WINDOW, (w, h))Set the motion-detection window on the HM01B0.
ioctl(IOCTL_HIMAX_MD_THRESHOLD, threshold)Set the motion-detection threshold (
0–255).ioctl(IOCTL_HIMAX_MD_CLEAR)Clear the motion-detection interrupt latch.
ioctl(IOCTL_HIMAX_OSC_ENABLE, enable)Enable (
True) or disable (False) the HM01B0’s internal oscillator.
Prophesee GENX320 – event sensor:
ioctl(IOCTL_GENX320_SET_BIASES, preset)Apply a bias preset.
presetis one of theGENX320_BIASES_*constants.ioctl(IOCTL_GENX320_SET_BIAS, bias, value)Set a single bias.
biasis one of theGENX320_BIAS_*constants;valueis the integer setting.ioctl(IOCTL_GENX320_SET_AFK, enable)ioctl(IOCTL_GENX320_SET_AFK, enable, freq_low_hz, freq_high_hz)Configure the anti-flicker filter.
enableis a bool; the optional frequency arguments set the filter passband.
- sensor.set_color_palette(palette: int) None¶
Sets the color palette for the FLIR Lepton (and similar) grayscale to RGB565 conversion.
paletteis one ofimage.PALETTE_RAINBOW,image.PALETTE_IRONBOW,image.PALETTE_DEPTH,image.PALETTE_EVT_DARK, orimage.PALETTE_EVT_LIGHT.
- sensor.get_color_palette() int | None¶
Returns the current color palette setting, or
Noneif the active palette is unrecognized.
Constants¶
- sensor.RGB565: int¶
RGB565 pixel format. Each pixel is 16-bits, 2-bytes. 5-bits red, 6-bits green, 5-bits blue.
- sensor.OV2640: int¶
sensor.get_id()returns this for the OV2640 camera.
- sensor.OV5640: int¶
sensor.get_id()returns this for the OV5640 camera.
- sensor.OV7670: int¶
sensor.get_id()returns this for the OV7670 camera.
- sensor.OV7690: int¶
sensor.get_id()returns this for the OV7690 camera.
- sensor.OV7725: int¶
sensor.get_id()returns this for the OV7725 camera.
- sensor.OV9650: int¶
sensor.get_id()returns this for the OV9650 camera.
- sensor.MT9V022: int¶
sensor.get_id()returns this for the MT9V022 camera.
- sensor.MT9V024: int¶
sensor.get_id()returns this for the MT9V024 camera.
- sensor.MT9V032: int¶
sensor.get_id()returns this for the MT9V032 camera.
- sensor.MT9V034: int¶
sensor.get_id()returns this for the MT9V034 camera.
- sensor.MT9M114: int¶
sensor.get_id()returns this for the MT9M114 camera.
- sensor.BOSON320: int¶
sensor.get_id()returns this for the BOSON 320x256 camera.
- sensor.BOSON640: int¶
sensor.get_id()returns this for the BOSON 640x512 camera.
- sensor.LEPTON: int¶
sensor.get_id()returns this for the LEPTON1/2/3 cameras.
- sensor.HM01B0: int¶
sensor.get_id()returns this for the HM01B0 camera.
- sensor.HM0360: int¶
sensor.get_id()returns this for the HM0360 camera.
- sensor.GC2145: int¶
sensor.get_id()returns this for the GC2145 camera.
- sensor.GENX320ES: int¶
sensor.get_id()returns this for the GENX320 (engineering sample) camera.
- sensor.GENX320: int¶
sensor.get_id()returns this for the GENX320 camera.
- sensor.PAG7920: int¶
sensor.get_id()returns this for the PAG7920 camera.
- sensor.PAG7936: int¶
sensor.get_id()returns this for the PAG7936 camera.
- sensor.PAJ6100: int¶
sensor.get_id()returns this for the PAJ6100 camera.
- sensor.FROGEYE2020: int¶
sensor.get_id()returns this for the FROGEYE2020 camera.
- sensor.NORMAL: int¶
Pass to
sensor.set_special_effect()for normal (no SDE) output.
- sensor.NEGATIVE: int¶
Pass to
sensor.set_special_effect()for negative-image output.
- sensor.B64X32: int¶
64x32 resolution. For use with
Image.find_displacement()and other FFT based algorithms.
- sensor.B64X64: int¶
64x64 resolution. For use with
Image.find_displacement()and other FFT based algorithms.
- sensor.B128X64: int¶
128x64 resolution. For use with
Image.find_displacement()and other FFT based algorithms.
- sensor.B128X128: int¶
128x128 resolution. For use with
Image.find_displacement()and other FFT based algorithms.
- sensor.IOCTL_SET_READOUT_WINDOW: int¶
Set the sensor readout window. See
sensor.ioctl().
- sensor.IOCTL_GET_READOUT_WINDOW: int¶
Get the sensor readout window. See
sensor.ioctl().
- sensor.IOCTL_SET_TRIGGERED_MODE: int¶
Set triggered mode (e.g. for the MT9V034). See
sensor.ioctl().
- sensor.IOCTL_GET_TRIGGERED_MODE: int¶
Get the current triggered-mode state. See
sensor.ioctl().
- sensor.IOCTL_SET_FOV_WIDE: int¶
Optimize
sensor.set_framesize()for field-of-view over FPS. Seesensor.ioctl().
- sensor.IOCTL_GET_FOV_WIDE: int¶
Get the current field-of-view-over-FPS optimization state. See
sensor.ioctl().
- sensor.IOCTL_TRIGGER_AUTO_FOCUS: int¶
Trigger auto focus on the OV5640 FPC camera module. See
sensor.ioctl().
- sensor.IOCTL_PAUSE_AUTO_FOCUS: int¶
Pause auto focus on the OV5640 FPC camera module. See
sensor.ioctl().
- sensor.IOCTL_RESET_AUTO_FOCUS: int¶
Reset auto focus on the OV5640 FPC camera module. See
sensor.ioctl().
- sensor.IOCTL_WAIT_ON_AUTO_FOCUS: int¶
Wait on auto focus to complete on the OV5640 FPC camera module. See
sensor.ioctl().
- sensor.IOCTL_SET_NIGHT_MODE: int¶
Enable/disable night mode on the sensor. See
sensor.ioctl().
- sensor.IOCTL_GET_NIGHT_MODE: int¶
Get the current night-mode state. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_WIDTH: int¶
Get the FLIR Lepton image width in pixels. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_HEIGHT: int¶
Get the FLIR Lepton image height in pixels. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_RADIOMETRY: int¶
Get the FLIR Lepton type (radiometric or not). See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_REFRESH: int¶
Get the FLIR Lepton refresh rate in Hz. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_RESOLUTION: int¶
Get the FLIR Lepton ADC resolution in bits. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_RUN_COMMAND: int¶
Execute a 16-bit FLIR Lepton SDK command. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_SET_ATTRIBUTE: int¶
Set a FLIR Lepton attribute. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_ATTRIBUTE: int¶
Get a FLIR Lepton attribute. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_FPA_TEMP: int¶
Get the FLIR Lepton FPA temperature in celsius. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_AUX_TEMP: int¶
Get the FLIR Lepton AUX temperature in celsius. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_SET_MODE: int¶
Set FLIR Lepton measurement mode. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_MODE: int¶
Get FLIR Lepton measurement-mode state. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_SET_RANGE: int¶
Set the FLIR Lepton measurement-mode temperature range. See
sensor.ioctl().
- sensor.IOCTL_LEPTON_GET_RANGE: int¶
Get the FLIR Lepton measurement-mode temperature range. See
sensor.ioctl().
- sensor.IOCTL_HIMAX_MD_ENABLE: int¶
Enable/disable HM01B0 motion detection. See
sensor.ioctl().
- sensor.IOCTL_HIMAX_MD_WINDOW: int¶
Set the HM01B0 motion detection window. See
sensor.ioctl().
- sensor.IOCTL_HIMAX_MD_THRESHOLD: int¶
Set the HM01B0 motion detection threshold. See
sensor.ioctl().
- sensor.IOCTL_HIMAX_MD_CLEAR: int¶
Clear the HM01B0 motion detection interrupt. See
sensor.ioctl().
- sensor.IOCTL_HIMAX_OSC_ENABLE: int¶
Enable/disable the HM01B0 internal oscillator. See
sensor.ioctl().
- sensor.IOCTL_GET_RGB_STATS: int¶
Get the
(r, gb, gr, b)RGB statistics from the sensor. Seesensor.ioctl().
- sensor.IOCTL_GENX320_SET_BIASES: int¶
Set the GENX320 sensor bias preset. See
sensor.ioctl().
- sensor.IOCTL_GENX320_SET_BIAS: int¶
Set a single GENX320 sensor bias. See
sensor.ioctl().
- sensor.IOCTL_GENX320_SET_AFK: int¶
Set GENX320 anti-flickering-filter parameters. See
sensor.ioctl().