352浏览
查看: 352|回复: 0

[官方教程] Maixduino系列实验(14)---零基础学MaixPy之机器视觉

[复制链接]

Maixduino系列实验(14)---零基础学MaixPy之机器视觉

TueMarch-202103021701..png

#MicroPython动手做(07)——零基础学MaixPy之机器视觉
#实验程序之一:affine 仿射变换(实时缩放)

import image
import lcd, sensor
import time

lcd.init()

lcd.init(type=2, freq=20000000)
sensor.reset(freq=24000000)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)

matrix = image.get_affine_transform([(0,0), (240, 0), (240, 240)], [(60,60), (240, 0), (220, 200)])
print(“matrix:”)
print(“[{:.02f}, {:.02f}, {:.02f}]”.format(matrix[0], matrix[1], matrix[2]))
print(“[{:.02f}, {:.02f}, {:.02f}]”.format(matrix[3], matrix[4], matrix[5]))
print(“[{:.02f}, {:.02f}, {:.02f}]”.format(matrix[6], matrix[7], matrix[8]))

try:
del img
del img2
except Exception:
pass

img2 = image.Image(size=(320, 240))
img2.pix_to_ai()
flag = False
while 1:
img = sensor.snapshot()
image.warp_affine_ai(img, img2, matrix)

img2.ai_to_pix()
if flag:
    lcd.display(img2)
else:
    lcd.display(img)
flag = not flag
time.sleep_ms(500)

TueMarch-202103028070..png

TueMarch-202103027465..png

TueMarch-202103029814..png

TueMarch-202103026652..png

TueMarch-202103022289..png

`matrix = image.get_affine_transform([(0,0), (240, 0), (240, 240)], [(60,60), (240, 0), (220, 200)])

matrix = image.get_affine_transform([(0,0), (240, 0), (240, 240)], [(40,80), (100, 60), (220, 180)])`
`#MicroPython动手做(07)——零基础学MaixPy之机器视觉
#实验程序之一:affine 仿射变换(实时缩放)之二

import image
import lcd, sensor
import time

lcd.init()

lcd.init(type=2, freq=20000000)
sensor.reset(freq=24000000)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)

matrix = image.get_affine_transform([(0,0), (240, 0), (240, 240)], [(40,80), (100, 60), (220, 180)])
print(“matrix:”)
print(“[{:.02f}, {:.02f}, {:.02f}]”.format(matrix[0], matrix[1], matrix[2]))
print(“[{:.02f}, {:.02f}, {:.02f}]”.format(matrix[3], matrix[4], matrix[5]))
print(“[{:.02f}, {:.02f}, {:.02f}]”.format(matrix[6], matrix[7], matrix[8]))

try:
del img
del img2
except Exception:
pass

img2 = image.Image(size=(320, 240))
img2.pix_to_ai()
flag = False
while 1:
img = sensor.snapshot()

image.warp_affine_ai(img, img2, matrix)

img2.ai_to_pix()
if flag:
    lcd.display(img2)
else:
    lcd.display(img)
flag = not flag
time.sleep_ms(300)`

TueMarch-202103027981..png

TueMarch-202103021262..png

`#MicroPython动手做(07)——零基础学MaixPy之机器视觉
#实验程序之二:image deal 图像处理(深色浮雕)

import sensor
import image
import lcd
import time

lcd.init(freq=15000000)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
origin = (0,0,0, 0,1,0, 0,0,0)
edge = (-1,-1,-1,-1,8,-1,-1,-1,-1)
sharp = (-1,-1,-1,-1,9,-1,-1,-1,-1)
relievo = (2,0,0,0,-1,0,0,0,-1)

tim = time.time()
while True:
img=sensor.snapshot()
img.conv3(edge)
lcd.display(img)
if time.time() -tim >10:
break
tim = time.time()
while True:
img=sensor.snapshot()
img.conv3(sharp)
lcd.display(img)
if time.time() -tim >10:
break
tim = time.time()
while True:
img=sensor.snapshot()
img.conv3(relievo)
lcd.display(img)
if time.time() -tim >10:
break

lcd.clear()`

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2021 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail