
Hi !
Let’s do some face detection using one of the most popular methods: Haar Casacades (See references). I won’t write about Cascades, there are almost 20 years of online documentation available.

And, IMHO opinion code is much more useful that long writing, so let’s go there.
1st load the cascade definition file.
_faceCascade = new CascadeClassifier();
_faceCascade.Load("haarcascade_frontalface_default.xml");
And, once we grab the camera frame, let’s perform some face detection:
using var gray = new Mat();
Cv2.CvtColor(newImage, gray, ColorConversionCodes.BGR2GRAY);
var faces = _faceCascade.DetectMultiScale(gray, 1.3, 5);
foreach (var face in faces)
{
Cv2.Rectangle(newImage, face, Scalar.Red);
Cv2.PutText(newImage, "Face Cascade", new Point(face.Left + 2, face.Top + face.Width + 20), HersheyFonts.HersheyComplexSmall, 1, Scalar.Red, 2);
}
And, the full code is here
That’s all for today!
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno
References
- OpenCVSharp, https://github.com/shimat/opencvsharp
- Wikipedia, Canny Edge Detector
- OpenCV, Canny tutorial
- OpenCV, FAST tutorial
- Wikipedia, FAST
- OpenCV, Perform face detection using Haar Cascades
Net 5 and OpenCV
- 13 lines to display a π¦ camera feed with OpenCV and Net5
- Detecting edges on the π¦ camera feed with Canny algorithm, OpenCV and Net5
- Detecting corners on the π¦ camera feed with FAST algorithm, OpenCV and Net 5
- Display the π¦ camera feed in a WinForm using OpenCV and Net5
- Face Detection using Face Cascades on the π¦ camera feed using OpenCV and Net 5
- Face Detection using DNN on the π¦ camera feed using OpenCV and Net 5
- Face Detection, DNN vs Haar Cascades on the π¦ camera feed using OpenCV and Net 5
- Age and Gender estimation on the π¦ camera feed using OpenCV and Net 5
- Caffe Model Zoo (GoogleNet) detection from the π¦ camera feed using OpenCV and Net5
- Pose detection from the π¦ camera feed using OpenCV and Net5
- Packaging a WinForm OpenCV and Net5 App in a one-self contained file
- Display a video file π₯ in Winform using OpenCV and Net5
- Open a video file π₯ and save each frame as a PNG πΌ file to a folderΒ π
- (Coming Soon) QR Codes detection on the π¦ camera feed using OpenCV and Net 5
1 comment