image – 图像处理

[English]

image 模块提供 Image 对象以及基于 OpenMV imlib 的视觉算法: 绘图、格式转换、滤波、颜色/色块分析,以及特征检测(直线、圆、矩形、二维码、 AprilTag)。编解码流类型 imageio.ImageIOimage.ImageIO – 图像流

当前 ESP32-P4 板级配置还会启用 ZXing-C++ 条形码后端和 image.Image.find_barcodes()

绘图与颜色色块追踪

import sensor

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=1000)

img = sensor.snapshot()
img.draw_rectangle(10, 10, 50, 50, color=(255, 0, 0))
thresholds = [(30, 100, 15, 127, 15, 127)]
for blob in img.find_blobs(thresholds, pixels_threshold=80, area_threshold=80):
    img.draw_rectangle(blob.rect(), color=(255, 0, 0), thickness=2)
    img.draw_cross(blob.cx(), blob.cy(), color=(0, 255, 0))

RGB565 阈值包含六个 LAB 范围值:(L_min, L_max, A_min, A_max, B_min, B_max)pixels_threshold 会过滤匹配像素过少的区域,area_threshold 会过滤外接矩形面积过小的区域。色块坐标以源图像像素为单位,可直接传给绘图方法。

滤波与二值分割

sensor.set_pixformat(sensor.GRAYSCALE)
img = sensor.snapshot()
img.gaussian(1)
img.binary([(80, 255)])
img.erode(1)
img.dilate(1)
img.flush()

gaussian() 在阈值处理前抑制高频噪声。binary() 将匹配的灰度值转换为有效二值,随后先腐蚀再膨胀可去除孤立像素并恢复主体区域。这些方法会原地修改图像。

二维码识别

sensor.set_pixformat(sensor.GRAYSCALE)
img = sensor.snapshot()
for code in img.find_qrcodes():
    img.draw_rectangle(code.rect(), color=255, thickness=2)
    print(code.payload())

find_qrcodes() 返回二维码的几何信息和解码内容。灰度输入通常可以降低处理开销;如果二维码只会出现在画面的固定区域,还可以指定较小的 ROI。

直线与圆检测

img = sensor.snapshot()
for line in img.find_lines(threshold=1400, theta_margin=25, rho_margin=25):
    img.draw_line(line.line(), color=255, thickness=2)

for circle in img.find_circles(threshold=2500, r_min=8, r_max=80, r_step=4):
    img.draw_circle(circle.x(), circle.y(), circle.r(), color=255, thickness=2)

检测阈值用于控制所需的累加器强度,提高阈值可减少较弱的检测结果。限制半径范围、ROI 或图像分辨率可以降低计算量,并通常能够提升稳定性。

编码并保存图像

import image

img = sensor.snapshot()
jpg = img.to_jpeg(quality=85, subsampling=image.JPEG_SUBSAMPLING_420)
jpg.save("/sdcard/snapshot.jpg")
print("encoded bytes:", jpg.size())

JPEG quality 用于权衡编码体积与图像细节,4:2:0 色度抽样通常可以得到更小的彩色图像。保存图像前,目标文件系统必须已经挂载且可写。

大多数原地操作的方法会返回图像本身,因此可以链式调用: img.to_grayscale().gaussian(1).binary([(128, 255)])

参见

关于这些方法背后的原理,参见 图像模型(像素格式、 色彩空间、帧缓冲)与 图像处理(滤波、阈值化、 特征检测)。

可运行示例:example/02-Image-Processing(绘图、滤波、颜色追踪、帧差分)、example/04-Barcodes(二维码)与 example/05-Feature-Detection(AprilTag、直线、圆)。

Constants

image.BINARY

1-bpp black-and-white pixel format (one bit per pixel).

image.GRAYSCALE

8-bit grayscale pixel format.

image.RGB565

16-bit RGB565 color pixel format.

image.BAYER

Raw Bayer mosaic pixel format from the sensor.

image.YUV422

Packed YUV422 pixel format.

image.JPEG

JPEG-compressed image format.

image.PNG

PNG-compressed image format.

image.PALETTE_RAINBOW

