yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
K230 Vision Module📖
1. Quick Start
  • 0.Get start
  • 1. K230 firmware download and burning
  • 2. Install the programming environment
  • 3. Debug and run routines
  • 4. Offline running routine
  • 5. Micropython Quick Start
  • 6. GUI Program Instructions
  • 7.K230 module bracket installation tutorial
  • 8.K230 module 2DOF PTZ installation tutorial
2. Basic Courses
  • 1.FPIOA pin assignment
  • 2.RGB lights
  • 3.Buzzer
  • 4.Buttons
  • 5.Serial communication
  • 6.I2C communication
  • 7.PWM
  • 8.WDT watchdog
  • 9.Timer
  • 10.Fourier Transform
  • 11.SHA256 encryption
  • 12.AES encryption
  • 13.Multithreading
  • 14.File reading and writing
  • 15.Image Display
  • 16.Touch Display
  • 17.Camera display
  • 18.Image Flip
  • 19.Camera
3. Draw the image
  • 1. Draw the lines
  • 2. Draw the circle
  • 3. Draw the rectangle
  • 4. Draw the ellipse
  • 5. Draw the arrow
  • 6. Draw the crosshairs
  • 7. Draw text
  • 8. Draw key points
4. Graphics detection
  • 1. Line segment detection
  • 2. Rectangle Detection
  • 3. Circle detection
  • 4. Object edge detection
  • 5. Line inspection basics:fast linear regression
5. Color recognition
  • 1. Color recognition
  • 2. Object Counting
  • 3. Multi-color recognition
  • 4. K230 Color Line Patrol
6.1 CV_lite Image Processing Special Topic
  • 1.Introduction to cv_litenew
  • 2.cv_lite API Reference Manualnew
  • 3.Color Block Recognition - Grayscale Imagenew
  • 4.Color Block Recognition - Color Imagenew
  • 5.Circle Recognition - Grayscale Imagenew
  • 6.Circle Recognition - Color Imagenew
  • 7.Corner Recognition - Grayscale Imagenew
  • 8.Corner Recognition - Color Imagenew
  • 9.Edge Recognition - Grayscale Imagenew
  • 10. Edge Recognition - Color Imagenew
  • 11. Rectangle Recognition - Grayscale Imagenew
  • 12.Rectangle Recognition - Color Imagenew
  • 13.Rectangle recognition combined with corner recognition - grayscale imagenew
  • 14.Rectangle recognition combined with corner recognition - color imagenew
  • 15.Image Binarization - Grayscalenew
  • 16.Image Binarization - Color Imagenew
  • 17.Exposure Adjustmentnew
  • 18.Image Black Hat Operationsnew
  • 19.Image Color Histogramnew
  • 20.Image Closingnew
  • 21.Image Expansionnew
  • 22.Image Corrosionnew
  • 23.Gaussian Blurnew
  • 24.Gradient Transformationnew
  • 25.Mean Fuzzynew
  • 26.Image Openingnew
  • 27.Image Top Hat Operationnew
  • 28.PnP rangingnew
  • 29.Find rectangles and measure distancesnew
  • 30.Image grayscale world white balancenew
6.2 OpenCV Image Processing Special Topicnew
  • 1. OpenCV Introduction
  • 2. OpenCV API Reference
  • 3. Image Basic Transforms
  • 4. Morphological Operations
  • 5. Color Segmentation and Shape Classification
  • 6. Corner and Centroid Detection
  • 7. Hough Circle Detection
  • 8. Hough Line Detection
  • 9. Contour Analysis
  • 10. Drawing Functions
  • 11. Template Matching
  • 12. Image Blur Filtering
  • 13. Edge Detection
  • 14. Thresholding
  • 15. Color Segmentation
  • 16. Histogram and Pixel Transformation
  • 17. Arithmetic and Bitwise Operations
  • 18. Channel Operation and Statistics
  • 19. Image File Read and Write
  • 20. Pixel Level Transformation
7. Code type recognition
  • 1.Barcode recognition
  • 2.QR code recognition
  • 3.AprilTag tag recognition
  • 4.DM code recognition
8. Face Recognition
  • 1.[Must-read] General code structure and prerequisite knowledge of AI vision routines
  • 2.Face Detection
  • 3.Facial key point recognition
  • 4.Face orientation detection
  • 5.Face 3D Network
  • 6.Gaze direction detection
  • 7.Register for face recognition
9. Human body characteristics
  • 1. Human body detection
  • 2. Human key point detection
  • 3. Human posture recognition
  • 4. Fall detection
  • 5. Palm detection
  • 6. Palm key point detection
  • 7. Palm key point classification
  • 8. Gesture Recognition
  • 9. Dynamic gesture recognition
  • 10. Rock, Paper, Scissors
10. Scenario Application
  • 1.OCR character detection
  • 2.OCR character recognition
  • 3.yolov8n target detection
  • 4.yolov8n segmentation
  • 5. Self-learning object recognition
  • 6. License plate detection
  • 7. License Plate Recognition
  • 8. Target Tracking
  • 9. Fruit classification
  • 10. Garbage classification
  • 11. Road sign recognition
11. Audio and video processing
  • 1. Audio Recording
  • 2. Play Audio
  • 3. Video Recording
  • 4. Play Video
  • 5. Keyword wake-up
