目录
导包:
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.