Welcome to K230 Vision Module repository
9.Edge Recognition - Grayscale Image
Edge Recognition - Grayscale Image
Edge Recognition - Grayscale ImageExample ResultsCode OverviewImporting ModulesSetting the Image SizeInitialize the cameraInitialize the display moduleInitialize the media manager and start the cameraSet edge detection parametersImage processing and edge detectionResource releaseParameter adjustment instructions
Example Results
Run the example code in this section [Source Code/06.cv_lite/7.grayscale_find_edges.py]
In this section, we will use the cv_lite extension module to implement grayscale image edge detection (Canny algorithm) on an embedded device.

Code Overview
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 (including edge detection)import ulab.numpy as np # NumPy-like ndarray for MicroPythonSetting the Image Size
xxxxxxxxxximage_shape = [480, 640] # Height x WidthDefine the image resolution to 480x640 (Height x Width). width), the camera and display module will be initialized based on this size later.
Initialize the camera
xxxxxxxxxxsensor = Sensor(id=2, width=1280, height=960, 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 1280x960 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 edge 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, using the ST7701 driver chip, with a resolution consistent with the image size. to_ide=True indicates that the image will be simultaneously transmitted to the IDE for virtual display, and quality=50 sets the image transmission quality.
Initialize the media manager and start the camera
xxxxxxxxxxMediaManager.init()