12. Network Basics
  • 1. Wireless network connection
  • 2. AP hotspot mode
  • 3. TCP-Server Example
  • 4. TCP-Client Example
  • 5. UDP-Server Example
  • 6. UDP-Client Example
  • 7. HTTP-Server Example
  • 8. HTTP-Client Example
  • 9. MQTT Quick Start
  • 10. MQTT-Publisher
  • 11. MQTT-Subscriber
  • 12. RTSP real-time image transmission
  • 13. RTSP real-time image transmission combined with AIDemo
  • 14. Call OpenRouter large model aggregation service
  • 15. Open the Resource Monitoring Panel
13. LVGL Graphical Interface
  • 1. Introduction to LVGL
  • 2. Create a button
  • 3. Create a slider
  • 4. Create an Image
  • 5. Create a text box and keyboard
14. GUI Code Tutorial & Secondary Development
  • 01.GUI System Architecture
  • 02.Core Engine Initialization
  • 03.Application Discovery Mechanism in GUI
  • 04.Desktop Layout Algorithm
  • 05.Advanced UI Styling
  • 06.BaseApp Base Class Analysis
  • 07.Hello_World Practical
  • 08.GUI Application Lifecycle and Resource Management
15. Train your own model
  • 1. Local deployment of yolo training environment
  • 2. Use online platforms for training
16.Touch Course
  • 1.Touch point detectionnew
  • 2.Touch Paintingnew
  • 3.Touch to take a photonew
17. Multi-master communication (purchased separately)
ESP32-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
Jetson-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
MSPM0G3507-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
Pico-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
raspberrypi-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
RDK-K230
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
STM32-K230
  • 1. stm32_k230 color recognition
  • 2. stm32_k230 barcode recognition
  • 3. stm32_k230 QR code recognition
  • 4. stm32_k230Apriltag code recognition
  • 5. stm32_k230DM code recognition
  • 6. stm32_k230 face detection
  • 7.stm32_k230 looking direction
  • 8. stm32_k230 face recognition
  • 9. stm32_k230 human body detection
  • 10. stm32_k230 fall detection
  • 11. stm32_k230 palm detection
  • 12. stm32_k230 gesture recognition
  • 13. stm32_k230OCR character recognition
  • 14. stm32_k230 object detection
  • 15. stm32_k230 target tracking
  • 16. stm32_k230 self-learning object recognition
  • 17.stm32_k230 license plate recognition
Arduino-K230
  • 1.arduino_k230 color recognition
  • 2.arduino_k230 barcode recognition
  • 3.arduino_k230 QR code recognition
  • 4.arduino_k230 Apriltag code recognition
  • 5.arduino_k230 DM code recognition
  • 6.arduino_k230 face detection
  • 7.arduino_k230 looking direction
  • 8.arduino_k230 face recognition
  • 9.arduino_k230 human body detection
  • 10.arduino_k230 fall detection
  • 11.arduino_k230 palm detection
  • 12.arduino_k230 gesture recognition
  • 13.arduino_k230 OCR character recognition
  • 14.arduino_k230 object detection
  • 15.arduino_k230 target tracking
  • 16.arduino_k230 self-learning object recognition
  • 17.arduino_k230 license plate recognition
Microbit-K230
  • 1.microbit_k230 color recognition
  • 2.microbit_k230 barcode recognition
  • 3.microbit_k230 QR code recognition
  • 4.microbit_k230 Apriltag code recognition
  • 5.microbit_k230 DM code recognition
  • 6.microbit_k230 face detection
  • 7.microbit_k230 looking direction
  • 8.microbit_k230 face recognition
  • 9.microbit_k230 human body detection
  • 10.microbit_k230 fall detection
  • 11.microbit_k230 palm detection
  • 12.microbit_k230 gesture recognition
  • 13.microbit_k230 OCR character recognition
  • 14.microbit_k230 object detection
  • 15.microbit_k230 target tracking
  • 16.microbit_k230 self-learning object recognition
  • 17.microbit_k230 license plate recognition
MSPM0G3519-K230
  • 1. K230 Color Recognitionnew
  • 2. K230 Barcode Recognitionnew
  • 3. K230 QR Code Recognitionnew
  • 4. K230 Apriltag Code Recognitionnew
  • 5. K230 DM Code Recognitionnew
  • 6. K230 Face Detectionnew
  • 7. K230 Gaze Directionnew
  • 8. K230 Face Recognitionnew
  • 9. K230 Human Body Detectionnew
  • 10. K230 Fall Detectionnew
  • 11. K230 Palm Detectionnew
  • 12. K230 Gesture Recognitionnew
  • 13. K230 OCR Character Recognitionnew
  • 14. K230 Object Detectionnew
  • 15. K230 Target Trackingnew
  • 16. K230 Self-learning Object Recognitionnew
  • 17. K230 License Plate Recognitionnew
18.Extension case (purchase separately)
For 2DOF Electric Platform
  • 1.Moving target control and automatic tracking system
  • 2.Human body recognition alarm
  • 3.Gesture Recognition
  • 4.Rock Paper Scissors
  • 5.Fruit sorting
  • 6.Color Tracking
  • 7.Face Tracking
MSPM0G3507 wheeled chassis V1/V2 combined with K230 application case
  • 1.Visual tracking
  • 2.Color tracking
  • 3.Color response
  • 4.Road sign recognition
  • 5.Machine code tracking
  • 6.QR code recognition action
  • 7.Autonomous avoid
  • 8.License plate tracking
  • 9.Face tracking
  • 10.Gaze direction tracking
  • 11.Palm tracking
  • 12.Target tracking
  • 13.Human body tracking
  • 14.OCR character recognition action
