Welcome to K230 Vision Module repository
5.Circle Recognition - Grayscale Image
Circle Recognition - Grayscale Image
Circle Recognition - Grayscale ImageExample ResultsCode ExplanationCode Snippet ExplanationImporting ModulesSet image sizeInitialize the cameraInitialize the display moduleInitialize the media manager and start the cameraSetting Hough Circle Detection ParametersImage Processing and Hough Circle DetectionResource releaseParameter adjustment instructions
Example Results
Run this section's example code [Source Code/06.cv_lite/3.grayscale_find_circles.py]
This section uses the cv_lite extension module to implement circle detection. It captures images in real time using a camera and draws a circular outline for annotation after detecting circular objects.
The average frame rate of this section's examples is around 15 frames per second. The specific frame rate depends on the actual detection scenario.

Code Explanation
Code Snippet Explanation
Importing Modules
import time, os, sys, gcfrom machine import Pinfrom media.sensor import * # Camera interfacefrom media.display import * # Display interfacefrom media.media import * # Media managerimport _threadimport cv_lite # cv_lite extension module (contains circle detection functions)import ulab.numpy as np # NumPy-like ndarray for MicroPythonThese modules provide the functionality required for camera control, image display, memory management, and Hough circle detection.
Set image size
xxxxxxxxxximage_shape = [480, 640] # Height x WidthDefine the image resolution to 480x640 (height x width). The camera and display module will be initialized based on this size.
Initialize the camera
xxxxxxxxxxsensor = Sensor(id=2, width=1280, height=720, fps=90)sensor.reset()sensor.set_framesize(width=image_shape[1], height=image_shape[0])sensor.set_pixformat(Sensor.GRAYSCALE) # Set to grayscale image output / Grayscale mode- Initialize the camera, set the resolution to 1280x720 and the frame rate to 90 FPS.
- Resize the output frame to 640x480 and set it to grayscale mode (single-channel image, saves memory and computing resources, suitable for Hough circle detection).
Initialize the display module
xxxxxxxxxxDisplay.init(Display.ST7701, width=image_shape[1], height=image_shape[0], to_ide=True, quality=50)Initialize the display module, use the ST7701 driver chip, and the resolution is consistent with the image size. to_ide=True means that the image will be transmitted to the IDE for virtual display at the same time, and quality=50 sets the image transmission quality.
Initialize the media manager and start the camera
xxxxxxxxxxMediaManager.init()sensor.run()Initialize the media resource manager and start the camera to start capturing the image stream.
Setting Hough Circle Detection Parameters