Face_recognition can crop a portrait or compare a live face with an ID photo, but shipping that kind of workflow is often where the friction shows up. Offline installation gets messy, and standalone binaries tend to behave differently across systems. A Docker container makes the runtime more predictable; the fr-compare project wraps the Face_recognition service for that purpose.
Build and run
# Build the image
sudo docker build -t fr-compare:2.0.0 .
# Start the container
sudo docker run --restart=always --name fr-compare -d -p 8726:8726 fr-compare:2.0.0
After the container is running, open http://0.0.0.0:8726. The page returns:
{"code":200,"message":"face_recognition server 2.0"}
Cropping
Send a POST request to http://0.0.0.0:8726/detect with the JSON content type:
'Content-Type': 'application/json'
The request body carries a Base64 image:
{
"b64_image": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQEC..."
}
The response contains the cropped portrait and a status message:
{
"b64_image": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQEC...", "message": "success"
}
When message is "success", b64_image holds the cropped avatar. If cropping fails, message carries the error and b64_image is an empty string.
Comparison
The comparison endpoint is listed as http://0.0.0.0:8722/detect (POST). The container above is exposed on port 8726, so check the port mapping in your environment before calling this URL. It also expects Content-Type: application/json.
Request body:
{
"b64_image_01": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQEC...",
"b64_image_02": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQEC..."
}
Response:
{
"message": "ok",
"distance": 56.84
}
A higher distance value means a greater probability that the two photos belong to the same person.
Container operations
The container can be managed with regular Docker commands:
# Enter the container
docker exec -it fr-compare /bin/sh
# Check application status (the container is built on pm2)
docker exec -it fr-compare pm2 list
# Stop the container
docker stop fr-compare
Offline deployment
For offline use, build-image.sh builds and exports the image, then compresses the package. deploy.sh handles the other side: it unpacks the archive, imports the image, and starts the container.