STM32 wheeled chassis V1/V2 combined with K230 application case
  • 1.Visual tracking
  • 2.Color tracking
  • 3.Color response
  • 4.Road sign recognition
  • 5.Machine code tracking
  • 6.QR code recognition action
  • 7.Autonomous avoid
  • 8.License plate tracking
  • 9.Face tracking
  • 10.Gaze direction tracking
  • 11.Palm tracking
  • 12.Target tracking
  • 13.Human body tracking
  • 14.OCR character recognition action
MSPM0G3519 wheeled chassis V1/V2 combined with K230 application case
  • 1.Visual trackingnew
  • 2.Color trackingnew
  • 3.Color responsenew
  • 4.Road sign recognitionnew
  • 5.Machine code trackingnew
  • 6.QR code recognition actionnew
  • 7.Autonomous avoidnew
  • 8.License plate trackingnew
  • 9.Face trackingnew
  • 10.Gaze direction trackingnew
  • 11.Palm trackingnew
  • 12.Target trackingnew
  • 13.Human body trackingnew
  • 14.OCR character recognition actionnew
19. Expansion case(purchase separately)new
  • 1.Motion target control and Auto track system
  • 2.Vehicle-mounted balance ball motion control system
Download
  • Manual
  • CanMV IDE
  • Software Tools
  • Firmware
  • Source Code
  • Appendix
Download ZIP

Welcome to K230 Vision Module repository

2.cv_lite API Reference Manual

cv_lite API Reference Manual

This manual is sourced from the Canaan Technology official website and is backed up here for your convenience. Due to version iterations and other factors, the APIs in this manual are not guaranteed to be fully functional. All API methods that have been tested and confirmed to be functional will be presented as tutorials in subsequent sections of this chapter.

cv_lite API Reference ManualAPI Introductiongrayscale_find_blobsrgb888_find_blobsgrayscale_find_circlesrgb888_find_circlesgrayscale_find_rectanglesrgb888_find_rectanglesgrayscale_find_edgesrgb888_find_edgesgrayscale_threshold_binaryrgb888_threshold_binaryrgb888_adjust_exposurergb888_adjust_exposure_fastrgb888_white_balance_gray_world_fastrgb888_white_balance_gray_world_fast_exrgb888_white_balance_white_patchrgb888_white_balance_white_patch_exrgb888_erodergb888_dilatergb888_openrgb888_closergb888_tophatrgb888_blackhatrgb888_gradientrgb888_mean_blurrgb888_gaussian_blurrgb888_calc_histogramrgb888_find_corners

API Introduction

grayscale_find_blobs

Description

Finds blobs (connected regions) in a grayscale image and returns their locations.

Syntax

Please ensure that the sensor is configured to output grayscale images, otherwise an error will occur.

​x
import cv_lite
​
image_shape = [480,640]  # Height, width
​
threshold = [230, 255]   # Binarization threshold range (bright area)
min_area = 10            # Minimum target area
kernel_size = 1          # Corrosion kernel size (can be used for noise reduction)
​
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get image data reference
​
# Perform binary connected domain detection on grayscale images
blobs = cv_lite.grayscale_find_blobs(image_shape, img_np,threshold[0], threshold[1],min_area, kernel_size)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
threshold_minMinimum value of the binarization threshold, int typeInput 
threshold_maxMaximum value of the binarization threshold, int typeInput 
min_areaMinimum area of the region, int typeInput 
kernel_sizeKernel size, int typeInput 

Return Value

Return ValueDescription
blobsList of blob location information, each containing 4 elements representing the location of a blob, including x, y, w, and h.

rgb888_find_blobs

Description

Finds blobs (connected regions) in an RGB888 image and returns their locations.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
​
image_shape = [480,640]  # Height, width
​
threshold = [120, 255, 0, 50, 0, 50]
​
min_area = 100    # Minimum color block area
kernel_size = 1   # Corrosion dilation kernel size (for preprocessing)
​
# Capture a frame of image
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get a reference to an RGB888 ndarray
​
# Call the cv_lite extension to perform color block detection and return a list of [x, y, w, h, ...]
blobs = cv_lite.rgb888_find_blobs(image_shape, img_np, threshold, min_area, kernel_size)

Parameters

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
thresholdBinarization threshold range, list type, including the threshold ranges for the R, G, and B channelsInput 
min_areaMinimum region area, int typeInput 
kernel_sizeKernel size, int typeInput 

Return Value

Return ValueDescription
blobsBlob location information list, each containing 4 elements representing the location of a blob, including the x, y, w, and h positions

grayscale_find_circles

Description

Finds a circle in a grayscale image and returns its location.

Syntax

Please ensure that the sensor is configured to output a grayscale image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Hough circle detection parameters
# -------------------------------
dp = 1            # Inverse ratio of resolution
minDist = 20      #  Minimum distance between centers
param1 = 80       #  Upper threshold for Canny edge detector
param2 = 20       #  Accumulator threshold for center detection
minRadius = 10    #  Minimum radius to detect
maxRadius = 50    #  Maximum radius to detect
​
#  Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  #  Get image data reference
​
# Detect circles using Hough Transform
# Return format: [x1, y1, r1, x2, y2, r2, ...]
circles = cv_lite.grayscale_find_circles(image_shape, img_np,dp, minDist,param1, param2,
minRadius, maxRadius)
​

