LoginSignup
5
1

More than 3 years have passed since last update.

M5StickVで2枚の画像の変化量を取る

Last updated at Posted at 2019-09-15
boot.py
import sensor, image, utime, lcd
from Maix import GPIO
from fpioa_manager import fm
from board import board_info
from machine import I2C

i2c = I2C(I2C.I2C0, freq=400000, scl=28, sda=29)
lcd.init(freq=15000000)
i2c.writeto_mem(0x34, 0x91,b'\x70')  # バックライトを最低輝度
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE) #カメラ画像をグレースケールに設定
sensor.set_framesize(sensor.QQVGA)   # カメラ画像をQQVGAに設定
sensor.run(1)
sensor.skip_frames(time = 500)

fm.register(board_info.BUTTON_A, fm.fpioa.GPIO1)
button_a = GPIO(GPIO.GPIO1, GPIO.IN, GPIO.PULL_UP)

#extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565)

print("About to save background image...")
sensor.skip_frames(time = 500) #センサ待ち
baseImage = sensor.get_fb()
print("Saved background image - Now frame differencing!")
start = 0

while(True):
    img = sensor.snapshot()         #カメラ画像取得
    #lcd.display()                #LCDに表示
    sim = img.get_similarity(baseImage)
    th = sim.max()
    #print(th)
    if(th < 0.75):    #別画像と判定する閾値を設定
        print("something in")
        now = utime.ticks_ms()
        lapTime = now - start
        ms = lapTime % 1000
        s = (int)(lapTime / 1000)
        m = (int)(s / 60)
        s = s % 60
        print("%d'%d\"%d" %( m, s, ms))
        timeString = str(m) + '\'' + str(s) + '\"' + str(ms)
        simg = image.Image()
        simg.draw_string(10,30, timeString, scale=4)
        lcd.display(simg)
        i2c.writeto_mem(0x34, 0x91,b'\xA0')  #液晶輝度変更
        start = now
        utime.sleep(1)
        i2c.writeto_mem(0x34, 0x91,b'\x70')  #液晶輝度変更

    if button_a.value() == 0:
        print("A pushed ")
        baseImage = img.copy()
        utime.sleep(0.3)

https://docs.openmv.io/index.html
https://maixpy.sipeed.com/en/

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1