logo
OpenMV
Home Cam
Applications
Store
AI
Sales Channels
Support
OpenMVOpenMV
ShieldsShields
LensLens
RoboticsRobotics
BookBook
VideoVideo
DownloadDownload
DocsDocs
ForumForum
OpenMV.ioOpenMV.io
GithubGithub

OpenMV4 Plus utilizes Edge Impulse to self-train neural networks for mask recognition

Last April, our new product OpenMV4 H7 Plus was launched. Today, I will introduce to you the new feature of OpenMV4 H7 Plus—using the EdgeImpulse online platform to independently train neural networks for classification and recognition.

In this tutorial, you will use machine learning to build a recognition system that can identify whether a person is wearing a mask through the OpenMV4 H7 Plus smart camera, achieving image classification.

OpenMV产品图

EdgeImpulse is a website that provides online training services for neural network models for embedded devices. It is our partner for OpenMV and also an official partner of STMicroelectronics. Currently, EdgeImpulse is free for our OpenMV users, allowing them to train neural network models online for OpenMV at no cost.

Adding neural networks to the embedded device OpenMV enables functions such as distinguishing poachers from elephants, performing quality control on factory production lines, and allowing remote-controlled model cars to drive autonomously.

In this tutorial, you will learn how to collect images to build a high-quality dataset, how to apply transfer learning to train a neural network, and how to deploy the system to OpenMV.

Additionally, we have provided video tutorials, which can be viewed by searching for "OpenMV4 Plus Training Neural Network for Mask Recognition" on the official website.

You can view the entire project content, including all code and models, at the following address: https://book.openmv.cc/project/mask.html

Using EdgeImpulse to train neural network models online for OpenMV primarily involves the following four steps: dataset collection, uploading, training, and deployment.

01. Data Collection Dataset

In this tutorial, we will build a model that can distinguish whether a face is wearing a mask. Of course, you can also choose to classify other items. To enable the operation of the machine learning model, you need to collect a large number of example images of faces both wearing masks and not wearing masks. During training, these example images are used for the model's differentiation exercises.

We need to use OpenMV IDE to collect our dataset. The steps for capturing images are as follows:

Create two categories:

Open the "Tools" menu in the OpenMV IDE, select "Dataset Editor," click "New Dataset," then create a new folder and open it. Inside the dataset, create two additional folders named "mask" (for saving photos of faces wearing masks) and "face" (for saving photos of faces without masks).

口罩识别教程-新建数据集
口罩识别教程-创建分类文件夹

Collecting images using OpenMV

First, we connect the OpenMV, click "Connect" in the IDE, then click "Run." In the Framebuffer, we can see the real-time image from the OpenMV. By clicking the photo button in the left menu bar, the OpenMV will automatically save this image, which becomes one data point in the dataset.

First, we need to save the face wearing a mask. Click the photo button, and the IDE will capture a photo at the bottom, automatically naming it 00000. The next one will be 00001, and so on.

Collect 200 photos of faces wearing masks (100 each for males and females) and 200 photos of faces not wearing masks (100 each for males and females) using OpenMV.

口罩识别教程-用OopenMV采集男生戴口罩的图像
口罩识别教程-用OopenMV采集女生戴口罩的图像

Note Ensure that photos are captured from various angles to guarantee the diversity of our training and learning.

If during the collection process you find that a certain image is not captured perfectly, you can right-click on this image and select delete.

02. Upload