Parameters

Parameter NameDescriptionInput/OutputExplanation
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
dpAccumulator resolution ratio, float typeInput 
minDistMinimum distance from circle center, int typeInput 
param1Canny high threshold, int typeInput 
param2Accumulator threshold, int typeInput 
minRadiusMinimum circle radius, int typeInput 
maxRadiusMaximum circle radius, int typeInput 

Return Value

Return ValueDescription
circlesA list of circle information. Each 3 elements represent the information of a circle, including the x, y, and r positions.

rgb888_find_circles

Description

Finds a circle in an RGB888 image and returns its location.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
#  Hough Circle parameters
# -------------------------------
dp = 1           # Inverse ratio of accumulator resolution
minDist = 30     # Minimum distance between detected centers
param1 = 80      # Higher threshold for Canny edge detection
param2 = 20      # Threshold for center detection in accumulator
minRadius = 10   # Minimum circle radius
maxRadius = 50   # Maximum circle radius
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get a reference to an RGB888 ndarray
​
# Call the Hough circle detection function extended by cv_lite and return the circle parameter list [x, y, r, ...]
circles = cv_lite.rgb888_find_circles(image_shape, img_np, dp, minDist, param1, param2, minRadius, maxRadius)
​

Parameters

Parameter NameDescriptionInput/OutputExplanation
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
dpInverse ratio of accumulator resolution to image resolution, float typeInput 
minDistMinimum distance to the detected circle center, int typeInput 
param1Canny edge detection high threshold, int typeInput 
param2Hough transform circle center detection threshold, int typeInput 
minRadiusMinimum radius of the detected circle, int typeInput 
maxRadiusMaximum radius of the detected circle, int typeInput 

Return Value

Return ValueDescription
circlesA list of circle information. Each 3 elements represents a circle, including its x, y, and r positions.

grayscale_find_rectangles

Description

Finds a rectangle in a grayscale image and returns its location.

Syntax

Please ensure that the sensor is configured to output grayscale images, otherwise an error will occur.

xxxxxxxxxx
import cv_lite
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Adjustable rectangle detection parameters
# -------------------------------
canny_thresh1      = 50        # Canny low threshold
canny_thresh2      = 150       # Canny high threshold
approx_epsilon     = 0.04      # Polygon approximation accuracy
area_min_ratio     = 0.001     # Min area ratio
max_angle_cos      = 0.3       # Max cosine of angle between edges
gaussian_blur_size = 5         # Gaussian blur kernel size
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()
​
# Call the underlying rectangle detection function
# Return format:[x0, y0, w0, h0, x1, y1, w1, h1, ...]
rects = cv_lite.grayscale_find_rectangles(
    image_shape, img_np,
    canny_thresh1, canny_thresh2,
    approx_epsilon,
    area_min_ratio,
    max_angle_cos,
    gaussian_blur_size
)

Parameter

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
canny_thresh1Canny edge detection lower threshold, int typeInput 
canny_thresh2Canny edge detection upper threshold, int typeInput 
approx_epsilonPolygon fitting accuracy ratio, float typeInput 
area_min_ratioMinimum area ratio, float typeInput 
max_angle_cosMaximum angle cosine, float typeInput 
gaussian_blur_sizeGaussian blur kernel size, int typeInput 

Return Value

Return ValueDescription
rectsA list of rectangle position information, each containing 4 elements representing the position of a rectangle, including x, y, w, and h.

rgb888_find_rectangles

Description

Finds a rectangle in an RGB888 image and returns its location.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Adjustable parameters (recommended for tuning)
# -------------------------------
canny_thresh1       = 50        # Canny edge low threshold
canny_thresh2       = 150       # Canny edge high threshold
approx_epsilon      = 0.04      # Polygon approximation precision (ratio)
area_min_ratio      = 0.001     # Minimum area ratio (0~1)
max_angle_cos       = 0.5       # Max cosine of angle (smaller closer to rectangle)
gaussian_blur_size  = 5         # Gaussian blur kernel size (odd number)
​
# Capture current frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get RGB888 ndarray reference
​
# Call the underlying rectangle detection function and return a rectangle list [x0, y0, w0, h0, x1, y1, w1, h1, ...]
# Call underlying rectangle detection function, returns list of rectangles [x, y, w, h, ...]
rects = cv_lite.rgb888_find_rectangles(
    image_shape, img_np,
    canny_thresh1, canny_thresh2,
    approx_epsilon,
    area_min_ratio,
    max_angle_cos,
    gaussian_blur_size
)

Parameter

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
canny_thresh1Canny edge detection lower threshold, int typeInput 
canny_thresh2Canny edge detection upper threshold, int typeInput 
approx_epsilonPolygon fitting accuracy ratio, float typeInput 
area_min_ratioMinimum area ratio, float typeInput 
max_angle_cosMaximum angle cosine, float typeInput 
gaussian_blur_sizeGaussian blur kernel size, int typeInput 

Return Value

Return ValueDescription
rectsA list of rectangle position information, each containing 4 elements representing the position of a rectangle, including x, y, w, and h.

grayscale_find_edges

Description

Find edges in a grayscale image and return the edge-detected image as a ulab.numpy.ndarray. You can create an Image instance based on the returned data.

Syntax

