M5StickV参考示例(2)
本帖最后由 vany5921 于 2020-3-23 16:37 编辑1.查找圆形
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))
2.图片显示
import image
img = image.Image()
img2 = image.Image("/flash/mai.bmp")
img3 = imgae.Image("/sd/kuraki.jpg")
3.画面裁剪
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)
4.保存图片
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")
5.光流图像位移检测
image.find_displacement(template[, roi[, template_roi[, logpolar=False]]])
template 比较图像对象
roi 图像处理范围
template 源图像处理范围
logpolar False平移检查 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())
6.直线检测
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)
7.获取指定坐标颜色
image.set_pixel(x, y, color)
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)
8.图像乘运算
image.mul(mul_image[, invert=False[, mask=None]])
mul_image 乘运算图像
invert 反转
mask 遮罩
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)
9.alpha叠加图像
image.blend(ble_image[, alpha=128[, mask=None]])
ble_image 叠加图像
alpha 0~256
mask 遮罩
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)
10.画面过滤
image image.mean(size, ]]]])
size 内核大小 3*3或5*5
threshold True自适应亮度阈值
offset 正值处理更锐利,负值范围更大
invert 黑白反转
mask 遮罩为白色或黑色大小与图像像素大小相同
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)
非常实用:victory:,建议置顶,已经收藏。 实用的教程。
页:
[1]