logo

OpenMV H7 Plus + Edge Impulse FOMO 识别草莓后如何定位草莓梗坐标?

2026-07-15 16:25
W
wccxtw5z3z9l

OpenMV H7 Plus + Edge Impulse FOMO 识别草莓后如何定位草莓梗坐标?

问题背景

用户使用 OpenMV H7 Plus 运行基于 Edge Impulse 训练的 FOMO 目标检测模型,已成功识别草莓并输出其中心坐标(x, y)。当前目标是实现机械臂自动采摘,需精确定位草莓梗(果柄)位置,而非仅草莓果实中心。

当前方案

  • 模型:Edge Impulse FOMO(轻量级热图式目标检测)
  • 硬件:OpenMV H7 Plus
  • 代码流程:FOMO 输出热图 → find_blobs 提取检测框 → 计算中心点坐标

核心需求

  • 在已有草莓识别基础上,获取草莓梗(细长茎部)的精确坐标(如端点、中点或方向向量)
  • 适配机械臂剪刀夹取动作,需梗的空间朝向或相对位置信息
  • 兼顾实时性(OpenMV 算力限制)与精度

技术疑问

  • 是否可通过单模型多类别(如同时标注“草莓果实”和“草莓梗”)实现端到端检测?
  • 能否在FOMO热图后增加后处理(如形态学+轮廓分析)定位梗区域?
  • 是否有轻量级关键点检测(Keypoint Detection)适配 OpenMV 的可行方案?

附:当前代码关键逻辑

for x, y, w, h, score in detection_list:
    center_x = math.floor(x + (w / 2))
    center_y = math.floor(y + (h / 2))
    print(f"x {center_x}\ty {center_y}\tscore {score}")
    img.draw_circle((center_x, center_y, 12), color=colors[i])
2026-07-15 16:41
W
wccxtw5z3z9l

Edge Impulse - OpenMV FOMO Object Detection Example

This work is licensed under the MIT license.

Copyright (c) 2013-2024 OpenMV LLC. All rights reserved.

https://github.com/openmv/openmv/blob/master/LICENSE

import sensor, image, time, ml, math, uos, gc

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) # Let the camera adjust.

net = None labels = None min_confidence = 0.5

try: # load the model, alloc the model file on the heap if we have at least 64K free after loading net = ml.Model("trained.tflite", load_to_fb=uos.stat('trained.tflite')[6] > (gc.mem_free() - (64*1024))) except Exception as e: raise Exception('Failed to load "trained.tflite", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')')

try: labels = [line.rstrip('\n') for line in open("labels.txt")] except Exception as e: raise Exception('Failed to load "labels.txt", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')')

