Created
July 10, 2019 13:51
-
-
Save ksasao/ad8fb722d45a2efa3745f34c1df28bdf to your computer and use it in GitHub Desktop.
MAIXPY one-shot learning. Burn firmware & mbnet kmodel here https://bbs.sipeed.com/t/topic/682 and write this code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sensor, image, lcd, time | |
import KPU as kpu | |
lcd.init() | |
sensor.reset() | |
sensor.set_pixformat(sensor.RGB565) | |
sensor.set_framesize(sensor.QVGA) | |
sensor.set_windowing((224, 224)) | |
sensor.set_vflip(0) | |
sensor.set_hmirror(0) | |
sensor.run(1) | |
lcd.clear() | |
task = kpu.load(0x200000) | |
info=kpu.netinfo(task) | |
clock = time.clock() | |
count = 0 | |
img = sensor.snapshot() | |
a=kpu.set_layers(task,29) | |
firstmap = kpu.forward(task,img) | |
firstdata = firstmap[:] | |
while(True): | |
img = sensor.snapshot() | |
clock.tick() | |
fmap = kpu.forward(task, img) | |
fps=clock.fps() | |
plist=fmap[:] | |
dist = 0 | |
for i in range(768): | |
dist = dist + (plist[i]-firstdata[i])*(plist[i]-firstdata[i]) | |
if dist < 200: | |
lcd.draw_string(224,0,"found!",lcd.GREEN,lcd.BLACK) | |
else: | |
lcd.draw_string(224,0," ") | |
a = lcd.display(img, oft=(0,0)) | |
lcd.draw_string(0, 224, "%.2f "%(dist)) | |
kpu.fmap_free(fmap) | |
a = kpu.deinit(task) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment