Error 2 in face_detection.py import to SD

Hello,
I have problem when I recorded the python program face_detection.py to SD. It has an error message. Please explain and help me correct it.
Thank you very much
Sincerely yours
Denis B

face_detection.py - Chương trình phát hiện khuôn mặt cho OpenMV H7R2

Được tạo bởi Gemini dựa trên yêu cầu của bạn.

import sensor # Thư viện để điều khiển cảm biến camera
import time # Thư viện để đo thời gian và điều khiển độ trễ
import image # Thư viện để xử lý hình ảnh, bao gồm phát hiện đối tượng

— Cài đặt cảm biến camera —

Đặt lại cảm biến về trạng thái mặc định

sensor.reset()

Đặt định dạng pixel thành GRAYSCALE (ảnh xám)

Phát hiện khuôn mặt hoạt động hiệu quả nhất và nhanh nhất trên ảnh xám.

sensor.set_pixformat(sensor.GRAYSCALE)

Đặt kích thước khung hình thành HQVGA (160x120 pixels)

Kích thước này cung cấp sự cân bằng tốt giữa hiệu suất và độ chính xác cho phát hiện khuôn mặt.

sensor.set_framesize(sensor.HQVGA)

Bỏ qua một số khung hình ban đầu để cảm biến ổn định độ phơi sáng và cân bằng trắng.

Điều này giúp đảm bảo chất lượng hình ảnh tốt ngay từ đầu.

sensor.skip_frames(time=2000) # Bỏ qua khung hình trong 2000ms (2 giây)

— Tải Haar Cascade cho phát hiện khuôn mặt —

Haar Cascade là một tập hợp các tính năng được huấn luyện để nhận diện các đối tượng cụ thể,

trong trường hợp này là khuôn mặt.

“frontalface” là mô hình tích hợp sẵn để phát hiện khuôn mặt phía trước.

‘stages=25’ sử dụng tất cả 25 giai đoạn của cascade, cung cấp độ chính xác cao nhất.

Bạn có thể giảm số lượng giai đoạn để tăng tốc độ nhưng có thể giảm độ chính xác.

face_cascade = image.HaarCascade(“frontalface”, stages=25)

In thông tin về Haar Cascade đã tải (ví dụ: đường dẫn, số lượng giai đoạn).

Điều này hữu ích cho việc gỡ lỗi.

print(face_cascade)

— Khởi tạo đồng hồ để tính toán FPS (Frames Per Second) —

Đồng hồ này sẽ giúp chúng ta theo dõi hiệu suất của chương trình.

clock = time.clock()

— Vòng lặp chính của chương trình —

Vòng lặp này sẽ chạy liên tục để chụp ảnh, phát hiện khuôn mặt và hiển thị kết quả.

while (True):
# Đánh dấu thời gian bắt đầu của khung hình hiện tại để tính toán FPS.
clock.tick()

# Chụp một bức ảnh từ cảm biến camera.
img = sensor.snapshot()

# --- Tìm các đối tượng (khuôn mặt) trong ảnh ---
# img.find_features() sử dụng Haar Cascade để quét ảnh và tìm các đối tượng.
# 'face_cascade': Mô hình Haar Cascade đã tải.
# 'threshold=0.75': Ngưỡng độ tin cậy. Giá trị cao hơn (gần 1.0) sẽ dẫn đến ít phát hiện hơn
# nhưng độ chính xác cao hơn (ít sai sót). Giá trị thấp hơn sẽ tăng số lượng
# phát hiện nhưng có thể có nhiều dương tính giả hơn.
# 'scale=1.35': Hệ số tỷ lệ. Giá trị này xác định mức độ thay đổi kích thước của cửa sổ quét
# giữa các lần lặp. Giá trị nhỏ hơn (gần 1.0) cho phép phát hiện các đối tượng
# nhỏ hơn nhưng sẽ chậm hơn. Giá trị lớn hơn sẽ nhanh hơn nhưng có thể bỏ lỡ
# các đối tượng nhỏ.
objects = img.find_features(face_cascade, threshold=0.75, scale=1.35)

# --- Vẽ hình chữ nhật xung quanh các khuôn mặt đã phát hiện ---
# Duyệt qua danh sách các đối tượng (khuôn mặt) đã tìm thấy.
# Mỗi 'r' là một tuple (x, y, width, height) đại diện cho vị trí và kích thước của khuôn mặt.
for r in objects:
    # Vẽ một hình chữ nhật trên ảnh tại vị trí của khuôn mặt.
    # 'r' cung cấp tọa độ và kích thước.
    img.draw_rectangle(r)

# --- In FPS ---
# In ra số khung hình mỗi giây hiện tại.
# Lưu ý: FPS thực tế trên OpenMV IDE có thể thấp hơn một chút do việc truyền dữ liệu
# khung hình qua USB.
print(clock.fps())

Hi, it’s because the model is not in the firmware by default. Did you install the latest dev release firmware? We are about to do a firmware release with ROMFS which re-enables this feature.

Please click the the firmware version label on the IDE and install the firmware that ships with the IDE. This should re-enable the haar cascade.