False-color rainbow palette (cold to hot).

image.PALETTE_IRONBOW

“Ironbow” thermal palette.

image.PALETTE_DEPTH

Depth-map palette.

image.PALETTE_EVT_DARK

Event-camera dark palette.

image.PALETTE_EVT_LIGHT

Event-camera light palette.

image.AREA

Scaling/geometry hint flags for copy()/crop()/scale()/draw_image(): area-average downscaling.

image.BILINEAR

Bilinear interpolation hint.

image.BICUBIC

Bicubic interpolation hint.

image.HMIRROR

Mirror horizontally.

image.VFLIP

Flip vertically.

image.TRANSPOSE

Swap X and Y (transpose).

image.CENTER

Center the source in the destination.

image.EXTRACT_RGB_CHANNEL_FIRST

Extract the RGB channel before applying the color palette.

image.APPLY_COLOR_PALETTE_FIRST

Apply the color palette before other steps.

image.SCALE_ASPECT_KEEP

Keep aspect ratio, fitting inside the destination.

image.SCALE_ASPECT_EXPAND

Keep aspect ratio, expanding to fill the destination.

image.SCALE_ASPECT_IGNORE

Ignore aspect ratio, stretching to the destination.

image.BLACK_BACKGROUND

Treat the background as black (needed for correct alpha blending).

image.ROTATE_90

Rotate 90 degrees.

image.ROTATE_180

Rotate 180 degrees.

image.ROTATE_270

Rotate 270 degrees.

image.JPEG_SUBSAMPLING_AUTO

Let the JPEG encoder pick chroma subsampling automatically.

image.JPEG_SUBSAMPLING_444

4:4:4 JPEG chroma subsampling (best quality).

image.JPEG_SUBSAMPLING_422

4:2:2 JPEG chroma subsampling.

image.JPEG_SUBSAMPLING_420

4:2:0 JPEG chroma subsampling (smallest size).

image.SEARCH_EX

Exhaustive template-search strategy.

image.SEARCH_DS

Diamond-search (faster, approximate) template-search strategy.

image.EDGE_CANNY

Canny edge-detection method for find_edges().

image.EDGE_SIMPLE

Simple gradient-threshold edge-detection method for find_edges().

image.CORNER_FAST

FAST corner detector for find_keypoints().

image.CORNER_AGAST

AGAST corner detector for find_keypoints().

image.EAN2

Barcode symbology constants returned by barcode.type() / accepted by find_barcodes().

image.EAN5
image.EAN8
image.UPCE
image.ISBN10
image.UPCA
image.EAN13
image.ISBN13
image.I25
image.DATABAR
image.DATABAR_EXP
image.CODABAR
image.CODE39
image.PDF417
image.CODE93
image.CODE128
image.TAG16H5

AprilTag family constants accepted by find_apriltags().

image.TAG25H7
image.TAG25H9
image.TAG36H10
image.TAG36H11

Functions

image.binary_to_grayscale(pixel)

Convert a 1-bpp binary pixel to a grayscale value.

image.binary_to_rgb(pixel)

Convert a 1-bpp binary pixel to an (r, g, b) tuple.

image.binary_to_lab(pixel)

Convert a 1-bpp binary pixel to a LAB tuple.

image.binary_to_yuv(pixel)

Convert a 1-bpp binary pixel to a YUV tuple.

image.grayscale_to_binary(pixel)

Convert a grayscale value to a 1-bpp binary pixel.

image.grayscale_to_rgb(pixel)

Convert a grayscale value to an (r, g, b) tuple.

image.grayscale_to_lab(pixel)

Convert a grayscale value to a LAB tuple.

image.grayscale_to_yuv(pixel)

Convert a grayscale value to a YUV tuple.

image.rgb_to_binary(pixel)

Convert an (r, g, b) color to a 1-bpp binary pixel.

image.rgb_to_grayscale(pixel)

Convert an (r, g, b) color to a grayscale value.

image.rgb_to_lab(pixel)

Convert an (r, g, b) color to a LAB tuple.

image.rgb_to_yuv(pixel)

