Train and Deploy an AI Water Meter Reader With ESP32-P4

by Lan_Makerfabs in Circuits > Electronics

424 Views, 4 Favorites, 0 Comments

Train and Deploy an AI Water Meter Reader With ESP32-P4

ins-cover.jpg

This project uses the ESP32-P4 alongside a 2M Autofocus Camera to capture high-speed USB image input and build an end-to-end Edge AI vision system for reading real-world water meters.

Water meters present unique challenges—especially reading precise pointer positions and digital values. In this guide, we capture real meter images, annotate a custom dataset, train a dedicated lightweight AI model, and deploy it directly onto the ESP32-P4 for on-device inference.

By the end of this tutorial, you’ll have a fully functional, automated meter-reading system.

Supplies

Ins封面.png
2.2.2.png

Hardware & Tools

Why this hardware setup? Standard fixed-focus cameras often yield blurry shots of water meter dials and fine digits, sharply reducing AI recognition accuracy. We use an external USB 2M Autofocus AI Camera paired with the ESP32-P4 to ensure clear, sharp image inputs at various distances for reliable local AI inference.


Hardware List:

  1. MaTouch ESP32-P4 10.1" MIPI Touch Display (with 4G LTE SIM7670G): An ESP32-P4 HMI board running local AI vision models on-device. Its onboard USB host port connects directly to the external camera for image acquisition and real-time processing.
  2. 2M Autofocus Camera for AI: A 2MP USB camera module featuring autofocus to reliably capture sharp photos of meter dials, pointers, and digits across different distances.


Software Tool:

Makerfabs Water Meter Model Tool: An all-in-one PC utility covering the entire workflow: image collection, dataset preparation, model training, evaluation, export, and ROI (Region of Interest) configuration for quick deployment.


Environmental Construction:

1. Install ESP-IDF V5.5.3 and Visual Studio Code. Follow the guide “Get started with ESP-IDF” step by step: https://wiki.makerfabs.com/Get_Start_with_ESP_IDF.html

2. Download the example code AI_Camera_P4:

https://github.com/Makerfabs/MaTouch_ESP32-P4_TFT_with_4G_LTE_Touch_10_1_MIPI/tree/main/examples/AI_Camera_P4

3. Open that folder with VS Code and wait for the ESP-IDF plugin to finish loading. When you see ESP-IDF v5.5.3 in the status bar at the bottom of VS Code, your environment is ready.

Data Collection

4-1-1.png
4-1-2.png
4-1-3.png
4-1-4.png
4-1-5.png
4-1-6.png
4-1-7.png
4-1-8.png
4-1-9.png
4-1-10.png
4-1-11.png
4-1-12.png
4-1-13.1.png
4-1-13.2.png
4-1-14.png
4-1-15.1.png
4-1-15.2.png
4-1-15.3.png
  1. Connect the camera to the board via the USB Device interface.
  2. Connect the board to your PC via the USB-TTL interface using a USB Type-C data cable.
  3. Set Capture Mode in main/CMakeLists.txt: 0 = Capture Mode, 1 = Recognition Mode.
  4. Configure flashing: select UART, choose the correct COM port, and select ESP32-P4.
  5. Click Build and Flash in VS Code and wait for the process to complete.
  6. Press Ctrl + ] to exit the monitor and release the serial port.
  7. Open MakerfabsWaterMeterModelTool.exe.
  8. In the Collect Data section, select the serial port, choose the image save location, and click Open Collector.
  9. Point the camera at the water meter.
  10. Adjust the yellow box so its top edge aligns with the bottom of the digital reading area.
  11. Click Capture to take a photo.
  12. Select the integer digits in the captured image.
  13. Select the pointer area, covering the range from 0.1 to 0.0001.
  14. Enter the corresponding meter reading and click Save.
  15. The tool will automatically create an image folder and a labels.csv file.
  16. Repeat the process to collect enough samples with different readings, positions, and lighting conditions.


Prepare Dataset

4-2-1.png
4-2-2.png
4-2-3.1.png
4-2-3.2.png
4-2-3.3.png
4-2-4.1.png
4-2-4.2.png
  1. Open the Prepare Dataset section. Select the Raw Dataset Folder, labels.csv, and Prepared Output Folder, then click Prepare Integer + Dial Datasets.
  2. The tool will automatically generate two folders: integer & dial
  3. The integer folder contains the cropped integer images and the corresponding labels.csv.
  4. The dial folder contains the pointer images and the corresponding labels.csv.


Model Training

4-3-1.png
4-3-2.1.png
4-3-2.2.png
4-3-3.1.png
4-3-3.2.png
  1. Open the Train Models section and select the Prepared Folder, Integer Output, and Dial Output.
  2. Train the integer recognition model.
  3. Check the Training Digit Accuracy and Training Five-Digit Accuracy. Use the model only when both values are above 0.95. Lower values indicate that the model needs further training.
  4. Train the dial recognition model.
  5. Check the Training Dial Accuracy in the red box. Use the model only when the value is above 0.95. A lower value indicates that the model needs further training.


Model Export

4-4-1.1.png
4-4-1.2.png
4-4-2.png
  1. Open the Export Models section and select ESP-IDF Project, Integer Keras Model, and Dial Keras Model.
  2. Click Export Both INT8 Models to generate the quantized models.
  3. After the export is complete, open the ESP-IDF project in VS Code to view the exported models.


Model Evaluation

4-5-1.png
4-5-2.1.png
4-5-2.2.png
4-5-2.3.png
4-5-3.1.png
4-5-3.2.png
4-5-3.3.png
  1. Open the Evaluate section and select the Integer TFLite Model, Prepared Integer Dataset, Dial TFLite Model, and Prepared Dial Dataset.
  2. Select an Evaluation Output folder and click Evaluate Integer Model to evaluate the integer recognition model.
  3. Select the Evaluation Output folder and click Evaluate Dial Model to evaluate the pointer recognition model.


Model Deployment and Testing

5-1.png
5-2.png
5-3.png
5-4.png
5-5.png
5-6.png
5-7.png
5-8.png
5-9.1.png

Step 6: Model Deployment

  1. Switch to Digital Recognition Mode.
  2. Click Full Clean in VS Code to clear the previous build cache.
  3. Click Build and Flash and wait for the process to complete.
  4. Press Ctrl + ] to exit the monitor and release the serial port.
  5. In Calibrate ROI, select the serial port and click Open ROI Calibration.
  6. Click Get Frame to calibrate the ROI, then click Save Calibration to save it to flash.
  7. Click Monitor Device in VS Code and wait for the device to restart and print the logs.
  8. Check whether the calibrated ROI correctly frames the target area.
  9. Check the recognition results


Testing Result

Ins封面.png

The ESP32-P4 successfully recognized the digits and pointer from real water meter images. The system accurately outputs the complete water meter reading directly on the device.

The source code can be found on our GitHub page.