Hi, thank you for your instructions. I tried to follow your instructions as well as the direct requests from the firmware to update the software so that it can be used in face_detection.py, But even though I did it over 10 times, there is still an error that I send you as follows

I am unable to update the above software, I would like you help me by sending me a small program to install (with directions install)

or those codes to copy and paste to software face_detection.py

If you have any other way please help me. I lost 3 days to repair this problem .
Thank you very much
Yours sincerely
Denis B

Hi, please install the latest dev IDE release here: Release Development Release · openmv/openmv-ide · GitHub

Grab the windows (non-factory version).

This new release works with the latest firmware. 4.6.20. As mentioned, if you’d installed the dev release firmware via Tools → Install Latest Dev Release, you’d run into the problem. The dev release IDE can fix this issue.

After you install the IDE, go to Tools->ROM FS->Reset ROMFS and the IDE will walk you through resetting the board firmware.

Dear Sir

I am experiencing significant difficulties attempting to update the firmware on my OpenMV Cam H7R2 and would greatly appreciate your assistance.

Summary of Initial Problem: I initially encountered an OSError: [Errno 2] ENOENT when trying to use the face detection function (image.HaarCascade(“frontalface”)), indicating missing or inaccessible Haar Cascade files.

Steps Taken and Results:

Attempting to put the board into DFU mode:
Initially, I struggled with the timing of connecting/disconnecting the BOOT/RST jumper wire and the USB cable, which resulted in the “Instale la última versión de desarro” option being greyed out.

After several attempts, I successfully managed to put the board into DFU mode, and OpenMV IDE recognized it.
Installing the latest development OpenMV IDE version:
Following your previous email’s guidance (dated May 28, 2025), I uninstalled the old IDE version and installed openmv-ide-windows-4.6.1.exe from GitHub.

The IDE installation was successful.
Attempting “Reset ROMFS” (Sistema de archivos ROM → Restablecer ROMFS en OpenMV Cam):
After installing the new IDE and putting the board into DFU, I navigated to “Herramientas” (Tools) → “Sistema de archivos ROM” (ROM File System) → “Restablecer ROMFS en OpenMV Cam” (Reset ROMFS on OpenMV Cam).

I confirmed “Sí” (Yes) and checked both “Borrar el sistema de archivos de grasa interna” (Erase internal FAT file system) and “Restablecer el sistema de archivos ROMFS” (Reset ROMFS file system).

However, after the process completed and I re-ran my Gemini_face_detection.py script, the OSError: [Errno 2] ENOENT error persisted at the line face_cascade = image.HaarCascade(“frontalface”, stages=25).

Attempting manual firmware flashing:
I downloaded firmware_ARDUINO_PORTENTA_H7.zip from github.com/openmv/openmv/releases and extracted firmware.bin and firmware.dfu from it.

When attempting to flash firmware.bin via “Herramientas” (Tools) → “Cargar firmware personalizado” (Load custom firmware), I received an error message: “¡Solo la carga *.DFU archivos se admite para el gestor de arranque de recuperación STM32!” (Only *.DFU file loading is supported for the STM32 recovery bootloader!).

When attempting to flash firmware.dfu (after checking both erase FAT and reset ROMFS options), I received a warning: “Tenga en cuenta que cargar el firmware.dfu o openmv.dfu (bootloader + firmware) puede no funcionar en las placas STM32H7 debido a un error en el cargador de arranque ROM del chip. OpenMV recomienda solo cargar el gestor de arranque.dfu para reparar el gestor de arranque.” (Please note that loading firmware.dfu or openmv.dfu (bootloader + firmware) may not work on STM32H7 boards due to an error in the chip’s ROM bootloader. OpenMV recommends only loading bootloader.dfu to repair the bootloader.)

Current Unsurmountable Issue: The final warning indicates that flashing firmware.dfu may not work on STM32H7 boards due to a ROM bootloader error, and OpenMV recommends only flashing a bootloader.dfu file to repair the bootloader. However, the firmware package I downloaded (firmware_ARDUINO_PORTENTA_H7.zip) does not contain a separate bootloader.dfu file.

Therefore, I am currently stuck and unable to proceed with the firmware update process to resolve the missing Haar Cascade issue.

Request for Support: Could you please guide me on how to resolve this problem? Specifically, I need to know:

Is there a way to fix the ROM bootloader error on STM32H7 without a separate bootloader.dfu file?
If not, where can I find the correct bootloader.dfu file for my OpenMV Cam H7R2?
Are there any other more reliable methods to flash the firmware (including the Haar Cascades) onto my board?
I am happy to provide any further details or screenshots if needed.

Thank you very much for your assistance.

Sincerely,

Denis Bui

Hi, sorry, you need to change the path in the script to:

image.HaarCascade(“/rom/haarcascade_frontalface.cascade”, stages=25).

Please use the new IDE and do not downgrade the firmware.

You can see the ROMFS objects via Tools->Edit ROMFS. This will show all the cascades and etc. installed onboard.

Attempting manual firmware flashing:
I downloaded firmware_ARDUINO_PORTENTA_H7.zip from github.com/openmv/openmv/releases and extracted firmware.bin and firmware.dfu from it.

This would brick the camera. The Arduino Portenta firmware is not meant for the H7 R2.