logo

OpenMV N6 运行 AprilTag 识别时异常报错(控制台无输出)

2026-05-29 16:30
I
iwnoabr0uz1z

OpenMV N6 运行 AprilTag 识别时异常报错(控制台无输出)

问题概述

用户使用 OpenMV N6 摄像头运行 AprilTag 识别代码,固件已更新至 v5.0,IDE 为 v4.8.11。代码可正常启动并捕获图像,但在识别到 AprilTag 时发生异常中断,IDE 控制台无任何报错文本输出(无红色错误信息),疑似底层异常、内存溢出或硬件兼容性问题。

关键信息汇总

  • 硬件型号:OpenMV N6(已附正/背面实拍图)
  • 固件版本:5.0
  • IDE 版本:4.8.11
  • 参考教程:[AprilTag标记跟踪 · OpenMV中文入门教程](https://book.openmv.cc/image/apriltag.html)
  • 运行环境:QQVGA 分辨率,关闭自动增益与白平衡,使用默认焦距参数计算
  • 异常表现:识别到 AprilTag 后立即中断,控制台静默无报错(非 Python 异常,疑似 MCU 级 crash 或 USB 通信中断)

附带资源

image
image
image

用户代码(已校验格式)

import sensor, image, time, math

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
sensor.set_auto_whitebal(False) # must turn this off to prevent image washout...
clock = time.clock()

# f_x 是x的像素为单位的焦距。对于标准的OpenMV,应该等于2.8/3.984*656...
# f_y 是y的像素为单位的焦距。对于标准的OpenMV,应该等于2.8/2.952*488...
# c_x 是图像的x中心位置
# c_y 是图像的y中心位置
f_x = (2.8 / 3.984) *160 # 默认值
f_y = (2.8 / 2.952) *120 # 默认值
c_x = 160 *0.5 # 默认值(image.w * 0.5)
c_y = 120 *0.5 # 默认值(image.h * 0.5)

def degrees(radians):
    return (180 * radians) / math.pi

while(True):
    clock.tick()
    img = sensor.snapshot()
    for tag in img.find_apriltags(fx=f_x, fy=f_y, cx=c_x, cy=c_y): # 默认为TAG36H11
        img.draw_rectangle(tag.rect(), color = (255, 0, 0))
        img.draw_cross([tag.cx](), [tag.cy](), color = (0, 255, 0))
        print_args = (tag.x_translation(), tag.y_translation(), tag.z_translation(),
                      degrees(tag.x_rotation()), degrees(tag.y_rotation()), degrees(tag.z_rotation()))
        # 位置的单位是未知的,旋转的单位是角度
        print("Tx: %f, Ty %f, Tz %f, Rx %f, Ry %f, Rz %f" % print_args)
    print(clock.fps())
2026-05-29 16:40
Z
星小瞳xs

用QVGA或者VGA

2026-05-29 16:50
I
iwnoabr0uz1z

用的

QVGA

I
iwnoabr0uz1z

QQVGA直接跑不起来

I
iwnoabr0uz1z

VGA帧率太低了,而且识别到也是崩溃

2026-05-29 17:11
I
iwnoabr0uz1z

您好

I
iwnoabr0uz1z

麻烦帮忙解决一下

2026-05-29 17:23
Z
星小瞳xs

QVGA

# This work is licensed under the MIT license.
# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# AprilTags Example
#
# This example shows the power of the OpenMV Cam to detect April Tags
# on the OpenMV Cam M7. The M4 versions cannot detect April Tags.

import sensor
import time
import math

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
clock = time.clock()

# Note! Unlike find_qrcodes the find_apriltags method does not need lens correction on the image to work.

# What's the difference between tag families? Well, for example, the TAG16H5 family is effectively
# a 4x4 square tag. So, this means it can be seen at a longer distance than a TAG36H11 tag which
# is a 6x6 square tag. However, the lower H value (H5 versus H11) means that the false positive
# rate for the 4x4 tag is much, much, much, higher than the 6x6 tag. So, unless you have a
# reason to use the other tags families just use TAG36H11 which is the default family.

# The AprilTags library outputs the pose information for tags. This is the x/y/z translation and
# x/y/z rotation. The x/y/z rotation is in radians and can be converted to degrees. As for
# translation the units are dimensionless and you must apply a conversion function.

# f_x is the x focal length of the camera. It should be equal to the lens focal length in mm
# divided by the x sensor size in mm times the number of pixels in the image.
# The below values are for the OV7725 camera with a 2.8 mm lens.

# f_y is the y focal length of the camera. It should be equal to the lens focal length in mm
# divided by the y sensor size in mm times the number of pixels in the image.
# The below values are for the OV7725 camera with a 2.8 mm lens.

# c_x is the image x center position in pixels.
# c_y is the image y center position in pixels.

f_x = (2.8 / 3.984) * 160  # find_apriltags defaults to this if not set
f_y = (2.8 / 2.952) * 120  # find_apriltags defaults to this if not set
c_x = 160 * 0.5  # find_apriltags defaults to this if not set (the image.w * 0.5)
c_y = 120 * 0.5  # find_apriltags defaults to this if not set (the image.h * 0.5)


def degrees(radians):
    return (180 * radians) / math.pi


while True:
    clock.tick()
    img = sensor.snapshot()
    for tag in img.find_apriltags(
        fx=f_x, fy=f_y, cx=c_x, cy=c_y
    ):  # defaults to TAG36H11
        img.draw_rectangle(tag.rect, color=(255, 0, 0))
        # img.draw_cross(tag.cx, tag.cy, color=(0, 255, 0))
        print_args = (
            tag.x_translation,
            tag.y_translation,
            tag.z_translation,
            degrees(tag.x_rotation),
            degrees(tag.y_rotation),
            degrees(tag.z_rotation),
        )
        # Translation units are unknown. Rotation units are in degrees.
        print("Tx: %f, Ty %f, Tz %f, Rx %f, Ry %f, Rz %f" % print_args)
    print(clock.fps())

2026-05-29 18:16
I
iwnoabr0uz1z

试过啦,还是一样的问题,用QQVGA根本跑不起来的,所以一直是用AVGA

2026-06-01 09:29
Z
星小瞳xs

我没有推荐你用QQVGA啊,N6目前不支持QQVGA的分辨率,只能用QVGA或者VGA

2026-06-01 09:44
I
iwnoabr0uz1z

您好

I
iwnoabr0uz1z

这个问题还没解决噢

Z
星小瞳xs

使用我给你的代码,此代码这边测试可以正常运行

2026-06-01 09:56
I
iwnoabr0uz1z
image.png

识别到标签就卡住了

I
iwnoabr0uz1z

AprilTags Example

This example shows the power of the OpenMV Cam to detect April Tags

on the OpenMV Cam M7. The M4 versions cannot detect April Tags.

import sensor, image, time, math

sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) # we run out of memory if the resolution is much bigger... sensor.skip_frames(30) sensor.set_auto_gain(False) # must turn this off to prevent image washout... sensor.set_auto_whitebal(False) # must turn this off to prevent image washout... clock = time.clock()

