Maixduino系列实验(14)---零基础学MaixPy之机器视觉
## 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)
`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)`
`#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()`