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 provides legacy access to the camera sensor.

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.reset() None

Initializes the camera sensor.

sensor.sleep(enable: bool) None

Puts the camera to sleep if enable is True. 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.flush() None

Copies whatever was in the frame buffer to the IDE preview.

sensor.snapshot() image.Image

Takes a picture using the camera and returns an image.Image object.

If sensor.set_auto_rotation() is enabled this method returns a new already rotated image.Image object.

sensor.skip_frames(n: int | None = None, time: int = 300) None

Skips n frames or time milliseconds (whichever is specified) to let the camera image stabilize after changing camera settings.

If neither n nor time is specified this method skips frames for 300 milliseconds.

If both are specified this method skips n frames but will timeout after time milliseconds.

sensor.width() int

Returns the sensor resolution width.

sensor.height() int

Returns the sensor resolution height.

sensor.get_fb() image.Image | None

Returns the image object returned by a previous call of sensor.snapshot(). Returns None if sensor.snapshot() has not been called before.

sensor.get_id() int

Returns the camera module ID. See the sensor constants below.

sensor.get_frame_available() bool

Returns True if a frame is available to read by calling sensor.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 new csi module instead.

sensor.dealloc_extra_fb() None

Deprecated since version 4.5: This function is deprecated and will raise OSError. Use the new csi module instead.

sensor.set_pixformat(pixformat: int) None

Sets the pixel format for the camera module. pixformat is one of:

sensor.get_pixformat() int

Returns the current pixformat for the camera module.

sensor.set_framesize(framesize: int) None

Sets the frame size for the camera module. See the framesize constants below for valid values.

sensor.get_framesize() int

Returns the current frame size for the camera module.

sensor.set_framerate(rate: int) None

Sets the frame rate in Hz for the camera module.

sensor.get_framerate() int

Returns the frame rate in Hz for the camera module.

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.

roi is a rect tuple/list (x, y, w, h). You may also pass (w, h) and the roi will 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 roi tuple (x, y, w, h) previously set with sensor.set_windowing().

sensor.set_gainceiling(gainceiling: int) bool

Set the camera image gain ceiling. Valid values are 2, 4, 8, 16, 32, 64, or 128. Returns True on success.

sensor.set_contrast(contrast: int) bool

Set the camera image contrast. Valid range is -3 to +3. Returns True on success.

sensor.set_brightness(brightness: int) bool

Set the camera image brightness. Valid range is -3 to +3. Returns True on success.

sensor.set_saturation(saturation: int) bool

Set the camera image saturation. Valid range is -3 to +3. Returns True on success.

sensor.set_quality(quality: int) bool

Set the camera image JPEG compression quality. Valid range is 0 to 100. Returns True on success. Only for the OV2640/OV5640 cameras.

sensor.set_colorbar(enable: bool) bool

Turns color bar test mode on (True) or off (False). Returns True on success.

sensor.set_auto_gain(enable: int, gain_db: float | None = None, gain_db_ceiling: float | None = None) None

enable turns auto gain control on (1) or off (0).

If enable is 0 you may set a fixed gain in decibels with gain_db.

If enable is non-zero you may set the maximum gain ceiling in decibels with gain_db_ceiling for the automatic gain control algorithm.

gain_db and gain_db_ceiling are keyword-only arguments.

sensor.get_gain_db() float

Returns the current camera gain value in decibels.

sensor.set_auto_exposure(enable: int, exposure_us: int = -1) None

enable turns auto exposure control on (1) or off (0).

If enable is 0 you may set a fixed exposure time in microseconds with exposure_us. exposure_us is a keyword-only argument.

sensor.get_exposure_us() int

Returns the current camera exposure value in microseconds.

sensor.set_auto_whitebal(enable: int, rgb_gain_db: Tuple[float, float, float] | None = None) None

enable turns auto white balance on (1) or off (0).

If enable is 0 you may set a fixed gain in decibels for the red, green, and blue channels respectively with rgb_gain_db. rgb_gain_db is 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.

enable is 1 to enable or 0 to disable.

regs if disabled, you can manually set the BLC register values via the values previously read from sensor.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.get_hmirror() bool

Returns True if horizontal mirror mode is enabled.

sensor.set_vflip(enable: bool) None

Turns vertical flip mode on (True) or off (False). Defaults to off.

sensor.get_vflip() bool

Returns True if vertical flip mode is enabled.

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.get_transpose() bool

Returns True if transpose mode is enabled.

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 an imu installed.

sensor.get_auto_rotation() bool

Returns True if auto rotation mode is enabled.

sensor.set_framebuffers(count: int) None

Sets the number of frame buffers used to receive image data.

count may be 1 (single buffer), 2 (double buffer), 3 (triple buffer), or 4 or greater to put the sensor driver into video FIFO mode where received frames are stored in a FIFO of count buffers.

sensor.get_framebuffers() int

Returns the current number of frame buffers allocated.

sensor.disable_delays(disable: bool | None = None) bool | None

If disable is True then disable all settling time delays in the sensor module.

If called with no arguments returns True if delays are disabled.

sensor.disable_full_flush(disable: bool | None = None) bool | None

If disable is True then automatic framebuffer flushing on frame drop is disabled.

If called with no arguments returns True if automatic flushing is disabled.

sensor.set_special_effect(sde: int) bool

Sets the special digital effect (SDE) on the sensor. sde is one of sensor.NORMAL or sensor.NEGATIVE. Returns True on success.

sensor.set_lens_correction(enable: bool, radi: int, coef: int) bool

