A .NET console application for real-time face and eye detection using OpenCV and machine learning models. This project leverages Haar Cascade classifiers and YuNet ONNX models for accurate facial feature detection.
- Face Detection: Detect faces in images and video streams using Haar Cascade and YuNet models
- Eye Detection: Locate eyes within detected faces
- Multi-Framework Support: Runs on .NET 9.0 and .NET 10.0
- OpenCV Integration: Uses OpenCvSharp4 for robust computer vision capabilities
- ONNX Model Support: Includes pre-trained YuNet model for high-accuracy detection
- .NET Runtime: .NET 9.0 or .NET 10.0
- System Requirements:
- Windows (due to OpenCvSharp4.runtime.win dependency)
- Minimum 256MB RAM
- Webcam or image files for processing
-
Clone the repository:
git clone <repository-url> cd FaceDetection
-
Restore dependencies:
dotnet restore
-
Build the project:
dotnet build
dotnet run --project FaceDetection.csprojOr if already built:
dotnet FaceDetection.dllFaceDetection/
├── Program.cs # Main application entry point
├── FaceDetection.csproj # Project configuration
├── data/
│ ├── haarcascade_frontalface_alt.xml # Haar Cascade for frontal face detection
│ ├── haarcascade_eye.xml # Haar Cascade for eye detection
│ └── face_detection_yunet_2023mar.onnx # YuNet ONNX model for face detection
└── README.md # This file
- Language: C# (.NET 10/9)
- Computer Vision: OpenCvSharp4 (v4.13.0.20260308)
- Models:
- Haar Cascade Classifiers (frontal face & eye detection)
- YuNet ONNX Model (deep learning-based face detection)
- Runtime: .NET Runtime for Windows
| Package | Version |
|---|---|
| OpenCvSharp4 | 4.13.0.20260308 |
| OpenCvSharp4.Extensions | 4.13.0.20260308 |
| OpenCvSharp4.runtime.win | 4.13.0.20260302 |
All data files (XML classifiers and ONNX models) are automatically copied to the output directory during build. Ensure the data/ folder structure is maintained for proper operation.
- YuNet ONNX model provides higher accuracy but requires more computational resources
- Haar Cascade classifiers are faster and suitable for real-time applications
- Consider frame resizing for video input optimization
- Project setup with OpenCV bindings
- Import appropriate libraries
- Find all connected cameras to the machine
- Show camera data in a Canvas UI
- Store camera data to disk
- Store camera frame metadata
- Switch between multiple cameras
- Implement multi-face tracking
Contributions are welcome! Please follow these guidelines:
- Create a feature branch for your changes
- Maintain code consistency with the existing codebase
- Test thoroughly before submitting
- Update documentation as needed
Missing Data Files: Ensure the data/ directory and all XML/ONNX files are present in the output directory.
OpenCV Runtime Issues: Verify that OpenCvSharp4.runtime.win is properly installed and compatible with your system.
Performance Issues: Consider reducing image resolution or adjusting detection parameters for better performance.