3.2 Display
Module API Manual#
Attention
This module has significant changes starting from firmware version V0.7. If you are using firmware prior to V0.7, please refer to the old version of the documentation.
1. Overview#
This manual is intended to guide developers on using the Micro Python API to call the CanMV Display module for image display functionality.
To add a custom screen, refer to Display Debugger.
2. API Introduction#
2.1 init#
Description
Initializes the Display path, including the VO module, DSI module, and LCD/HDMI.
Must be called before MediaManager.init()
Syntax
init(type=None, width=None, height=None, osd_num=1, to_ide=False, fps=None, quality=90)
Parameters
Parameter Name |
Description |
Input / Output |
Notes |
---|---|---|---|
type |
Input |
Required |
|
width |
Resolution width |
Input |
Default value depends on |
height |
Resolution height |
Input |
Default value depends on |
osd_num |
Number of layers supported in show_image |
Input |
Larger values occupy more memory |
to_ide |
Whether to transfer screen display to IDE display |
Input |
Occupies more memory when enabled |
fps |
Display frame rate |
Input |
Only supports |
quality |
Sets |
Input |
Effective only when |
Return Value
Return Value |
Description |
---|---|
None |
2.2 show_image#
Description
Displays an image on the screen.
Syntax
show_image(img, x=0, y=0, layer=None, alpha=255, flag=0)
Parameters
Parameter Name |
Description |
Input / Output |
Notes |
---|---|---|---|
img |
Image to display |
Input |
|
x |
X value of the starting coordinate |
Input |
|
y |
Y value of the starting coordinate |
Input |
|
layer |
Display on the specified layer |
Input |
Only supports |
alpha |
Layer blending alpha |
Input |
|
flag |
Display flag |
Input |
Return Value
Return Value |
Description |
---|---|
None |
2.3 deinit#
Description
Performs deinitialization. The deinit method will shut down the entire Display path, including the VO module, DSI module, and LCD/HDMI.
Must be called before MediaManager.deinit()
Must be called after sensor.stop()
Syntax
deinit()
Return Value
Return Value |
Description |
---|---|
None |
2.4 bind_layer#
Description
Binds the output of the sensor
or vdec
module to the screen display. This allows continuous image display without manual intervention.
Must be called before init
Syntax
bind_layer(src=(mod, dev, layer), dstlayer, rect=(x, y, w, h), pix_format, alpha, flag)
Parameters
Parameter Name |
Description |
Input / Output |
Notes |
---|---|---|---|
src |
Output information of |
Input |
Obtainable via |
dstlayer |
Display layer to bind to display layer |
Input |
Can be bound to |
rect |
Display area |
Input |
Obtainable via |
pix_format |
Image pixel format |
Input |
Obtainable via |
alpha |
Layer blending alpha |
Input |
|
flag |
Display flag |
Input |
|
Return Value
Return Value |
Description |
---|---|
None |
2.5 width#
Description
Gets the display width of the screen or a specified layer.
Syntax
width(layer=None)
Parameters
Parameter Name |
Description |
Input / Output |
Notes |
---|---|---|---|
layer |
Specifies the display layer to query. If |
Input |
Optional |
Return Value
Return Value |
Description |
---|---|
width |
Width of the screen or specified layer |
2.6 height#
Description
Gets the display height of the screen or a specified layer.
Syntax
height(layer=None)
Parameters
Parameter Name |
Description |
Input / Output |
Notes |
---|---|---|---|
layer |
Specifies the display layer to query. If |
Input |
Optional |
Return Value
Return Value |
Description |
---|---|
height |
Height of the screen or specified layer |
3. Data Structure Description#
3.1 type#
Type |
Example Initialization Parameters |
Notes |
---|---|---|
VIRT |
|
Default: 640x480@90 |
DEBUGGER |
For debugging screens. |
|
ST7701 |
|
Default: 800x480 |
|
Portrait mode: 480x800 |
|
|
854x480 |
|
|
Portrait mode: 480x854 |
|
|
640x480 |
|
|
Portrait mode: 480x640 |
|
|
368x552 |
|
|
Portrait mode: 552x368 |
|
HX8399 |
|
Default: 1920x1080 |
|
Portrait mode: 1080x1920 |
|
ILI9806 |
|
Default: 800x480 |
|
Portrait mode: 480x800 |
|
LT9611 |
|
Default: 1920x1080@30 |
|
1920x1080@60 |
|
|
1280x720@60 |
|
|
1280x720@50 |
|
|
1280x720@30 |
|
|
640x480@60 |
3.2 layer#
K230 supports 2 video layers and 4 OSD layers:
Display Layer |
Description |
Notes |
---|---|---|
LAYER_VIDEO1 |
Only usable in bind_layer, supports hardware rotation |
|
LAYER_VIDEO2 |
Only usable in bind_layer, no hardware rotation support |
|
LAYER_OSD0 |
Usable in show_image and bind_layer |
|
LAYER_OSD1 |
Usable in show_image and bind_layer |
|
LAYER_OSD2 |
Usable in show_image and bind_layer |
|
LAYER_OSD3 |
Usable in show_image and bind_layer |
3.3 flag#
Flag |
Description |
Notes |
---|---|---|
FLAG_ROTATION_0 |
Rotate |
|
FLAG_ROTATION_90 |
Rotate |
|
FLAG_ROTATION_180 |
Rotate |
|
FLAG_ROTATION_270 |
Rotate |
|
FLAG_MIRROR_NONE |
No mirroring |
|
FLAG_MIRROR_HOR |
Horizontal mirroring |
|
FLAG_MIRROR_VER |
Vertical mirroring |
|
FLAG_MIRROR_BOTH |
Horizontal & vertical mirroring |
4. Sample Program#
from media.display import * # Import the display module to use display related interfaces
from media.media import * # Import the media module to use media related interfaces
import os, time, image # Import the image module to use image related interfaces
# Use LCD as display output
Display.init(Display.ST7701, width=800, height=480, to_ide=True)
# Initialize media manager
MediaManager.init()
# Create an image for drawing
img = image.Image(800, 480, image.RGB565)
img.clear()
img.draw_string_advanced(0, 0, 32, "Hello World!,你好世界 ! ! ! ", color=(255, 0, 0))
Display.show_image(img)
try:
while True:
time.sleep(1)
os.exitpoint()
except KeyboardInterrupt as e:
print(" User stopped:", e)
except BaseException as e:
print(f" Exception: {e}")
Display.deinit()
MediaManager.deinit()