Please ensure that the output image in the Sensor configuration is grayscale; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Canny edge detection thresholds
# -------------------------------
threshold1 = 50  # Lower threshold
threshold2 = 80  # Upper threshold
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get ndarray reference
​
# Call the cv_lite extension to perform edge detection
# Returns edge image ndarray
edge_np = cv_lite.grayscale_find_edges(
    image_shape, img_np, threshold1, threshold2)
​
# Wrap ndarray as image for display
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=edge_np)

Parameters

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
threshold1Low threshold, int typeInput 
threshold2High threshold, int typeInput 

Return Value

Return ValueDescription
edge_npImage data after edge detection, ulab.numpy.ndarray type, used to create an image instance

rgb888_find_edges

Description

Find edges in an RGB888 image and return the edge-detected image data as a ulab.numpy.ndarray. You can then create an Image instance from this data.

Syntax

Please ensure that the output image in the Sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Canny edge detection thresholds
# -------------------------------
threshold1 = 50  # Lower threshold
threshold2 = 80  # Upper threshold
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get a reference to an RGB888 ndarray
​
# Call the edge detection function of the cv_lite extension and return the grayscale edge map ndarray
edge_np = cv_lite.rgb888_find_edges(image_shape, img_np, threshold1, threshold2)
​
# Construct a grayscale image object for display
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE, alloc=image.ALLOC_REF, data=edge_np)

Parameters

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
threshold1Low threshold, int typeInput 
threshold2High threshold, int typeInput 

Return Value

Return ValueDescription
edge_npImage data after edge detection, ulab.numpy.ndarray type, used to create an image instance

grayscale_threshold_binary

Description

Binarizes a grayscale image and returns the binarized image data as a ulab.numpy.ndarray. This data can be used to create an Image instance.

Syntax

Please ensure that the output image of the Sensor configuration is grayscale; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Binary threshold parameters
# -------------------------------
thresh = 130   # Threshold value
maxval = 255   # Max value for white pixels
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get ndarray reference
​
# Call the cv_lite extension for binarization
# Returns binary image ndarray
binary_np = cv_lite.grayscale_threshold_binary(image_shape, img_np, thresh, maxval)
​
# Wrap ndarray as grayscale image for display
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=binary_np)

Parameters

Parameter NameDescriptionInput/OutputExplanation
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
threshThreshold, int typeInput 
maxvalMaximum value, int typeInput 

Return Value

Return ValueDescription
binary_npBinarized image data, ulab.numpy.ndarray type, creates an image instance based on this data

rgb888_threshold_binary

Description

Binarizes an RGB888 image and returns the binarized image data as a ulab.numpy.ndarray. This data can be used to create an Image instance.

Syntax

Please ensure that the output image in the Sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Binary threshold parameters
# -------------------------------
thresh = 130   # Threshold value
maxval = 255   # Max value for white pixels
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get ndarray reference
​
# Call binary threshold function (returns ndarray)
binary_np = cv_lite.rgb888_threshold_binary(image_shape, img_np, thresh, maxval)
​
# Construct grayscale image for display
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=binary_np)

Parameters

Parameter NameDescriptionInput/OutputExplanation
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
threshThreshold, int typeInput 
maxvalMaximum value, int typeInput 

Return Value

Return ValueDescription
binary_npBinarized image data, ulab.numpy.ndarray type, creates an image instance based on this data

rgb888_adjust_exposure

Description

Adjusts the exposure of an RGB888 image and returns the adjusted image data as a ulab.numpy.ndarray. This data can be used to create an Image instance for display.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Exposure gain factor (<1 decreases brightness, >1 increases brightness)
# -------------------------------
exposure_gain = 2.5          # Recommended range: 0.2~3.0, 1.0 = no gain
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get RGB888 ndarray reference (HWC)
​
# Apply exposure adjustment using cv_lite module
exposed_np = cv_lite.rgb888_adjust_exposure(image_shape, img_np, exposure_gain)
​
# Wrap processed image for display
img_out = image.Image(image_shape[1], image_shape[0], image.RGB888,
                        alloc=image.ALLOC_REF, data=exposed_np)

Parameters

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
exposure_gainExposure gain factor, float typeInput 

Return Value

Return ValueDescription
exposed_npImage data after exposure adjustment, ulab.numpy.ndarray type, creates an image instance based on this data

rgb888_adjust_exposure_fast

Description

Quickly adjusts the exposure of an RGB888 image, returning the adjusted image data in a ulab.numpy.ndarray. This data can be used to create an Image instance for display. This method is an accelerated version of the software exposure method described above.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# Exposure adjustment parameters
# exposure_gain: Exposure gain factor, recommended range: 0.2 to 3.0
# A value less than 1.0 reduces exposure (darkening), while a value greater than 1.0 increases exposure (brightening).
# exposure_gain < 1.0: darker, > 1.0: brighter
# -------------------------------
exposure_gain = 2.5  # Example: brighten image by 1.5x
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get RGB888 ndarray (HWC)
​
# Apply exposure gain using cv_lite
exposed_np = cv_lite.rgb888_adjust_exposure_fast(
    image_shape,
    img_np,
    exposure_gain
)
​
# Wrap processed image for display
img_out = image.Image(image_shape[1], image_shape[0], image.RGB888,
                        alloc=image.ALLOC_REF, data=exposed_np)

Parameters

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
exposure_gainExposure gain factor, float typeInput 

Return Value

Return ValueDescription
exposed_npImage data after exposure adjustment, ulab.numpy.ndarray type, creates an image instance based on this data

rgb888_white_balance_gray_world_fast

