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.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
Executes a sensor specific method.
requestis one of theIOCTL_*constants documented below. The remaining arguments and the return value depend onrequest:sensor.IOCTL_SET_READOUT_WINDOW- Pass a rect tuple(x, y, w, h)or a size tuple(w, h).sensor.IOCTL_GET_READOUT_WINDOW- Returns the current readout window rect tuple(x, y, w, h).sensor.IOCTL_SET_TRIGGERED_MODE- PassTrueorFalse.sensor.IOCTL_GET_TRIGGERED_MODE- Returns the current triggered-mode state as abool.sensor.IOCTL_SET_FOV_WIDE- PassTrueorFalseto optimizesensor.set_framesize()for field-of-view over FPS.sensor.IOCTL_GET_FOV_WIDE- Returns the current field-of-view-over-FPS optimization state as abool.sensor.IOCTL_SET_NIGHT_MODE- PassTrueorFalseto enable/disable night mode.sensor.IOCTL_GET_NIGHT_MODE- Returns the current night-mode state as abool.sensor.IOCTL_TRIGGER_AUTO_FOCUS- Triggers auto focus on the OV5640 FPC camera module.sensor.IOCTL_PAUSE_AUTO_FOCUS- Pauses auto focus on the OV5640 FPC camera module.sensor.IOCTL_RESET_AUTO_FOCUS- Resets auto focus on the OV5640 FPC camera module.sensor.IOCTL_WAIT_ON_AUTO_FOCUS- Waits for auto focus to finish on the OV5640 FPC camera module. Optional second argument is the timeout in milliseconds (default5000).sensor.IOCTL_LEPTON_GET_WIDTH- Returns the FLIR Lepton image width in pixels.sensor.IOCTL_LEPTON_GET_HEIGHT- Returns the FLIR Lepton image height in pixels.sensor.IOCTL_LEPTON_GET_RADIOMETRY- Returns the FLIR Lepton type (radiometric or not).sensor.IOCTL_LEPTON_GET_REFRESH- Returns the FLIR Lepton refresh rate in Hz.sensor.IOCTL_LEPTON_GET_RESOLUTION- Returns the FLIR Lepton ADC resolution in bits.sensor.IOCTL_LEPTON_RUN_COMMAND- Pass a 16-bit command id (FLIR Lepton SDK).sensor.IOCTL_LEPTON_SET_ATTRIBUTE- Pass the 16-bit attribute id and abytes/bytearraypayload (multiple of 16-bits).sensor.IOCTL_LEPTON_GET_ATTRIBUTE- Pass the 16-bit attribute id and the number of 16-bit words to read. Returns abytearray.sensor.IOCTL_LEPTON_GET_FPA_TEMP- Returns the FLIR Lepton FPA temperature in celsius.sensor.IOCTL_LEPTON_GET_AUX_TEMP- Returns the FLIR Lepton AUX temperature in celsius.sensor.IOCTL_LEPTON_SET_MODE- Passenablefollowed by an optionalhigh_tempflag.sensor.IOCTL_LEPTON_GET_MODE- Returns the tuple(measurement-mode-enabled, high-temp-enabled).sensor.IOCTL_LEPTON_SET_RANGE- Passmin_temp_candmax_temp_cfloats.sensor.IOCTL_LEPTON_GET_RANGE- Returns the sorted(min, max)2-tuple temperature range in celsius.sensor.IOCTL_HIMAX_MD_ENABLE- PassTrue/Falseto enable/disable motion detection on the HM01B0.sensor.IOCTL_HIMAX_MD_WINDOW- Pass a rect tuple(x, y, w, h)or a size tuple(w, h).sensor.IOCTL_HIMAX_MD_THRESHOLD- Pass a threshold value (0-255).sensor.IOCTL_HIMAX_MD_CLEAR- Clears the motion detection interrupt on the HM01B0.sensor.IOCTL_HIMAX_OSC_ENABLE- PassTrue/Falseto enable/disable the HM01B0 oscillator.sensor.IOCTL_GET_RGB_STATS- Returns the tuple(r, gb, gr, b)of RGB statistics from the camera sensor.sensor.IOCTL_GENX320_SET_BIASES- Pass one of theGENX320_BIASES_*constants to set the GENX320 sensor biases.sensor.IOCTL_GENX320_SET_BIAS- Pass one of theGENX320_BIAS_*constants and an integer bias value.sensor.IOCTL_GENX320_SET_AFK- Pass eitherenable(True/False) alone orenable,freq_low_in_hz,freq_high_in_hz.
- 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().