Punch cards get shared. Fingerprint scanners spread germs and fail on worn fingertips. A face recognition attendance system fixes both: an employee looks at a camera, the system matches the face against a registered repository, and the check-in is logged. No hardware beyond a webcam or phone.
This builds one in Python with a face analysis REST API, no OpenCV, dlib, or local model required.
Want to see the matching in action? Try the Face Analyzer API with two photos.
Why a REST API instead of OpenCV
Rolling your own means dlib or a deep model, a GPU for reasonable latency, and ongoing maintenance of the recognition pipeline. A REST API handles detection, embedding, and matching server-side. You manage a face repository and call two endpoints.
Setting up the face repository
import requests
BASE = "https://faceanalyzer-ai.p.rapidapi.com"
HEADERS = {
"x-rapidapi-host": "faceanalyzer-ai.p.rapidapi.com",
"x-rapidapi-key": "YOUR_API_KEY",
}
requests.post(
f"{BASE}/create-facial-repository",
headers={**HEADERS, "Content-Type": "application/x-www-form-urlencoded"},
data={"repository_id": "office-hq"},
)
Registering employees
def register_employee(photo_path, employee_id):
with open(photo_path, "rb") as f:
r = requests.post(
f"{BASE}/save-face-in-repository",
headers=HEADERS,
files={"image": (photo_path, f, "image/jpeg")},
data={"repository_id": "office-hq", "external_id": employee_id, "max_faces": "1"},
)
return r.json()
register_employee("alice.jpg", "EMP-001")
register_employee("bob.jpg", "EMP-002")
See the repository-management details in the complete tutorial.
The check-in endpoint
At check-in, search the repository for the captured face:
def check_in(photo_path):
with open(photo_path, "rb") as f:
r = requests.post(
f"{BASE}/search-face-in-repository",
headers=HEADERS,
files={"image": (photo_path, f, "image/jpeg")},
data={"repository_id": "office-hq"},
)
matches = r.json()["body"].get("FaceMatches", [])
return matches[0]["ExternalImageId"] if matches else None
employee = check_in("checkin_capture.jpg")
print(f"Checked in: {employee}" if employee else "No match, try again")
Wrapping it in Flask
from flask import Flask, request, jsonify
from datetime import datetime
app = Flask(__name__)
@app.route("/checkin", methods=["POST"])
def checkin():
file = request.files["image"]
file.save("/tmp/capture.jpg")
emp = check_in("/tmp/capture.jpg")
if emp:
return jsonify({"employee_id": emp, "time": str(datetime.now())})
return jsonify({"error": "no match"}), 404
Anti-spoofing and privacy
Pair the check-in with a liveness step (ask for a blink or head turn) to block photo-of-a-photo buddy punching. For GDPR compliance, store only the repository's face identifiers, get explicit employee consent, and provide a delete path with the delete-face-from-repository endpoint.
Face recognition vs fingerprint
Face recognition is contactless, works on any phone or webcam, and is hard to share. Fingerprint hardware is cheap but fails on worn fingertips and raises hygiene concerns. For distributed or remote teams, the camera-based approach wins on reach.
Read the full tutorial with the complete Flask app, cURL tests, and JavaScript examples on ai-engine.net.
Top comments (0)