Description

Quickly white balances an RGB888 image using the grayscale world algorithm. Returns the white-balanced image data in a ulab.numpy.ndarray format, which can be used to create an Image instance for display. This method is an accelerated version of the software white balance method described above.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get RGB888 ndarray reference (HWC)
​
# Accelerated grayscale world white balancing using cv_lite
# Apply fast gray world white balance
balanced_np = cv_lite.rgb888_white_balance_gray_world_fast(image_shape, img_np)
​
# Wrap processed image for display
img_out = image.Image(image_shape[1], image_shape[0], image.RGB888,alloc=image.ALLOC_REF, data=balanced_np)

Parameters

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 

Return Value

Return ValueDescription
balanced_npWhite-balanced image data, ulab.numpy.ndarray type, used to create an image instance

rgb888_white_balance_gray_world_fast_ex

Description

Quickly white balances an RGB888 image using the grayscale world algorithm, returning the white-balanced image data in a ulab.numpy.ndarray. This data can be used to create an Image instance for display. This method is a parameter-adjustable version of the above method.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# White balance parameters
# -------------------------------
gain_clip = 2.5             # Gain limit to prevent color blowout
brightness_boost = 1.25     # Global brightness boost
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get RGB888 ndarray reference (HWC)
​
# Accelerated grayscale world white balance processing using cv_lite (adjustable parameters)
# Apply fast gray world white balance with tunable parameters
balanced_np = cv_lite.rgb888_white_balance_gray_world_fast_ex(
    image_shape,
    img_np,
    gain_clip,
    brightness_boost
)
​
# Wrap processed image for display
img_out = image.Image(image_shape[1], image_shape[0], image.RGB888,
                        alloc=image.ALLOC_REF, data=balanced_np)

Parameter

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
gain_clipGain limit coefficient, float typeInput 
brightness_boostBrightness boost coefficient, float typeInput 

Return Value

Return ValueDescription
balanced_npWhite-balanced image data, ulab.numpy.ndarray type, from which an image instance can be created for display

rgb888_white_balance_white_patch

Description

Uses the white patch algorithm to white balance an RGB888 image, returning the white-balanced image data as a ulab.numpy.ndarray. This data can be used to create an Image instance for display.

Syntax

Please ensure that the output image of the sensor is configured as an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# Capture a frame of image
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # RGB888 raw image
​
# Call the cv_lite extension module for white patch white balancing
balanced_np = cv_lite.rgb888_white_balance_white_patch(image_shape, img_np)
​
# Construct RGB888 display image
img_out = image.Image(image_shape[1], image_shape[0], image.RGB888,
                        alloc=image.ALLOC_REF, data=balanced_np)

Parameters

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 

Return Value

Return ValueDescription
balanced_npWhite-balanced image data, ulab.numpy.ndarray type, used to create an image instance

rgb888_white_balance_white_patch_ex

Description

Uses the white patch algorithm to white balance an RGB888 image, returning the white-balanced image data in a ulab.numpy.ndarray. This data can be used to create an Image instance for display. This method is a parameter-adjustable version of the above method.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640]  # Height, width
​
# -------------------------------
# White balance parameters
# -------------------------------
top_percent = 5.0          # Percentage of brightest pixels used for white point estimation 
gain_clip = 2.5            # Maximum gain limit
brightness_boost = 1.1     # Brightening Factor
​
# Capture one frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get image data reference (ulab ndarray)
​
# Perform white point white balancing
balanced_np = cv_lite.rgb888_white_balance_white_patch_ex(
    image_shape, img_np,
    top_percent,
    gain_clip,
    brightness_boost
)
​
# Wrapping images for display
img_out = image.Image(image_shape[1], image_shape[0], image.RGB888,
                        alloc=image.ALLOC_REF, data=balanced_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
top_percentPercentage of the brightest pixels used for white point estimation, float typeInput 
gain_clipMaximum gain limit, float typeInput 
brightness_boostBrightness boost factor, float typeInput 

Return Value

Return ValueDescription
balanced_npImage data after white balance, ulab.numpy.ndarray type. Create an image instance based on this data for display

rgb888_erode

Description

Applies an erosion operation to an RGB888 image, returning the eroded single-channel image data as a ulab.numpy.ndarray. This data can be used to create an Image instance for display.

Syntax

Please ensure that the output image in the Sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
​
# -------------------------------
# Corrosion algorithm parameter settings
# -------------------------------
kernel_size = 3         # Convolution kernel size (must be an odd number, such as 3, 5, 7)
iterations = 1          # Erosion iterations
threshold_value = 100   # Binarization threshold (0 = use Otsu automatic thresholding)
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get a reference to an RGB888 ndarray
​
# Apply an erosion operation (after automatic conversion to grayscale)
eroded_np = cv_lite.rgb888_erode(
    image_shape,
    img_np,
    kernel_size,
    iterations,
    threshold_value
)
​
# Construct an image for display (grayscale format)
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=eroded_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 
iterationsNumber of erosion iterations, int typeInput 
threshold_valueBinarization threshold, int typeInput 

Return Value

Return ValueDescription
eroded_npImage data after erosion, ulab.numpy.ndarray type

rgb888_dilate

Description

Applies a dilation operation to an RGB888 image, returning the dilated single-channel image data as a ulab.numpy.ndarray. This data can be used to create an Image instance for display.

Syntax

Please ensure that the output image of the sensor is configured as RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640] # Height, width
​
# -------------------------------
# Dilation algorithm parameter settings
# -------------------------------
kernel_size = 3         # Convolution kernel size (Odd numbers are recommended, but some implementations support even numbers)
iterations = 1          # Dilation iterations
threshold_value = 100   # Binarization threshold (0 = use Otsu automatic thresholding)
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # 获取 RGB888 ndarray 引用 / Get RGB888 ndarray reference
​
# Apply dilation (convert to grayscale internally before dilation)
result_np = cv_lite.rgb888_dilate(
    image_shape,
    img_np,
    kernel_size,
    iterations,
    threshold_value
)
​
# Construct an image for display (grayscale format)
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=result_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 
iterationsNumber of dilation iterations, int typeInput 
threshold_valueBinarization threshold, int typeInput 