enable True to enable, False to disable. radi integer radius of pixels to correct. coef power of correction.

Returns True on success.

sensor.set_vsync_callback(cb: Callable[[int], None] | None) None

Registers callback cb to be executed (in interrupt context) whenever the camera module generates a new frame (but before the frame is received).

cb takes 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 cb to be executed (in interrupt context) whenever the camera module generates a new frame and the frame is ready to be read via sensor.snapshot().

cb takes no arguments.

Pass a non-callable (e.g. None) to unregister.

sensor.ioctl(request: int, *args: Any) Any

Executes a sensor specific method. request is one of the IOCTL_* constants documented below. The remaining arguments and the return value depend on request:

sensor.set_color_palette(palette: int) None

Sets the color palette for the FLIR Lepton (and similar) grayscale to RGB565 conversion. palette is one of image.PALETTE_RAINBOW, image.PALETTE_IRONBOW, image.PALETTE_DEPTH, image.PALETTE_EVT_DARK, or image.PALETTE_EVT_LIGHT.

sensor.get_color_palette() int | None

Returns the current color palette setting, or None if the active palette is unrecognized.

sensor.__write_reg(address: int, value: int) None

Write value to camera register at address.

Note

See the camera data sheet for register info.

sensor.__read_reg(address: int) int

Read camera register at address.

Note

See the camera data sheet for register info.

Constants

sensor.BINARY: int

BINARY (bitmap) pixel format. Each pixel is 1-bit.

sensor.GRAYSCALE: int

GRAYSCALE pixel format (Y from YUV422). Each pixel is 8-bits, 1-byte.

sensor.RGB565: int

RGB565 pixel format. Each pixel is 16-bits, 2-bytes. 5-bits red, 6-bits green, 5-bits blue.

sensor.BAYER: int

RAW BAYER pixel format. 8-bits per pixel.

sensor.YUV422: int

YUV422 pixel format (8-bits Y1, 8-bits U, 8-bits Y2, 8-bits V, etc.).

sensor.JPEG: int

JPEG mode. Compressed JPEG output. Only works for the OV2640/OV5640 cameras.

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.QQCIF: int

88x72 resolution.

sensor.QCIF: int

176x144 resolution.

sensor.CIF: int

352x288 resolution.

sensor.QQSIF: int

88x60 resolution.

sensor.QSIF: int

176x120 resolution.

sensor.SIF: int

352x240 resolution.

sensor.QQQQVGA: int

40x30 resolution.

sensor.QQQVGA: int

80x60 resolution.

sensor.QQVGA: int

160x120 resolution.

sensor.QVGA: int

320x240 resolution.

sensor.VGA: int

640x480 resolution.

sensor.HQQQQVGA: int

40x20 resolution.

sensor.HQQQVGA: int

80x40 resolution.

sensor.HQQVGA: int

160x80 resolution.

sensor.HQVGA: int

240x160 resolution.

sensor.HVGA: int

480x320 resolution.

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.B160X160: int

160x160 resolution (for the HM01B0).

sensor.B320X320: int

320x320 resolution (for the HM01B0).

sensor.LCD: int

128x160 resolution (for use with the LCD shield).

sensor.QQVGA2: int

128x160 resolution (for use with the LCD shield).

sensor.WVGA: int

720x480 resolution (for the MT9V034).

sensor.WVGA2: int

752x480 resolution (for the MT9V034).

sensor.SVGA: int

800x600 resolution. Only for the OV2640/OV5640 cameras.

sensor.XGA: int

1024x768 resolution. Only for the OV2640/OV5640 cameras.

sensor.WXGA: int

1280x768 resolution (for the MT9M114).

sensor.SXGA: int

1280x1024 resolution. Only for the OV2640/OV5640 cameras.

sensor.SXGAM: int

1280x960 resolution (for the MT9M114).

sensor.UXGA: int

1600x1200 resolution. Only for the OV2640/OV5640 cameras.

sensor.HD: int

1280x720 resolution. Only for the OV2640/OV5640 cameras.

sensor.FHD: int

1920x1080 resolution. Only for the OV5640 camera.

sensor.QHD: int

2560x1440 resolution. Only for the OV5640 camera.

sensor.QXGA: int

2048x1536 resolution. Only for the OV5640 camera.

sensor.WQXGA: int

2560x1600 resolution. Only for the OV5640 camera.

sensor.WQXGA2: int

2592x1944 resolution. Only for the OV5640 camera.

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. See sensor.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. See sensor.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().

sensor.GENX320_BIASES_DEFAULT: int

Default biases preset for the GENX320.

sensor.GENX320_BIASES_LOW_LIGHT: int

Low-light biases preset for the GENX320.

sensor.GENX320_BIASES_ACTIVE_MARKER: int

Active-marker biases preset for the GENX320.

sensor.GENX320_BIASES_LOW_NOISE: int

Low-noise biases preset for the GENX320.

sensor.GENX320_BIASES_HIGH_SPEED: int

High-speed biases preset for the GENX320.

sensor.GENX320_BIAS_DIFF_OFF: int

GENX320 DIFF_OFF bias selector.

sensor.GENX320_BIAS_DIFF_ON: int

GENX320 DIFF_ON bias selector.

sensor.GENX320_BIAS_FO: int

GENX320 FO bias selector.

sensor.GENX320_BIAS_HPF: int

GENX320 HPF bias selector.

sensor.GENX320_BIAS_REFR: int

GENX320 REFR bias selector.