Convert an (r, g, b) color to a YUV tuple.

image.lab_to_binary(pixel)

Convert a LAB tuple to a 1-bpp binary pixel.

image.lab_to_grayscale(pixel)

Convert a LAB tuple to a grayscale value.

image.lab_to_rgb(pixel)

Convert a LAB tuple to an (r, g, b) tuple.

image.lab_to_yuv(pixel)

Convert a LAB tuple to a YUV tuple.

image.yuv_to_binary(pixel)

Convert a YUV tuple to a 1-bpp binary pixel.

image.yuv_to_grayscale(pixel)

Convert a YUV tuple to a grayscale value.

image.yuv_to_rgb(pixel)

Convert a YUV tuple to an (r, g, b) tuple.

image.yuv_to_lab(pixel)

Convert a YUV tuple to a LAB tuple.

Classes

class image.line

A detected line segment with Hough-space attributes.

line()

Return the line as (x1, y1, x2, y2).

x1()

Start-point x coordinate.

y1()

Start-point y coordinate.

x2()

End-point x coordinate.

y2()

End-point y coordinate.

length()

Segment length in pixels.

magnitude()

Hough accumulator magnitude (line strength).

theta()

Line angle theta in degrees (Hough space).

rho()

Line distance rho in pixels (Hough space).

class image.circle

A detected circle.

circle()

Return the circle as (x, y, r).

x()

Center x coordinate.

y()

Center y coordinate.

r()

Radius in pixels.

magnitude()

Hough accumulator magnitude (circle strength).

class image.rect

A detected rectangle (quadrilateral).

corners()

Return the four corner points in clockwise order.

rect()

Return the bounding box as (x, y, w, h).

x()

Bounding-box top-left x.

y()

Bounding-box top-left y.

w()

Bounding-box width.

h()

Bounding-box height.

magnitude()

Detection strength.

class image.blob

A connected color region found by find_blobs().

corners()

The four bounding-box corners.

min_corners()

The four corners of the minimum-area enclosing rectangle.

rect()

Bounding box as (x, y, w, h).

x()

Bounding-box top-left x.

y()

Bounding-box top-left y.

w()

Bounding-box width.

h()

Bounding-box height.

pixels()

Number of pixels in the blob.

cx()

Centroid x (integer).

cxf()

Centroid x (float).

cy()

Centroid y (integer).

cyf()

Centroid y (float).

rotation()

Orientation of the blob’s major axis in radians.

rotation_deg()

Orientation in degrees.

rotation_rad()

Orientation in radians.

code()

Bitmask of the thresholds this blob matched.

count()

Number of blobs merged into this one.

perimeter()

Bounding-box perimeter.

roundness()

Roundness metric in [0, 1] (1 == circle).

elongation()

Elongation metric in [0, 1].

area()

Bounding-box area (w * h).

density()

Pixel density: pixels / area.

extent()

Alias of density().

compactness()

Compactness metric in [0, 1].

solidity()

Solidity (pixels / convex-hull area) in [0, 1].

convexity()

Convexity metric in [0, 1].

x_hist_bins()

Horizontal projection histogram bins.

y_hist_bins()

Vertical projection histogram bins.

major_axis_line()

Major-axis line as (x1, y1, x2, y2).

minor_axis_line()

Minor-axis line as (x1, y1, x2, y2).

enclosing_circle()

Minimum enclosing circle as (x, y, r).

enclosed_ellipse()

Best-fit enclosed ellipse as (x, y, rx, ry, rotation).

class image.qrcode

A decoded QR code found by find_qrcodes().

corners()

The four corner points.

rect()

Bounding box as (x, y, w, h).

x()

Bounding-box top-left x.

y()

Bounding-box top-left y.

w()

Bounding-box width.

h()

Bounding-box height.

payload()

Decoded payload string.

version()

QR version (size) number.

ecc_level()

Error-correction level.

mask()

Data mask pattern index.

data_type()

Encoding mode of the payload.

eci()

Extended Channel Interpretation value.

is_numeric()

True if the payload is numeric.

is_alphanumeric()

True if the payload is alphanumeric.