Return Value

Return ValueDescription
dilated_npDilated image data, ulab.numpy.ndarray type

rgb888_open

Description

Performs an opening operation on an RGB888 image, returning the resulting single-channel image data as a ulab.numpy.ndarray. This data can be used to create an image instance for display.

Syntax

Please ensure that the output image in the sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640] # Height, width
​
# -------------------------------
# Open operation parameter settings
# -------------------------------
kernel_size = 3         # Convolution kernel size (should be an odd number)
iterations = 1          # Number of operation iterations
threshold_value = 100   # Binarization threshold (0 = use Otsu automatic thresholding)
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get a reference to an RGB888 ndarray
​
# Perform an opening operation (erode first and then dilate)
open_np = cv_lite.rgb888_open(
    image_shape,
    img_np,
    kernel_size,
    iterations,
    threshold_value
)
​
# Construct a grayscale image object for display
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=open_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 
iterationsNumber of opening iterations, int typeInput 
threshold_valueBinarization threshold, int typeInput 

Return Value

Return ValueDescription
opened_npImage data after opening, ulab.numpy.ndarray type

rgb888_close

Description

Applies a closed RGB888 image, returning the closed single-channel ulab.numpy.ndarray image data. This data can be used to create an Image instance for display.

Syntax

Please ensure that the output image of the sensor is configured as RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640] # Height, width
​
# -------------------------------
# Closed operation parameter settings
# -------------------------------
kernel_size = 3         # Convolution kernel size (odd number recommended)
iterations = 1          # Number of operation iterations
threshold_value = 100   # Binarization threshold (0 = use Otsu automatic thresholding)
​
# Get image frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get a reference to an RGB888 ndarray
​
# Apply a closing operation (dilation followed by erosion)
closed_np = cv_lite.rgb888_close(
    image_shape,
    img_np,
    kernel_size,
    iterations,
    threshold_value
)
​
# Construct an image object (grayscale image) for display
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=closed_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 
iterationsNumber of closing iterations, int typeInput 
threshold_valueBinarization threshold, int typeInput 

Return Value

Return ValueDescription
closed_npImage data after closing operation, ulab.numpy.ndarray type

rgb888_tophat

Description

Performs a top-hat operation on an RGB888 image, returning the resulting single-channel ulab.numpy.ndarray image data. You can create an image instance based on this data for display.

Syntax

Please ensure that the output image in the Sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640] # Height, width
​
# -------------------------------
# Top hat operation parameter settings
# -------------------------------
kernel_size = 3         # Convolution kernel size (odd number recommended)
iterations = 1          # Number of operation iterations
threshold_value = 100   # Binarization threshold (0 = use Otsu automatic thresholding)
​
# Get a frame of image and convert it into ndarray
img = sensor.snapshot()
img_np = img.to_numpy_ref()
​
# Perform top-hat operation
# Top hat = original image - opening operation result
tophat_np = cv_lite.rgb888_tophat(
    image_shape,
    img_np,
    kernel_size,
    iterations,
    threshold_value
)
​
# Construct an image object and display it
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=tophat_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 
iterationsNumber of top-hat operation iterations, int typeInput 
threshold_valueBinarization threshold, int typeInput 

Return Value

Return ValueDescription
tophat_npImage data after top-hat operation, ulab.numpy.ndarray type

rgb888_blackhat

Description

Performs a blackhat operation on an RGB888 image, returning the resulting single-channel image data as a ulab.numpy.ndarray. This data can be used to create an Image instance for display.

Syntax

Please ensure that the output image in the Sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640] # Height, width
​
# -------------------------------
# Black hat operation parameter settings
# -------------------------------
kernel_size = 3         # Convolution kernel size (odd number recommended)
iterations = 1          # Number of operation iterations
threshold_value = 100   # Binarization threshold (0 = use Otsu automatic thresholding)
​
# Capture a frame and convert to ndarray
img = sensor.snapshot()
img_np = img.to_numpy_ref()
​
# Perform black hat operations
# Black hat = closing operation - original image
blackhat_np = cv_lite.rgb888_blackhat(
    image_shape,
    img_np,
    kernel_size,
    iterations,
    threshold_value
)
​
# Construct an image object and display it
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=blackhat_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 
iterationsNumber of blackhat operation iterations, int typeInput 
threshold_valueBinarization threshold, int typeInput 

Return Value

Return ValueDescription
blackhat_npImage data after blackhat operation, ulab.numpy.ndarray type

rgb888_gradient

Description

Applies a morphological gradient operation to an RGB888 image, returning a single-channel ulab.numpy.ndarray image data after the morphological gradient. This data can be used to create an Image instance for display.

