MaixduinoはK210搭載のAI開発ボードです。2.4インチLCDとカメラモジュールがセットになっています。開発環境はMicroPythonの MaixPy IDE と、Arduino IDE が使えます。
Maixduinoのセットアップ
パソコンと接続・認識
USB Type-Cケーブルでパソコンに繋ぐと、Macの場合は /dev/cu.* にシリアルポートが2個現れました。末尾が0と1の違いは不明です。
1 2 |
crw-rw-rw- 1 root wheel 9, 13 3 31 11:04 /dev/cu.usbserial-2D5213A3400 crw-rw-rw- 1 root wheel 9, 11 3 31 11:04 /dev/cu.usbserial-2D5213A3401 |
Windowsの場合はUSBシリアルドライバが必要と思われますが未確認です。
書き込みツール kflash をダウンロード
2021年3月時点の最新版 v1.6.5 を使用することにしました。Mac用のファイル名は kflash_gui_v1.6.5_2_macOS.dmg です。
ファームウエアをダウンロード
v0.6.2 を選択。readme.txt に “maixpy_*.bin” が normal firmware だと書いてあるので、ファイル名 maixpy_v0.6.2_44_gd9dc6c58c.bin を選択。
ファームウエアを書き込み
kflash_gui を起動する。
[Open File] からファームウエアのファイルを指定する。
[Board] は “Sipeed Maixduino” を選択。
[Port] でシリアルポートを指定。末尾0の方を指定した。
他はデフォルトのまま [Download] ボタンで書き込み実行。
顔検出を試す
MaixPy IDE をインストール
2021年3月時点の最新版 v0.2.5 を選択。ファイル名は maixpy-ide-mac-0.2.5_2.dmg (Mac用) または maixpy-ide-windows-0.2.5.exe (Windows用) です。サーバーが中国にあるせいか、ダウンロードは10分くらいかかります。
顔のモデルをダウンロード
ファイル名 mobilenet_0x300000.kfpkg をダウンロードして、kflash_gui を使って焼き込みます。
MaixPy IDE を起動
[ツール]>[Select Board] で “Sipeed Maixduino” を選択。左下の鎖アイコンを押して接続デバイスに接続します。このときシリアルポートを聞かれるのでポート名を指定します。左下の▶ボタンでデフォルトのサンプルプログラム helloworld_1.py を動作させるとカメラ映像がLCDとパソコン上のIDE画面にも表示されます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# Hello World Example # # Welcome to the MaixPy IDE! # 1. Conenct board to computer # 2. Select board at the top of MaixPy IDE: `tools->Select Board` # 3. Click the connect buttion below to connect board # 4. Click on the green run arrow button below to run the script! import sensor, image, time, lcd lcd.init(freq=15000000) sensor.reset() # Reset and initialize the sensor. It will # run automatically, call sensor.run(0) to stop sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) sensor.skip_frames(time = 2000) # Wait for settings take effect. clock = time.clock() # Create a clock object to track the FPS. while(True): clock.tick() # Update the FPS clock. img = sensor.snapshot() # Take a picture and return the image. lcd.display(img) # Display on LCD print(clock.fps()) # Note: MaixPy's Cam runs about half as fast when connected # to the IDE. The FPS should increase once disconnected. |
顔認証のプログラムを作成
MaixPy IDE に次のコードをコピペして動作させると顔検出が動きます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import sensor import image import lcd import KPU as kpu lcd.init() sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.run(1) task = kpu.load(0x300000) # you need put model(face.kfpkg) in flash at address 0x300000 # task = kpu.load("/sd/face.kmodel") anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025) a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor) while(True): img = sensor.snapshot() code = kpu.run_yolo2(task, img) if code: for i in code: print(i) a = img.draw_rectangle(i.rect()) a = lcd.display(img) a = kpu.deinit(task) |
プログラムをMaixduinoに送る。
MaixPy IDE が Maixduino と接続されている状態で、メニューの [ツール]>[transfer file to board] を実行すると、MaixPy IDE で動作しているプログラムがデバイスに転送されます。その後は Maixduino 単独で、例えばモバイルバッテリー等から電源供給すれば単独で動作します。