【01Studio MaixPy AI K210】12.画图

目录

导包:

image库

例程:

导包:

import sensor, image, time, lcd

image库

'''
读取文件路径获取,支持bmp/pgm/ppm/jpg/jpeg格式的图像文件。
copy_to_fb=True:可以加载大图片;
copy_to_fb=False:不可以加载大图片。
'''
img=image.Image(path[, copy_to_fb=False])
#示加载根目录下的 01Studio.bmp 图片。
img = image.Image("01Studio.bmp", copy_to_fb=True)

'''
画线段。
(x0,y0):起始坐标;
(x1,y1):终点坐标;
color:颜色,如(255,0,0)表示红色;
thickness:粗细。
'''
image.draw_line(x0, y0, x1, y1[, color[, thickness=1]])

'''
画矩形。
(x,y):起始坐标;
w:宽度;
h:长度;
color:颜色;
thickness:边框粗细;
fill:是否填充。
'''
image.draw_rectangle(x, y, w, h[, color[, thickness=1[, fill=False]]])

'''
画圆。
(x,y):圆心; 
radius:半径; 
color:颜色;
thickness:线条粗细;
fill:是否填充。
'''
image.draw_circle(x, y, radius[, color[, thickness=1[, fill=False]]])

'''
画箭头。
(x0,y0):起始坐标;
(x1,y1):终点坐标;
color:颜色;
size:箭头位置大小。
thickness:线粗细。
'''
image.draw_arrow(x0, y0, x1, y1[, color[, size,[thickness=1]]])

'''
画十字交叉。
(x,y): 交叉坐标;
color:颜色;
size:尺寸;
thickness:线粗细。
'''
image.draw_cross(x, y[, color[, size=5[, thickness=1]]])

'''
写字符。
(x,y): 起始坐标;
text:字符内容;
color:颜色;
scale:字体大小;
mono_space:强制间距。
'''
image.draw_string(x, y, text[, color[, scale=1[,mono_space=True…]]])

例程:

'''
main.py

画各种图形和写字符
'''

import sensor, image, time, lcd

lcd.init(freq=15000000)
sensor.reset()                      #复位摄像头
#sensor.set_vflip(1)                 #将摄像头设置成后置方式(所见即所得)

sensor.set_pixformat(sensor.RGB565) # 设置像素格式 RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # 设置帧尺寸 QVGA (320x240)
sensor.skip_frames(time = 2000)     # 灯带设置响应.
clock = time.clock()                # 新建一个时钟对象计算FPS.

while(True):
    clock.tick()
    img = sensor.snapshot()

    # 画线段:从 x0, y0 到 x1, y1 坐标的线段,颜色红色,线宽度 2。
    img.draw_line(20, 20, 100, 20, color = (255, 0, 0), thickness = 2)

    #画矩形:绿色不填充。
    img.draw_rectangle(150, 20, 100, 30, color = (0, 255, 0),thickness = 2, fill = False)

    #画圆:蓝色不填充。
    img.draw_circle(60, 120, 30, color = (0, 0, 255), thickness = 2,fill = False)

    #画箭头:白色。
    img.draw_arrow(150, 120, 250, 120, color = (255, 255, 255), size =20, thickness = 2)

    #画十字交叉。
    img.draw_cross(60, 200, color = (255, 255, 255), size = 20,thickness = 2)

    #写字符。
    img.draw_string(150, 200, "Hello 01Studio!", color = (255, 255,255), scale = 2,mono_space = False)

    lcd.display(img)                # Display on LCD
    print(clock.fps())              # Note: MaixPy's Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

因心,三人水

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值