is_binary()

True if the payload is binary.

is_kanji()

True if the payload is Kanji.

class image.barcode

A decoded 1D/2D barcode found by find_barcodes().

corners()

The four corner points.

rect()

Bounding box as (x, y, w, h).

x()

Bounding-box top-left x.

y()

Bounding-box top-left y.

w()

Bounding-box width.

h()

Bounding-box height.

payload()

Decoded payload string.

type()

Symbology type constant (e.g. EAN13, CODE128).

rotation()

Rotation of the barcode in degrees.

quality()

Decode quality (number of agreeing scan lines).

class image.apriltag

A detected AprilTag with optional 6-DoF pose. Attributes are fields, not methods.

class image.histogram

Channel histogram returned by get_histogram(). For RGB565 the L/A/B channels correspond to the LAB color space.

bins()

Combined bins (grayscale/binary) or L bins (RGB565).

l_bins()

L-channel (lightness) bins.

a_bins()

A-channel bins (RGB565 only).

b_bins()

B-channel bins (RGB565 only).

get_percentile(p)

Return the value at the given cumulative percentile (0..1).

参数:

p – percentile in the range 0 to 1.

get_threshold()

Compute an Otsu threshold from the histogram.

get_stats()

Compute statistics (mean/median/mode/stdev/…) from the histogram.

get_statistics()

Alias of get_stats().

statistics()

Alias of get_stats().

class image.percentile

A percentile result from histogram.get_percentile().

value()

Combined/L value at the percentile.

l_value()

L-channel value.

a_value()

A-channel value.

b_value()

B-channel value.

class image.threshold

An Otsu threshold result from histogram.get_threshold().

value()

Combined/L threshold value.

l_value()

L-channel threshold.

a_value()

A-channel threshold.

b_value()

B-channel threshold.

class image.statistics

Region statistics returned by get_statistics(). Combined accessors apply to grayscale/binary; l_*/a_*/b_* apply to RGB565 LAB channels.

mean()
median()
mode()
stdev()
min()
max()
lq()

Lower quartile (25th percentile).

uq()

Upper quartile (75th percentile).

l_mean()
l_median()
l_mode()
l_stdev()
l_min()
l_max()
l_lq()
l_uq()
a_mean()
a_median()
a_mode()
a_stdev()
a_min()
a_max()
a_lq()
a_uq()
b_mean()
b_median()
b_mode()
b_stdev()
b_min()
b_max()
b_lq()
b_uq()
class image.Image(path, *, copy_to_fb=...)
class image.Image(width, height, pixformat, *, buffer=..., copy_to_fb=...)
class image.Image(array, *, buffer=..., copy_to_fb=...)

A 2D image backed by a pixel buffer. Create one from a file path, from a width/height/pixformat, or from an array; most often you get one from sensor.snapshot(). Most in-place methods return self so calls can be chained.

Load an image from a file (BMP/PPM/PGM/JPEG/PNG depending on build).

参数:
  • path – source file path.

  • copy_to_fb – True loads the decoded image into the frame buffer.

width()

Image width in pixels.

height()

Image height in pixels.

format()

Pixel format constant (BINARY/GRAYSCALE/RGB565/…).

size()

Size of the pixel buffer in bytes.

bytearray()

Return the pixel buffer as a bytearray (no copy).

get_pixel(x, y, *, rgbtuple=...)

Read one pixel. x, y: pixel coordinates.

参数:

rgbtuple – for RGB565, True returns an (r, g, b) tuple, False the packed value.

set_pixel(x, y, pixel)

Write one pixel. x, y: pixel coordinates.

参数:

pixel – grayscale value or (r, g, b) color.

flush()

Push this image to the host preview over USB CDC (EVFRAME JPEG stream).

save(path, *, roi=..., quality=...)

Save the image to a file; the format is inferred from the extension.

参数:
  • path – destination path.

  • roi – optional source rectangle (x, y, w, h).

  • quality – JPEG quality from 1 to 100 when saving as JPEG.

copy(*, roi=..., x_scale=..., y_scale=..., rgb_channel=..., alpha=..., color_palette=..., alpha_palette=..., hint=..., transform=..., copy=...)

