Image detection and recognition
Functions for object detection, image segmentation, text recognition, and subplot detection.
The functions in this topic are provided by the Python multimodal function library (VVR 11.8 or later). Before you use them, add the following statements at the beginning of the SQL deployment:
LOAD MODULE python;
USE MODULES python, core;
For complete examples and the IMAGE type, see Image function overview.
Function list
|
Function |
Description |
|
Detects objects by using YOLO |
|
|
Generates an image segmentation mask by using FastSAM |
|
|
Extracts text from an image by using EasyOCR |
|
|
Determines whether an image is a composite image and returns the number of subplots |
IMAGE_DETECT_OBJECTS
Detects objects by using YOLO.
IMAGE_DETECT_OBJECTS(image_input [, model [, confidence [, imgsz [, iou]]]])
|
Parameter |
Type |
Default value |
Description |
|
image_input |
|
Required |
The decoded image. |
|
model |
|
|
The name or path of the YOLO model. Note
Only the default model is supported. |
|
confidence |
|
|
The minimum detection confidence. Valid values: |
|
imgsz |
|
|
The inference resolution of the model. A larger value helps detect small objects, but also increases inference latency and resource consumption. |
|
iou |
|
|
The IoU threshold for NMS. Valid values: |
Return type: ARRAY<ROW<label STRING, x DOUBLE, y DOUBLE, w DOUBLE, h DOUBLE, confidence DOUBLE>>
Each element in the returned array represents a detection box:
|
Field |
Description |
|
|
The name of the object category. |
|
|
The coordinates of the upper-left corner of the detection box, in pixels. |
|
|
The width and height of the detection box, in pixels. |
|
|
The detection confidence. Value range: |
SELECT CARDINALITY(IMAGE_DETECT_OBJECTS(img, 'yolov8n', 0.25, 640, 0.5))
FROM images;
IMAGE_SEGMENT
Generates an image segmentation mask by using FastSAM.
IMAGE_SEGMENT(image_input [, model [, confidence [, imgsz [, iou]]]])
|
Parameter |
Type |
Default value |
Description |
|
image_input |
|
Required |
The decoded image. |
|
model |
|
|
The name or path of the FastSAM model. Note
Only the default model is supported. |
|
confidence |
|
|
The minimum confidence. Valid values: |
|
imgsz |
|
|
The inference resolution of the model. A larger value helps preserve mask details of small objects, but also increases inference latency and resource consumption. |
|
iou |
|
|
The IoU threshold for NMS. Valid values: |
Return type: BYTES, an 8-bit segmentation mask encoded in PNG. A pixel value of 0 indicates the background. Values from 1 to 255 indicate the numbers of different segmentation regions. The 255th and all subsequent regions all use the value 255.
SELECT IMAGE_SEGMENT(img, 'FastSAM-x.pt', 0.05, 1024, 0.5) FROM images;
IMAGE_OCR
Extracts text from an image by using EasyOCR.
IMAGE_OCR(image_input [, lang])
|
Parameter |
Type |
Default value |
Description |
|
image_input |
|
Required |
The decoded image. |
|
lang |
|
|
The language list. The current built-in model supports English recognition only. To recognize more languages, use general-purpose invocation. |
Return type: ARRAY<ROW<text STRING, confidence DOUBLE, bbox ARRAY<ARRAY<DOUBLE>>>>
Each element in the returned array represents a text region:
|
Field |
Description |
|
|
The recognized text content. |
|
|
The OCR confidence. The value usually ranges from |
|
|
The coordinates of the four corner points of the text region, in the form of |
SELECT IMAGE_OCR(img, ARRAY['en']) FROM images;
IMAGE_DETECT_SUBPLOT
Determines whether an image is a composite image, a grid image, or a subplot based on edge and grid features, and returns the estimated number of subplots.
IMAGE_DETECT_SUBPLOT(image_input [, threshold])
|
Parameter |
Type |
Default value |
Description |
|
image_input |
|
Required |
The decoded image. |
|
threshold |
|
|
The edge detection threshold. Valid values: |
Return type: ROW<is_subplot BOOLEAN, count INT>
|
Field |
Description |
|
|
Indicates whether a composite or subplot structure is detected. |
|
|
The estimated number of subplots. Returns 1 if the image is not a subplot. |
An image with any side smaller than 20 pixels directly returns is_subplot=FALSE and count=1.
SELECT IMAGE_DETECT_SUBPLOT(img).is_subplot, IMAGE_DETECT_SUBPLOT(img).count
FROM images;