colors = [ # Add more colors if you are detecting more than 7 types of classes at once. (255, 0, 0), ( 0, 255, 0), (255, 255, 0), ( 0, 0, 255), (255, 0, 255), ( 0, 255, 255), (255, 255, 255), ]

threshold_list = [(math.ceil(min_confidence * 255), 255)]

def fomo_post_process(model, inputs, outputs): ob, oh, ow, oc = model.output_shape[0]

x_scale = inputs[0].roi[2] / ow
y_scale = inputs[0].roi[3] / oh

scale = min(x_scale, y_scale)

x_offset = ((inputs[0].roi[2] - (ow * scale)) / 2) + inputs[0].roi[0]
y_offset = ((inputs[0].roi[3] - (ow * scale)) / 2) + inputs[0].roi[1]

l = [[] for i in range(oc)]

for i in range(oc):
    # Edge Impulse - OpenMV FOMO Object Detection Example
    #
    # This work is licensed under the MIT license.
    # Copyright (c) 2013-2024 OpenMV LLC. All rights reserved.
    # https://github.com/openmv/openmv/blob/master/LICENSE

    import sensor, image, time, ml, math, uos, gc

    sensor.reset()                         # Reset and initialize the sensor.
    sensor.set_pixformat(sensor.RGB565)    # Set pixel format to RGB565 (or GRAYSCALE)
    sensor.set_framesize(sensor.QQVGA)      # Set frame size to QVGA (320x240)
    # sensor.set_windowing((240, 240))       # Set 240x240 window.
    sensor.skip_frames(time=2000)          # Let the camera adjust.

    net = None
    labels = None
    min_confidence = 0.5



    # 列出文件目录及文件信息
    print("\nFiles on SD card:")
    for f in uos.listdir():
        temp = uos.stat(f)
        print("file: %s, size: %u bytes" % (f, temp[6]))
    print("")

    gc.collect()

    labels = [line.rstrip('\n') for line in open("labels.txt")]
    print(labels)

    net = ml.Model("trained.tflite", load_to_fb=True)
    print(net)





    colors = [ # Add more colors if you are detecting more than 7 types of classes at once.
        (255,   0,   0),
        (  0, 255,   0),
        (255, 255,   0),
        (  0,   0, 255),
        (255,   0, 255),
        (  0, 255, 255),
        (255, 255, 255),
    ]

    threshold_list = [(math.ceil(min_confidence * 255), 255)]

    def fomo_post_process(model, inputs, outputs):
        ob, oh, ow, oc = model.output_shape[0]

        x_scale = inputs[0].roi[2] / ow
        y_scale = inputs[0].roi[3] / oh

        scale = min(x_scale, y_scale)

        x_offset = ((inputs[0].roi[2] - (ow * scale)) / 2) + inputs[0].roi[0]
        y_offset = ((inputs[0].roi[3] - (ow * scale)) / 2) + inputs[0].roi[1]

        l = [[] for i in range(oc)]

        for i in range(oc):
            # Slice the output and multiply by 255.0 to ensure float arithmetic
            # OpenMV image.Image() from ndarray expects simple memory layout and float32 usually
            img_data = outputs[0][0, :, :, i] * 255.0
            img = image.Image(img_data)
            blobs = img.find_blobs(
                threshold_list, x_stride=1, y_stride=1, area_threshold=1, pixels_threshold=1
            )
            for b in blobs:
                rect = b.rect()
                x, y, w, h = rect
                score = (
                    img.get_statistics(thresholds=threshold_list, roi=rect).l_mean() / 255.0
                )
                x = int((x * scale) + x_offset)
                y = int((y * scale) + y_offset)
                w = int(w * scale)
                h = int(h * scale)
                l[i].append((x, y, w, h, score))
        return l

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

        img = sensor.snapshot()

        for i, detection_list in enumerate(net.predict([img], callback=fomo_post_process)):
            if i == 0: continue  # background class
            if len(detection_list) == 0: continue  # no detections for this class?

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

        print(clock.fps(), "fps", end="\n\n")

    blobs = img.find_blobs(
        threshold_list, x_stride=1, y_stride=1, area_threshold=1, pixels_threshold=1
    )
    for b in blobs:
        rect = b.rect()
        x, y, w, h = rect
        score = (
            img.get_statistics(thresholds=threshold_list, roi=rect).l_mean() / 255.0
        )
        x = int((x * scale) + x_offset)
        y = int((y * scale) + y_offset)
        w = int(w * scale)
        h = int(h * scale)
        l[i].append((x, y, w, h, score))
return l

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

img = sensor.snapshot()

for i, detection_list in enumerate(net.predict([img], callback=fomo_post_process)):
    if i == 0: continue  # background class
    if len(detection_list) == 0: continue  # no detections for this class?

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

print(clock.fps(), "fps", end="\n\n")
2026-07-15 16:48
Z
星小瞳xs

你最终需要的是机械臂抓取点的三维空间坐标。具体可以参考:OpenMV机械臂-项目实例 · OpenMV中文入门教程

2026-07-15 17:43
W
wccxtw5z3z9l

我现在得到了草莓x y的坐标,有没有教程得到z轴坐标

W
wccxtw5z3z9l

最大的问题是怎么识别草莓梗,得到草莓梗的坐标

2026-07-15 17:51
W
wccxtw5z3z9l
DSC_1378_JPG.rf.baf40ede3a040fbd387d45c7e19058e5.jpg
W
wccxtw5z3z9l

还得是识别成熟草莓的梗

W
wccxtw5z3z9l

有木有办法🌹🌹

2026-07-16 09:29
Z
星小瞳xs

Z坐标得你自己解决,如加传感器什么的,OpenMV仅能反馈X,Y

Z
星小瞳xs

识别成熟加入成熟和不成熟的数据集即可

2026-07-16 16:55
W
wccxtw5z3z9l

识别草莓梗有什么办法吗😵‍💫

2026-07-17 09:25
2026-07-17 17:26
W
wccxtw5z3z9l

如果成熟草莓和未成熟草莓以及草莓柄都识别,那怎么确保我得到成熟草莓柄的坐标

m5o8laag.png
W
wccxtw5z3z9l

怎么区分成熟草莓的柄和未未成熟草莓的柄🌹🌹

2026-07-17 17:48
Z
星小瞳xs

为什么要识别柄呢?得到了草莓的位置不就等于得到了柄的坐标吗?

2026-07-18 09:18
W
wccxtw5z3z9l

我要根据坐标控制机械臂上的剪刀去剪草莓柄,只识别草莓不就直接怼草莓上了?得到根据草莓位置得到柄的坐标?😵‍💫🌹🌹

W
wccxtw5z3z9l

我要根据坐标控制机械臂上的剪刀去剪草莓柄,只识别草莓不就直接怼草莓上了?得到根据草莓位置得到柄的坐标?😵‍💫🌹🌹

2026-07-20 09:36
Z
星小瞳xs

得到草莓坐标后,然后再此坐标上做一些偏移不就可以了?柄的样子都一模一样,神经网络也分辨不出来,只能依靠草莓的坐标去做处理啊