logo

用openmv m3运行FOMO人检测例程时,提示tf模块没有load_builtin_model方法?

2025-01-26 12:36
3
gfgy
1aef76ac-0761-4a9a-8d7b-5c4b7577387c.png
import sensor
import time
import tf
import math

sensor.reset()  # 重置并初始化感光元件
sensor.set_pixformat(sensor.RGB565)  # 设置图像格式为 RGB565 (或 GRAYSCALE)
sensor.set_framesize(sensor.QVGA)  # 设置图像大小为 QVGA (320x240)
sensor.set_windowing((240, 240))  # 设置图像为 240x240 窗口大小
sensor.skip_frames(time=2000)  # 跳过几帧使设置生效

min_confidence = 0.4

# 加载内置的 FOMO 人脸检测模型
labels, net = tf.load_builtin_model("fomo_face_detection")

# 或者,模型文件也可以从文件系统存储中加载。
# net = tf.load('<object_detection_network>', load_to_fb=True)
# labels = [line.rstrip('\n') for line in open("labels.txt")]

colors = [  # 可以添加更多标识圈的颜色,可以超过7种,不同种类目标物体用不同颜色圈表示
    (255, 0, 0),
    (0, 255, 0),
    (255, 255, 0),
    (0, 0, 255),
    (255, 0, 255),
    (0, 255, 255),
    (255, 255, 255),
]

clock = time.clock()
while True:
    clock.tick()

    img = sensor.snapshot()

    # detect() 返回图像中检测到的所有的物体 (已经按照种类分类好)
    # 跳过索引0, 因为第0个分类是 背景 
    # 然后在识别到的物体中央画出圆圈

    for i, detection_list in enumerate(
        net.detect(img, thresholds=[(math.ceil(min_confidence * 255), 255)])
    ):
        if i == 0:
            continue  # 索引0是背景分类
        if len(detection_list) == 0:
            continue  # 没有检测到这个种类的物体

        print("********** %s **********" % labels[i])
        for d in detection_list:
            [x, y, w, h] = d.rect()
            center_x = math.floor(x + (w / 2))
            center_y = math.floor(y + (h / 2))
            print(f"x {center_x}\ty {center_y}")
            img.draw_circle((center_x, center_y, 12), color=colors[i], thickness=2)

    print(clock.fps(), "fps", end="\n")
2025-02-10 18:30
I
网红小智智 星瞳科技

OpenMV3 M7 运行不了的,最少也需要OpenMV4 H7