Return a scaled/cropped/converted copy of the image. x_scale, y_scale: horizontal/vertical scale factors.

参数:
  • roi – source rectangle (x, y, w, h) to read from.

  • hint – bitwise OR of AREA/BILINEAR/BICUBIC/HMIRROR/VFLIP/TRANSPOSE/ROTATE_*/SCALE_ASPECT_* flags.

  • rgb_channel – extract a single RGB channel (0, 1, or 2; -1 for all).

  • alpha – blend alpha from 0 to 255.

  • copy – True returns a new image; False converts in place.

crop(*, roi=..., x_scale=..., y_scale=..., hint=..., copy=...)

Crop/scale the image to a region of interest. Same options as copy().

scale(*, x_scale=..., y_scale=..., roi=..., hint=..., copy=...)

Scale the image by x_scale/y_scale (alias of crop in this build).

compress(*, quality=..., subsampling=..., roi=...)

Compress the image to JPEG in place (alias of to_jpeg).

参数:
  • quality – JPEG quality from 1 to 100.

  • subsampling – one of the JPEG_SUBSAMPLING_* constants.

to_bitmap(*, copy=..., roi=...)

Convert to a 1-bpp bitmap.

to_grayscale(*, copy=..., roi=...)

Convert to grayscale.

to_rgb565(*, copy=..., roi=...)

Convert to RGB565.

to_rainbow(*, copy=..., roi=...)

Apply the rainbow palette and convert to RGB565.

to_ironbow(*, copy=..., roi=...)

Apply the ironbow thermal palette and convert to RGB565.

to_jpeg(*, quality=..., subsampling=..., copy=...)

Encode to JPEG.

参数:
  • quality – JPEG quality from 1 to 100.

  • subsampling – one of the JPEG_SUBSAMPLING_* constants.

to_png(*, copy=...)

Encode to PNG.

clear(*, mask=...)

Fill the image with zeros (optionally only where mask is set).

参数:

mask – optional 1-bpp image limiting which pixels are cleared.

draw_line(x0, y0, x1, y1, color=..., thickness=...)
draw_line(line, color=..., thickness=...)
draw_rectangle(x, y, w, h, color=..., thickness=..., fill=...)
draw_rectangle(rect, color=..., thickness=..., fill=...)
draw_circle(x, y, r, color=..., thickness=..., fill=...)
draw_circle(circle, color=..., thickness=..., fill=...)
draw_ellipse(x, y, rx, ry, rotation, color=..., thickness=..., fill=...)
draw_ellipse(ellipse, color=..., thickness=..., fill=...)
draw_string(x, y, text, color=..., scale=..., x_spacing=..., y_spacing=..., mono_space=..., char_rotation=..., char_hmirror=..., char_vflip=..., string_rotation=..., string_hmirror=..., string_vflip=...)

Draw text using the built-in bitmap font. x, y: top-left position of the text.

参数:
  • text – string to draw.

  • color – text color.

  • scale – integer/float scale factor of the font.

draw_cross(x, y, color=..., size=..., thickness=...)

Draw a cross marker centered at (x, y).

draw_arrow(x0, y0, x1, y1, color=..., size=..., thickness=...)
draw_arrow(line, color=..., size=..., thickness=...)
draw_edges(corners, color=..., size=..., thickness=..., fill=...)

Draw connecting edges between a sequence of corner points.

draw_keypoints(keypoints, color=..., size=..., thickness=..., fill=...)

Draw a set of keypoints.

draw_image(image, x=..., y=..., *, x_scale=..., y_scale=..., roi=..., rgb_channel=..., alpha=..., color_palette=..., alpha_palette=..., hint=..., transform=..., mask=...)

Alpha-blend/scale another image (or a solid color) onto this one. x, y: destination top-left position. x_scale, y_scale: scale factors; roi: source rectangle; alpha: 0..255;

参数:
  • image – source Image, an (r, g, b) tuple, or a packed scalar color.

  • hint – SCALE_ASPECT_*/interpolation flags; mask: optional 1-bpp mask.

