logo

OpenMV4 H7 Plus 运行多色块识别示例报错:NameError: name 'image' is not defined

2026-07-25 00:02
G
gs9x4x6klr7f

OpenMV4 H7 Plus 运行多色块识别示例报错:NameError: name 'image' is not defined

问题概述

用户在 OpenMV4 H7 Plus(固件 v5.0.0)上运行官方 Multi Color Blob Tracking 示例代码时,报错: ``` NameError: name 'image' is not defined ``` 错误出现在调用 `image.get_major_axis_line(blob)` 和 `image.get_minor_axis_line(blob)` 处。经核查,OpenMV 5.x 固件中相关 API 已变更,原 `image` 模块方法已移至 `img`(Image 对象实例)下。

关键信息汇总

  • 硬件型号:OpenMV4 H7 Plus
  • 固件版本:5.0.0
  • IDE 环境:最新版 OpenMV IDE(需确认兼容性)
  • 参考示例:OpenMV 官方 multi_color_blob_tracking.py(GitHub master 分支)
  • 报错位置:`image.get_major_axis_line(blob)` / `image.get_minor_axis_line(blob)`
  • 根本原因:API 迁移 —— OpenMV 5.0+ 中 axis line 相关方法已改为 img 实例方法,不再通过 `image` 模块调用

修复建议(代码修正)

将出错两行:

img.draw_line(image.get_major_axis_line(blob), color=(0, 255, 0))
img.draw_line(image.get_minor_axis_line(blob), color=(0, 0, 255))

替换为:

img.draw_line(blob.major_axis_line(), color=(0, 255, 0))
img.draw_line(blob.minor_axis_line(), color=(0, 0, 255))

补充说明

  • OpenMV 5.0+ 中 blob 对象新增了 `major_axis_line()` 和 `minor_axis_line()` 方法,直接返回 (x0,y0,x1,y1) 元组,无需再通过 `image` 模块调用
  • 其他潜在兼容问题:`img.draw_detection(blob)` 在 5.0+ 中已弃用,建议改用 `img.draw_rectangle(blob.rect(), color=(...))` + `img.draw_cross(blob.cx(), blob.cy(), ...)`
  • 请确保 IDE 与固件版本匹配(推荐使用 OpenMV IDE v3.6+ 配合固件 v5.0.0)

附件

image
2026-07-25 00:18
G
gs9x4x6klr7f

AttributeError: 'tuple' object has no attribute 'major_axis_line'

G
gs9x4x6klr7f

怎么又报错了,识别不了的

2026-07-25 00:39
G
gs9x4x6klr7f

你好,我已经修改了将近一个晚上的色块了,5.0.0的事例,颜色识别那块好多报错的

2026-07-25 14:20
G
gs9x4x6klr7f
ScreenShot_2026-07-25_142025_644.png
2026-07-25 14:26
Z
星小瞳xs

最开头加一句import image就行

2026-07-25 16:55
G
gs9x4x6klr7f

ok

2026-07-25 18:06
I
i52x71p5tm1a

我添加之后出现不了这个界面

image.png
2026-07-26 22:22
Z
星小瞳xs

哪个型号的openmv 然后固件和ide版本是多少?