视觉识别模块
0、学前先看&供电说明
1、固件下载与烧录
2、安装编程环境
3、调试运行例程
4、离线运行例程
5、Micropython 快速入门
6、GUI程序使用说明
7、二维云台安装教程
8、FPIOA引脚分配
9、RGB灯
10、蜂鸣器
11、按键
12、串口通信
13、I2C通讯
14、PWM
15、WDT看门狗
16、定时器计时
17、傅里叶变换
18、SHA256加密
19、AES加密
20、多线程
21、文件读写
22、图像显示
23、触摸显示
24、摄像头显示
25、图像翻转
26、照相机
27、绘制圆形
28、绘制矩形
29、绘制椭圆
30、绘制箭头
31、绘制十字准心
32、绘制文字
汝城县职业中等专业学校知识库-信息中心朱老师编辑
-
+
首页
31、绘制十字准心
## 例程简介 本节我们介绍绘制十字准心的draw\_cross()方法 ## API 文档 `image.draw_cross(x, y[, color[, size=5[, thickness=1]]])` 在图像上绘制一个十字标记。参数可以分别传入 `x, y`,也可以作为元组 `(x, y)` 一起传递。 * **color**: 表示颜色的 RGB888 元组,适用于灰度或 RGB565 图像,默认为白色。对于灰度图像,还可以传递像素值(范围 0-255);对于 RGB565 图像,可以传递字节翻转的 RGB565 值。 * **size**: 控制十字标记的大小,默认为 5。 * **thickness**: 控制十字线条的像素宽度,默认为 1。 该方法返回图像对象,允许通过链式调用其他方法。 不支持压缩图像和 Bayer 格式图像。 ## 示例代码 ``` # Import required modules # 导入所需的模块 import time, os, urandom, sys, math # Import display and media related modules # 导入显示和媒体相关模块 from media.display import * from media.media import * # Define display resolution constants # 定义显示分辨率常量 DISPLAY_WIDTH = 640 DISPLAY_HEIGHT = 480 def display_test(): """ Function to test display functionality 测试显示功能的函数 """ # Create main background image with white color # 创建白色背景的主图像 img = image.Image(DISPLAY_WIDTH, DISPLAY_HEIGHT, image.ARGB8888) img.clear() img.draw_rectangle(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT,color=(255,255,255),fill=True) # Initialize display with ST7701 driver # 使用ST7701驱动初始化显示器 Display.init(Display.ST7701, width = DISPLAY_WIDTH, height = DISPLAY_HEIGHT, to_ide = True) # Initialize media manager # 初始化媒体管理器 MediaManager.init() try: # 中心大十字 - 坐标调整为居中 img.draw_cross(320, 240, color=(0, 191, 255), size=40, thickness=3) # 内圈小十字环绕 - 坐标调整为居中 for i in range(8): angle = i * (360 / 8) # 均匀分布在圆周上 x = int(320 + 50 * math.cos(math.radians(angle))) y = int(240 + 50 * math.sin(math.radians(angle))) img.draw_cross(x, y, color=(135, 206, 235), size=15, thickness=2) # 外圈更小的十字 - 坐标调整为居中 for i in range(12): angle = i * (360 / 12) x = int(320 + 80 * math.cos(math.radians(angle))) y = int(240 + 80 * math.sin(math.radians(angle))) img.draw_cross(x, y, color=(173, 216, 230), size=10, thickness=1) # 四个角的装饰性十字 - 坐标调整为居中 img.draw_cross(240, 140, color=(0, 191, 255), size=25, thickness=2) img.draw_cross(400, 140, color=(0, 191, 255), size=25, thickness=2) img.draw_cross(240, 340, color=(0, 191, 255), size=25, thickness=2) img.draw_cross(400, 340, color=(0, 191, 255), size=25, thickness=2) # 中心点缀小十字 - 坐标调整为居中 img.draw_cross(320, 240, color=(173, 216, 230), size=8, thickness=1) # Update display with background image # 更新显示背景图像 Display.show_image(img) while True: time.sleep(2) except KeyboardInterrupt as e: print("user stop: ", e) except BaseException as e: print(f"Exception {e}") # Cleanup and deinitialize display # 清理并反初始化显示器 Display.deinit() os.exitpoint(os.EXITPOINT_ENABLE_SLEEP) time.sleep_ms(100) # Release media resources # 释放媒体资源 MediaManager.deinit() if __name__ == "__main__": # Enable exit points and run display test # 启用退出点并运行显示测试 os.exitpoint(os.EXITPOINT_ENABLE) display_test() ``` ## 运行效果 可以看到,我们在屏幕的中心使用不同大小和不同色调的十字准心来构建一个放射状绘制了一个图形 
admin
2026年1月4日 08:07
转发
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
Word文件
PDF文档
PDF文档(打印)
分享
链接
类型
密码
更新密码
有效期
AI