binary(thresholds, *, invert=..., zero=..., mask=..., to_bitmap=..., copy=...)

Threshold the image into a binary mask against a list of color thresholds.

参数:
  • thresholds – list of grayscale (min, max) or LAB 6-tuple thresholds.

  • invert – invert the match.

  • zero – zero out matching pixels instead of setting them.

  • mask – optional 1-bpp image limiting the operation.

  • to_bitmap – output a 1-bpp bitmap.

  • copy – return a new image instead of modifying in place.

invert()

Invert pixel values.

erode(ksize, *, threshold=..., mask=...)

Morphological erosion with a (2*ksize+1) square structuring element.

参数:
  • ksize – structuring-element radius.

  • threshold – minimum number of set neighbors to keep a pixel.

  • mask – optional 1-bpp image limiting the operation.

dilate(ksize, *, threshold=..., mask=...)

Morphological dilation. See erode() for parameters.

open(ksize, *, threshold=..., mask=...)

Morphological opening (erode then dilate).

close(ksize, *, threshold=..., mask=...)

Morphological closing (dilate then erode).

difference(image, x=..., y=..., *, roi=..., mask=...)

Absolute per-pixel difference against another image/color (frame differencing). x, y: placement of the other image.

参数:

image – other Image, (r, g, b) tuple, or scalar color.

histeq(*, adaptive=..., clip_limit=..., mask=...)

Histogram equalization (global). adaptive is not supported in this build.

参数:

clip_limit – reserved; mask: optional 1-bpp image.

mean(ksize, *, threshold=..., offset=..., invert=..., mask=...)

Box (mean) blur over a (2*ksize+1) window. threshold/offset/invert: adaptive-threshold the result.

参数:
  • ksize – kernel radius.

  • mask – optional 1-bpp image.

median(ksize, *, percentile=..., threshold=..., offset=..., invert=..., mask=...)

Median filter (edge-preserving denoise).

参数:
  • ksize – kernel radius.

  • percentile – rank in [0, 1] to select (0.5 == median).

mode(ksize, *, threshold=..., offset=..., invert=..., mask=...)

Mode (most-common value) filter.

参数:

ksize – kernel radius.

midpoint(ksize, *, bias=..., threshold=..., offset=..., invert=..., mask=...)

Midpoint filter ((min + max)/2 blended by bias).

参数:

ksize – kernel radius; bias: 0 == min, 1 == max, 0.5 == midpoint.

morph(ksize, kernel, *, mul=..., add=..., threshold=..., offset=..., invert=..., mask=...)

Apply an arbitrary NxN convolution kernel.

参数:
  • ksize – kernel radius; the kernel must be (2*ksize+1) square.

  • kernel – flat or nested sequence of integer weights.

  • mul – output multiplier (defaults to 1/sum(kernel)); add: output bias.

blur(ksize, *, unsharp=..., mul=..., add=..., threshold=..., offset=..., invert=..., mask=...)

Gaussian blur using a separable Pascal-triangle kernel (alias: gaussian, gaussian_blur).

参数:
  • ksize – kernel radius.

  • unsharp – True turns the filter into an unsharp-mask sharpener.

gaussian(ksize, *, unsharp=..., mul=..., add=..., threshold=..., offset=..., invert=..., mask=...)

Gaussian blur. See blur() for parameters.

gaussian_blur(ksize, *, unsharp=..., mul=..., add=..., threshold=..., offset=..., invert=..., mask=...)

Gaussian blur. See blur() for parameters.

laplacian(ksize, *, sharpen=..., mul=..., add=..., threshold=..., offset=..., invert=..., mask=...)

Laplacian edge filter (or sharpener when sharpen is True).

参数:

ksize – kernel radius.

bilateral(ksize, *, color_sigma=..., space_sigma=..., threshold=..., offset=..., invert=..., mask=...)

Bilateral filter (edge-preserving smoothing).

参数:
  • ksize – kernel radius.

  • color_sigma – range sigma (color closeness); larger blurs across more contrast.

  • space_sigma – spatial sigma (distance closeness).

