This is a face recognition login package using Go and OpenCV (gocv).
- Face detection using Haar cascades
- Face recognition using OpenCV's FaceRecognizer
- Model training and updating
- Easy API for face registration and recognition
go get -u github.com/mahmoud-italy/face-recognition-loginInstall pkg-config and OpenCV
Depending on your OS using the appropriate command:
Ubuntu/Debian
sudo apt update
sudo apt install -y pkg-config
sudo apt install -y libopencv-devMac (Homebrew)
brew install pkg-config
brew install opencvWindows (Using MSYS2) If you're on Windows, install MSYS2 and then run
pacman -S mingw-w64-x86_64-pkg-configDownload and install OpenCV from the official website: https://opencv.org/releases Set the OpenCV_DIR environment variable to the installation path.
Verify Installation Run the following command to check if pkg-config is properly installed:
pkg-config --versionIf it prints a version number, pkg-config is working. Also, check if OpenCV is found by running:
pkg-config --modversion opencv4If it returns an OpenCV version number (e.g., 4.5.2), everything is good.
import (
"fmt"
facerecognition "github.com/mahmoud-italy/face-recognition-login"
)
func main() {
faceRec, _ := facerecognition.NewFaceRecognizer("assets/haarcascade_frontalface_default.xml", "models/face_model.yml")
faceRec.RegisterFace("data/test_faces/face1.jpg", 1)
label, confidence, _ := faceRec.RecognizeFace("data/test_faces/face1.jpg")
fmt.Printf("Recognized label: %d, Confidence: %f\n", label, confidence)
}go testThe MIT License (MIT). Please see License File for more information.
Feel free to contribute by submitting issues or pull requests.