Syntax

Please ensure that the output image in the Sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640] # Height, width
​
# ================================
# Gradient operating parameters
# ================================
kernel_size = 3        # Convolution kernel size (odd number recommended)
iterations = 1         # Morphological iterations
threshold_value = 100  # Binarization threshold (0 = use Otsu automatic thresholding)
​
# Capture image and convert to ndarray
img = sensor.snapshot()
img_np = img.to_numpy_ref()
​
# Call the gradient operation (Gradient = dilation - erosion)
gradient_np = cv_lite.rgb888_gradient(image_shape, img_np, kernel_size, iterations, threshold_value)
​
# Construct a grayscale image for display
img_out = image.Image(image_shape[1], image_shape[0], image.GRAYSCALE,
                        alloc=image.ALLOC_REF, data=gradient_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 
iterationsNumber of morphological iterations, int typeInput 
threshold_valueBinarization threshold, int typeInput 

Return Value

Return ValueDescription
gradient_npImage data after morphological gradient, ulab.numpy.ndarray type

rgb888_mean_blur

Description

Applies a mean blur to an RGB888 image, returning the blurred image data as a ulab.numpy.ndarray. This data can be used to create an Image instance for display.

Syntax

Please ensure that the output image in the Sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640] # Height, width
​
# -------------------------------
# Mean blur kernel size
# Must be odd: 3, 5, 7, etc.
# -------------------------------
kernel_size = 3
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get an RGB888 image reference
​
# Apply mean fuzzy filtering
mean_blur_np = cv_lite.rgb888_mean_blur_fast(
    image_shape,
    img_np,
    kernel_size
)
​
# Constructing an image for display
img_out = image.Image(image_shape[1], image_shape[0], image.RGB888,
                        alloc=image.ALLOC_REF, data=mean_blur_np)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, in the order [height, width], e.g., [480, 640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 

Return Value

Return ValueDescription
mean_blur_npImage data after mean blurring, ulab.numpy.ndarray type

rgb888_gaussian_blur

Description

Applies a Gaussian blur to an RGB888 image, returning the blurred image data as a ulab.numpy.ndarray. This data can be used to create an Image instance for display.

Syntax

Please ensure that the output image in the Sensor configuration is RGB888; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
import image
​
image_shape = [480,640] # Height, width
​
# -------------------------------
# Gaussian filter kernel size
# Must be odd: 3, 5, 7, etc.
# -------------------------------
kernel_size = 3
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get an RGB888 image reference
​
# Apply a Gaussian blur filter
gaussian_blur_np = cv_lite.rgb888_gaussian_blur_fast(
    image_shape,
    img_np,
    kernel_size
)
​
# Constructing an image for display
img_out = image.Image(image_shape[1], image_shape[0], image.RGB888,
                        alloc=image.ALLOC_REF, data=gaussian_blur_np)

Parameters

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, in the order [height, width], e.g., [480,640]Input 
img_npImage data reference, ulab.numpy.ndarray typeInput 
kernel_sizeConvolution kernel size, int typeInput 

Return Value

Return ValueDescription
gaussian_blur_npImage data after Gaussian blur, ulab.numpy.ndarray type

rgb888_calc_histogram

Description

Calculates the histogram of an RGB888 image and returns the histogram data.

Syntax

xxxxxxxxxx
import cv_lite
​
# Capture a frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get an RGB888 image reference
​
# Use cv_lite to calculate the RGB histogram (return an array of shape 3x256)
hist = cv_lite.rgb888_calc_histogram(image_shape, img_np)

Parameter

Parameter NameDescriptionInput/OutputNotes
image_shapeImage shape, list type, including width and height, such as [1920, 1080]Input 
img_npImage data referenceInput 

Return Value

Return ValueDescription
histHistogram data

rgb888_find_corners

Description

Finds corner points in an RGB888 image and returns their coordinates.

Syntax

Please ensure that the sensor is configured to output an RGB888 image; otherwise, an error will occur.

xxxxxxxxxx
import cv_lite
​
image_shape = [240,320] # Height, width
​
# -------------------------------
# Adjustable parameters (recommended for debugging)
# -------------------------------
max_corners       = 20        # Maximum number of corner points
quality_level     = 0.01      # Shi-Tomasi quality factor
min_distance      = 20.0      # Minimum corner distance
​
# Capture current frame
img = sensor.snapshot()
img_np = img.to_numpy_ref()  # Get a reference to an RGB888 ndarray
​
# Call the corner detection function and return the corner point array [x0, y0, x1, y1, ...]
corners = cv_lite.rgb888_find_corners(
    image_shape, img_np,
    max_corners,
    quality_level,
    min_distance
)
​
# Traverse the corner point array and draw the corner points
for i in range(0, len(corners), 2):
    x = corners[i]
    y = corners[i + 1]
    img.draw_circle(x, y, 3, color=(0, 255, 0), fill=True)

Parameter

Parameter NameDescriptionInput/OutputNote
image_shapeImage shape, list type, including width and height, such as [240,320]Input 
img_npImage data referenceInput 
max_cornersMaximum number of corner pointsInput 
quality_levelShi-Tomasi quality factorInput 
min_distanceMinimum distanceInput 

Return Value

Return ValueDescription
cornersCorner point coordinate array, where each two numbers represent the coordinates of a corner point, such as [x0, y0, x1, y1, ...]
Introduction to cv_lite
Color Block Recognition - Grayscale Image

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文