M5StickV参考示例(2)-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1604|回复: 2

M5StickV参考示例(2)

[复制链接]
发表于 2020-3-10 09:57 | 显示全部楼层 |阅读模式
本帖最后由 vany5921 于 2020-3-23 16:37 编辑

1.查找圆形

[mw_shl_code=python,true]import sensor, image, time, lcd

lcd.init(freq=15000000)
lcd.rotation(2)

sensor.reset()

sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
#sensor.set_windowing((128, 64))
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    lcd.display(img)
    for c in img.find_circles():
        area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())
        statistics = img.get_statistics(roi=area)
        img.draw_rectangle(area, color = (255, 255, 255))[/mw_shl_code]

2.图片显示
[mw_shl_code=python,true]import image

img = image.Image()
img2 = image.Image("/flash/mai.bmp")   
img3 = imgae.Image("/sd/kuraki.jpg")    [/mw_shl_code]

3.画面裁剪
[mw_shl_code=python,true]import sensor, image, time, lcd

lcd.init(freq=15000000)
lcd.rotation(2)

sensor.reset()

sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
#sensor.set_windowing((128, 64))
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    img2 = img.copy((50,50,10,32))
    lcd.display(img2)[/mw_shl_code]

4.保存图片
[mw_shl_code=python,true]import sensor, image, time, lcd

lcd.init(freq=15000000)
lcd.rotation(2)

sensor.reset()

sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
#sensor.set_windowing((128, 64))
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    img = sensor.snapshot()
    img.save("/flash/1.bmp")
    img.save("/sd/2.bmp") [/mw_shl_code]


5.光流图像位移检测
image.find_displacement(template[, roi[, template_roi[, logpolar=False]]])
template 比较图像对象
roi 图像处理范围
template 源图像处理范围
logpolar False平移检查 True缩放检查
[mw_shl_code=python,true]
import sensor, image, time, lcd
lcd.init(freq=15000000)
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.B64X64)
sensor.set_windowing((64,64))
sensor.skip_frames(time = 2000)
clock = time.clock()

x=0.0
y=0.0
old = sensor.snapshot()
while(True):
    clock.tick()
    img = sensor.snapshot()
    lcd.display(img)
    result = img.find_displacement(oldImage)
    x += result.x_translation()
    y += result.y_translation()
    x = round(x,3)
    y = round(y,3)
    oldImage = img.copy()
    print("x: ", x, "y: ", y)
    print(clock.fps()) [/mw_shl_code]

6.直线检测
[mw_shl_code=python,true]import sensor, image, time, lcd

lcd.init(freq=15000000)
sensor.reset()                     

sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
#sensor.set_windowing((64,64))
sensor.skip_frames(time = 2000)
clock = time.clock()

while True:
    img = sensor.snapshot()
    lcd.display(img)
    lines = img.find_lines()
    print(lines)[/mw_shl_code]

7.获取指定坐标颜色
image.set_pixel(x, y, color)

[mw_shl_code=python,true]import sensor, image, time, lcd

lcd.init(freq=15000000)
lcd.rotation(2)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)

#sensor.set_windowing((128,64))
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    img = sensor.snapshot()
    lcd.display(img)
    rgbtuple = img.get_pixel(20,30)   
   
    print("pixel: ", rgbtuple)[/mw_shl_code]


8.图像乘运算
image.mul(mul_image[, invert=False[, mask=None]])
mul_image 乘运算图像
invert 反转
mask 遮罩
[mw_shl_code=python,true]import sensor, image, time, lcd

lcd.init(freq=15000000)
lcd.rotation(2)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)

#sensor.set_windowing((128,64))
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    img = sensor.snapshot()  
    img = img.copy((0,0,240,135))  
    lcd.display(img)
    time.sleep(2)

    img2 = sensor.snapshot()
    img2 = img2.copy((0,0,240,135))
    lcd.display(img2)
    time.sleep(2)

    img3 = img2.mul(img)
    lcd.display(img3)
    time.sleep(2)[/mw_shl_code]

9.alpha叠加图像
image.blend(ble_image[, alpha=128[, mask=None]])
ble_image 叠加图像
alpha 0~256
mask 遮罩
[mw_shl_code=python,true]
import sensor, image, time, lcd

lcd.init(freq=15000000)
lcd.rotation(2)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)

#sensor.set_windowing((128,64))
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    img = sensor.snapshot()
    img = img.copy((0,0,240,135))
    lcd.display(img)
    time.sleep(2)

    img2 = sensor.snapshot()
    img2 = img2.copy((0,0,240,135))
    lcd.display(img2)
    time.sleep(2)

    img3 = img2.blend(img, alpha = 128)
    lcd.display(img3)
    time.sleep(2)[/mw_shl_code]

10.画面过滤
image image.mean(size, [threshold=False, [offset=0, [invert=False, [mask=None]]]]])
size 内核大小 3*3或5*5
threshold True自适应亮度阈值
offset 正值处理更锐利,负值范围更大
invert 黑白反转
mask 遮罩为白色或黑色大小与图像像素大小相同
[mw_shl_code=python,true]
import sensor, image, time, lcd

lcd.init(freq=15000000)
lcd.rotation(2)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    img = sensor.snapshot()
    img2 = img.mean(25, threshold=True,invert=False)
   
    lcd.display(img2)
    time.sleep_ms(2)
[/mw_shl_code]

发表于 2020-3-11 12:30 | 显示全部楼层
非常实用,建议置顶,已经收藏。
发表于 2020-3-12 00:36 | 显示全部楼层
实用的教程。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 08:41 , Processed in 0.073354 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表