注意!与find_qrcodes不同,find_apriltags 不需要软件矫正畸变就可以工作。

注意,输出的姿态的单位是弧度,可以转换成角度,但是位置的单位是和你的大小有关,需要等比例换算

f_x 是x的像素为单位的焦距。对于标准的OpenMV,应该等于2.8/3.984*656,这个值是用毫米为单位的焦距除以x方向的感光元件的长度,乘以x方向的感光元件的像素(OV7725)

f_y 是y的像素为单位的焦距。对于标准的OpenMV,应该等于2.8/2.952*488,这个值是用毫米为单位的焦距除以y方向的感光元件的长度,乘以y方向的感光元件的像素(OV7725)

c_x 是图像的x中心位置

c_y 是图像的y中心位置

f_x = (2.8 / 3.984) 160 # 默认值 f_y = (2.8 / 2.952) 120 # 默认值 c_x = 160 0.5 # 默认值(image.w 0.5) c_y = 120 0.5 # 默认值(image.h 0.5)

def degrees(radians): return (180 * radians) / math.pi

while(True): clock.tick() img = sensor.snapshot() for tag in img.find_apriltags(fx=f_x, fy=f_y, cx=c_x, cy=c_y): # 默认为TAG36H11 img.draw_rectangle(tag.rect(), color = (255, 0, 0)) img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0)) print_args = (tag.x_translation(), tag.y_translation(), tag.z_translation(), degrees(tag.x_rotation()), degrees(tag.y_rotation()), degrees(tag.z_rotation())) # 位置的单位是未知的,旋转的单位是角度 print("Tx: %f, Ty %f, Tz %f, Rx %f, Ry %f, Rz %f" % print_args) print(clock.fps())

2026-06-01 10:39
Z
星小瞳xs

你这运行的也不是我给你的代码啊