After capturing images with OpenMV, you need to register an account and log in to the EdgeImpulse official website (https://edgeimpulse.com/) to start uploading images. The steps for uploading images are as follows:

Create a new project on EdgeImpulse, click on "keys", select "API Key" and copy the "API Key". Use the API Key to establish connectivity between OpenMV IDE and Edge Impulse.

口罩识别教程-和Edge Impulse的连通

Select "Tools" from the menu bar at the top of OpenMV IDE, then choose "Data Editor," followed by "Export," "Upload," and "Upload via API Key." Copy the "API Key" and upload it.

During upload, the data will be automatically divided into training and testing sets. We recommend using the default ratio of "80% and 20%." We have collected over 400 facial images in total, where 80% of the Training Data means that 80% of your data is used for training by default, and the remaining 20% is used as the testing set.

口罩识别教程-用OpenMV上传数据集
口罩识别教程-将数据集上传到EdgeImpulse上

03. Training Dataset

The dataset is ready, and you can now train it on the EdgeImpulse website interface.

Configuration Processing Module:

First, select "Impulse Design" and configure the processing module:

Set the default image dimensions to "96 x 96".

Select the "Images" module, indicating that we are conducting classification training on images (you can also use EdgeImpulse to classify sounds, videos, etc.).

Select "Transfer Learning (Images)", configure the learning model.

Select "Save impulse", and if "Successfully" is displayed, the configuration is successful.

口罩识别教程-配置处理模块

Image Preprocessing:

Click "Image" in the left menu, set the color format to "RGB," then click "Save.

口罩识别教程-图像预处理

Next, select "Generate Features" to initiate the process. This will perform image preprocessing on over 400 data entries, and a 3D visualization of the complete dataset will be displayed on the right side.

口罩识别教程-数据可视化处理

Configure the transfer learning model

Click on "Transfer learning" in the left menu, and you can either keep all the default settings or adjust the parameters according to your needs.

1. Set the default value for the Number of training cycles to 10

2. Set the learning rate to 0.0005

3. You may or may not check the "Data augmentation" option.

4. Set the default Minimum confidence rating to 0.8.

Click "Start training". The training process takes approximately 4 to 5 minutes.

After the model training is completed, you can view the accuracy, confusion matrix, and expected device performance.

口罩识别教程-训练完成后的表现

Testing Model:

After the training is completed, we will use test data to examine the model.

Select "Model testing", check the box next to "Sample name", and click "Classify selected". The accuracy displayed here reaches 97%, which is quite remarkable for a model with limited data.

口罩识别教程-测试模型

The image highlighted in red indicates an uncertain classification. Click the three dots on the right side of this image, select "Show classification," and you will enter the "Real-time Classification" interface, which contains more details about the file. This interface will help you determine the reason for the incorrect image classification.

口罩识别教程-无法分类的图片

If the data falls outside all known clusters (with mask/without mask), this may be data that does not match any previously seen classification—possibly due to hair covering most of the face.

04. Running the Model on OpenMV

After completing the steps of training design, model training, and model validation, you can export this model to your OpenMV. Select "OpenMV," choose "Build" to generate, and it will automatically create three files.

trained.tflite trained neural network model

Two classification labels in labels.txt (face and mask)

* ei_image_classification.py is the code to be run on OpenMV

口罩识别教程-在OpenMV上运行模型

Connect to OpenMV IDE and save these three files to the built-in Flash of OpenMV. Open the ei_image_classification.py file in OpenMV IDE to view the code we just generated in EdgeImpulse. Click Run, and the operation results will be displayed in the serial terminal.

口罩识别教程-识别戴口罩的人脸.
口罩识别教程-识别不戴口罩的人脸

Alright, you have successfully added the feature of self-training neural networks to OpenMV.

Looking forward to your achievements!

Related articles

机房/配电房/单元门敞开识别

AI Sentinel Based on OpenMV: Automatic Alert for Unlocked Key Locations

Automatically detects whether the door of a key location has remained open for an extended period and issues a timely alert.

越界识别

Personnel crossing the boundary triggers an alarm; OpenMV defines the “sense of security boundary.”

Detecting personnel or equipment crossing boundaries via virtual alert lines.

占道经营识别

“AI城管” is here: An automated system for detecting illegal street vending, built on OpenMV

Automatically identifies illegal street vending activities to support daily urban governance.

煤气罐违规摆放识别

Is the gas cylinder placed haphazardly? Use OpenMV to automatically trigger a hazard alert

Automatically identifies unauthorized placements of gas cylinders to detect potential gas safety hazards in advance.

绝缘手套佩戴识别

Did you perform live-line work without wearing insulating gloves? OpenMV will immediately alert you!

Automatically identifies whether workers are wearing insulating gloves to assist in safe operations.

铝板缺陷识别

Utilizing the OpenMV smart camera to detect surface defects on aluminum plates in real time

Online detection of surface defects on aluminum plates, such as scratches and dents, to support quality control.

Popular categories

Language and Region
Copyright © 2025 星瞳科技SingTown
粤ICP备17045162号