get_histogram(thresholds=..., *, invert=..., roi=..., bins=..., l_bins=..., a_bins=..., b_bins=..., difference=...)

Compute a channel histogram over the image or a region. bins / l_bins / a_bins / b_bins: bin counts; -1 selects the channel default.

参数:
  • thresholds – optional list of thresholds to restrict counted pixels.

  • invert – invert the threshold match.

  • roi – region of interest (x, y, w, h).

  • difference – optional image to histogram the difference against.

get_hist(thresholds=..., *, invert=..., roi=..., bins=..., l_bins=..., a_bins=..., b_bins=..., difference=...)

Alias of get_histogram().

histogram(thresholds=..., *, invert=..., roi=..., bins=..., l_bins=..., a_bins=..., b_bins=..., difference=...)

Alias of get_histogram().

get_statistics(thresholds=..., *, invert=..., roi=..., bins=..., l_bins=..., a_bins=..., b_bins=..., difference=...)

Compute region statistics (mean/median/mode/stdev/quartiles). thresholds/invert/roi/bins: as in get_histogram().

get_stats(thresholds=..., *, invert=..., roi=..., bins=..., l_bins=..., a_bins=..., b_bins=..., difference=...)

Alias of get_statistics().

statistics(thresholds=..., *, invert=..., roi=..., bins=..., l_bins=..., a_bins=..., b_bins=..., difference=...)

Alias of get_statistics().

get_regression(thresholds, *, invert=..., roi=..., x_stride=..., y_stride=..., area_threshold=..., pixels_threshold=..., robust=...)

Fit a line to the thresholded pixels via least-squares (or robust) regression. x_stride, y_stride: pixel sampling steps. area_threshold, pixels_threshold: minimum region area / pixel count to fit.

参数:
  • thresholds – list of color thresholds selecting the pixels to fit.

  • invert – invert the match; roi: region of interest.

  • robust – use a robust (Theil-Sen) estimator.

find_blobs(thresholds, *, invert=..., roi=..., x_stride=..., y_stride=..., area_threshold=..., pixels_threshold=..., merge=..., margin=..., threshold_cb=..., merge_cb=..., x_hist_bins_max=..., y_hist_bins_max=...)

Find connected color regions (blobs) matching the thresholds. x_stride, y_stride: pixel sampling steps. area_threshold, pixels_threshold: minimum bounding-box area / pixel count. threshold_cb / merge_cb: optional Python filter/merge callbacks.

参数:
  • thresholds – list of color thresholds.

  • invert – invert the match; roi: region of interest.

  • merge – merge overlapping blobs; margin: extra merge margin.

find_lines(*, roi=..., x_stride=..., y_stride=..., threshold=..., theta_margin=..., rho_margin=...)

Find straight lines with the Hough transform. theta_margin, rho_margin: merge tolerance for similar lines.

参数:
  • roi – region of interest; x_stride, y_stride: sampling steps.

  • threshold – minimum Hough accumulator magnitude to report a line.

find_circles(*, roi=..., x_stride=..., y_stride=..., threshold=..., x_margin=..., y_margin=..., r_margin=..., r_min=..., r_max=..., r_step=...)

Find circles with the Hough transform. x_margin, y_margin, r_margin: merge tolerances. r_min, r_max, r_step: radius search range and step.

参数:

threshold – minimum accumulator magnitude.

find_rects(*, roi=..., threshold=...)

Find rectangles/quadrilaterals (e.g. for fiducials).

参数:

threshold – minimum edge-magnitude score.

find_qrcodes(*, roi=...)

Find and decode QR codes.

参数:

roi – region of interest.

find_barcodes(*, roi=...)

Find and decode 1D/2D barcodes (requires the barcode backend).

参数:

roi – region of interest.

find_apriltags(*, roi=..., families=..., fx=..., fy=..., cx=..., cy=..., pose=...)

Find and decode AprilTags, optionally estimating 6-DoF pose. fx, fy, cx, cy: camera intrinsics for pose estimation.

参数:
  • roi – region of interest; families: OR of TAG* family constants.

  • pose – True computes translation/rotation (needs intrinsics).