
import sensor, image, time, tf,lcd
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # 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)
lcd.init() # Let the camera adjust.
mobilenet = "openmv_classify.tflite"
labels = [line.rstrip() for line in open("labels.txt")]
class_num = len(labels)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
for obj in tf.classify(mobilenet, img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
img.draw_rectangle(obj.rect())
output = obj.output()
for i in range(class_num):
print("%s = %f" % (labels[i], output[i]))
print(clock.fps(), "fps")
img.draw_string(10,110, str(output)) # 文字输入 固定
img.draw_string(10,100, "no mask msak")
lcd.display(img)>>> a = "0.123456789"
>>> a[:5]
'0.123'我尝试了这样output = obj.output()[:3],无变化
又尝试了a=output【0】 b=a【:5】 img.draw_string(10,110, str(b))显示错误
output_str = ""
for n in output:
output_str += str(n)[:5]
img.draw_string(10,110, output_str)