logo

OpenMV4 H7 Plus + 固件4.8.1:为何 image.HaarCascade("frontalface") 报 OSError: ENOENT?内置模型是否已移除?

2026-01-23 15:45
4
4pqqadtr4n2v

OpenMV4 H7 Plus + 固件4.8.1:为何 image.HaarCascade("frontalface") 报 OSError: ENOENT?内置模型是否已移除?

用户在运行 OpenMV 官方人脸识别例程时,执行以下代码行报错:

face_cascade = image.HaarCascade("frontalface", stages=25)

错误信息为:OSError: [Errno 2] ENOENT。经确认硬件为 OpenMV4 H7 Plus,固件为最新版 4.8.1,近期已多次重烧录固件,但 IDE 中未发现 frontalface.cascade 文件路径。

  • 问题核心:固件 4.8.1 是否已移除内置 Haar 模型(如 frontalface、eye)?
  • 若已移除,是否必须通过 Edge Impulse 等平台训练并部署自定义神经网络模型?
  • 是否有替代方案?例如:手动下载旧版 cascade 文件并加载?或使用 OpenMV 自带的 face detect 示例(基于 CNN)?
  • 如何验证当前固件中实际预置了哪些 Haar 模型?IDE 中能否查看 /data/cascade/ 目录?
2026-01-23 17:12
Z
星小瞳xs
image.png

点击固件版本,擦除和重置文件系统即可

2026-01-24 10:56
4
4pqqadtr4n2v

试了,还是会报错,代码

# 人脸识别例程
#
# 这个例子展示了OpenMV Cam的内置人脸检测功能。
#
# 人脸检测通过在图像上使用Haar Cascade特征检测器来工作。 haar级联是
# 一系列简单的区域对比检查。 对于内置的前表面探测器,有25个阶段的检查,
# 每个阶段有数百个检查一块。 Haar Cascades运行速度很快,因为只有在
# 以前的阶段过去后才会评估后期阶段。 此外,您的OpenMV使用称为
# 整体图像的数据结构来在恒定时间内快速执行每个区域对比度检查
#(特征检测仅为灰度的原因是因为整体图像的空间需求)。

import sensor, time, image

# 重置感光元件
sensor.reset()

# 感光元件设置
sensor.set_contrast(3)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
# HQVGA和灰度对于人脸识别效果最好
sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
#注意人脸识别只能用灰度图哦

# 加载Haar算子
# 默认情况下,这将使用所有阶段,更低的satges更快,但不太准确。
face_cascade = image.HaarCascade("frontalface", stages=25)
#image.HaarCascade(path, stages=Auto)加载一个haar模型。haar模型是二进制文件,
#这个模型如果是自定义的,则引号内为模型文件的路径;也可以使用内置的haar模型,
#比如“frontalface” 人脸模型或者“eye”人眼模型。
#stages值未传入时使用默认的stages。stages值设置的小一些可以加速匹配,但会降低准确率。
print(face_cascade)

# FPS clock
clock = time.clock()

while (True):
    clock.tick()

    # 拍摄一张照片
    img = sensor.snapshot()

    # Find objects.
    # Note: Lower scale factor scales-down the image more and detects smaller objects.
    # Higher threshold results in a higher detection rate, with more false positives.
    objects = img.find_features(face_cascade, threshold=0.75, scale=1.35)
    #image.find_features(cascade, threshold=0.5, scale=1.5),thresholds越大,
    #匹配速度越快,错误率也会上升。scale可以缩放被匹配特征的大小。

    #在找到的目标上画框,标记出来
    for r in objects:
        img.draw_rectangle(r)

    # 打印FPS。
    # 注:实际FPS更高,流FB使它更慢。
    print(clock.fps())
2026-01-26 14:35
Z
星小瞳xs
# 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
#
# Face Detection Example
#
# This example shows off the built-in face detection feature of the OpenMV Cam.
#
# Face detection works by using the Haar Cascade feature detector on an image. A
# Haar Cascade is a series of simple area contrasts checks. For the built-in
# frontalface detector there are 25 stages of checks with each stage having
# hundreds of checks a piece. Haar Cascades run fast because later stages are
# only evaluated if previous stages pass. Additionally, your OpenMV Cam uses
# a data structure called the integral image to quickly execute each area
# contrast check in constant time (the reason for feature detection being
# grayscale only is because of the space requirement for the integral image).

import sensor
import time
import image

# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(3)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("/rom/haarcascade_frontalface.cascade", stages=25)
print(face_cascade)

# FPS clock
clock = time.clock()

while True:
    clock.tick()

    # Capture snapshot
    img = sensor.snapshot()

    # Find objects.
    # Note: Lower scale factor scales-down the image more and detects smaller objects.
    # Higher threshold results in a higher detection rate, with more false positives.
    objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25)

    # Draw objects
    for r in objects:
        img.draw_rectangle(r)

    # Print FPS.
    # Note: Actual FPS is higher, streaming the FB makes it slower.
    print(clock.fps())