logo

在lcd上显示了数据,但由于直接应用的数组 数值略长 如何实现数组分离和得到除法后的结果

2022-04-05 16:07
8
x4k1
c8aa92df-8541-4706-bf2e-a945873d978d.png
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)
2022-04-06 19:55
I
网红小智智 星瞳科技
>>> a = "0.123456789"
>>> a[:5]
'0.123'
2022-04-07 19:09
8
x4k1

我尝试了这样output = obj.output()[:3],无变化

又尝试了a=output【0】 b=a【:5】 img.draw_string(10,110, str(b))显示错误

2022-04-07 19:17
I
网红小智智 星瞳科技
output_str = ""
for n in output:
    output_str += str(n)[:5]
img.draw_string(10,110, output_str)