# Edge Impulse - OpenMV Image Classification Example
import sensor, image, time, os, tf
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.set_windowing((240, 240)) # Set 240x240 window.
sensor.skip_frames(time=2000) # Let the camera adjust.
net = "trained.tflite"
labels = ["3","8"]
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
# default settings just do one detection... change them to search the image...
for obj in tf.classify(net, img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
img.draw_rectangle(obj.rect())
# This combines the labels and confidence values into a list of tuples
predictions_list = list(zip(labels, obj.output()))
for i in range(len(predictions_list)):
print("%s = %f" % (predictions_list[i][0], predictions_list[i][1]))
print(clock.fps(), "fps")
固件版本是什么?
openmv-H7 R1
神经网络只能在OpenMV4 Plus上运行的。
OpenMV4 不行。
但是我这个就可以运行啊
#导入功能包
import pyb
import sensor, image, time, math
import os, tf
#摄像头传感器配置
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA) # we run out of memory if the resolution is much bigger...
sensor.set_brightness(500)
sensor.skip_frames(time = 20)
sensor.set_auto_gain(True) # must turn this off to prevent image washout...
sensor.set_auto_whitebal(True,(0,0x80,0)) # must turn this off to prevent image washout...
clock = time.clock()
#导入模型
net_path = "mnist_acc_0.9921_quant.tflite" # 定义模型的路径
labels = ["0", "1", "2", "3","4","5", "6", "7", "8", "9"] # 加载标签
net = tf.load(net_path, load_to_fb=True) # 加载模型
while(True):
#拍摄一张照片
img = sensor.snapshot()
#寻找矩形
for r in img.find_rects(threshold = 50000):
#矩形画框
img.draw_rectangle(r.rect(), color = (255, 0, 0))
#提取矩形中图像
img1 = img.copy(r.rect())
#运行模型识别
for obj in tf.classify(net , img1, min_scale=1.0, scale_mul=0.5, x_overlap=0.0, y_overlap=0.0):
#计算结果
sorted_list = sorted(zip(labels, obj.output()), key = lambda x: x[1], reverse = True)
#在图像中画出结果
img.draw_string(r.rect()[0] + 20, r.rect()[1]-20, sorted_list[0][0],color = (255,0,0), scale = 2,mono_space=False)这个是mnist,一个非常小的网络。
edge impulse是mobilenet,比mnist的网络大很多。
你这个mnist是哪来的?我不记得OpenMV发布过这个。