Last active
August 26, 2025 17:55
-
-
Save symisc/86d33e975a2dc9cb6a81288180a2b3ab to your computer and use it in GitHub Desktop.
Check whether two given faces in different images belong to the same person or not using the FACEIO API - https://faceio.net/rest-api#faceverify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Face Verification API - Programmatically Compare Two Faces in Different Images | |
| # | |
| # Documentation: - https://faceio.net/rest-api#faceverify | |
| # | |
| # The Face Verify API endpoint allow you to programmatically compare (check) whether two faces | |
| # in different images belong to the same person. This API is ideal for programmatic face checks | |
| # that don't require user interaction. Simply upload two images, each containing a single face, | |
| # using your preferred programming language, and the algorithm determines if the faces belong to the same person. | |
| import requests | |
| import json | |
| import base64 | |
| # Load an image from disk and encode it in base64. | |
| def load_image_and_encode(image_path): | |
| with open(image_path, "rb") as image_file: | |
| encoded_string = base64.b64encode(image_file.read()).decode('utf-8') | |
| mime_type = "image/jpeg" # Or determine the MIME type dynamically | |
| return f"data:{mime_type};base64,{encoded_string}" | |
| source_face_img_path = "path/to/face1.jpg" # Replace with the actual path to your source face image | |
| target_face_img_path = "path/to/face2.jpg" # Replace with the actual path to your target face (to compare to source) image | |
| # Or if the face image is on Public URL, just pass it as is: | |
| # source_face_url = "https://example.com/face1.jpg" # In case of public image URL | |
| payload = { | |
| "key": "apiKey", # Get your API key from the FACEIO Console at - https://console.faceio.net/ | |
| "src": load_image_and_encode(source_face_img_path), | |
| "target": load_image_and_encode(target_face_img_path) | |
| } | |
| try: | |
| response = requests.post( | |
| "https://api.faceio.net/faceverify", | |
| headers={"Content-Type": "application/json"}, | |
| json=payload | |
| ) | |
| response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) | |
| print(response.json()) | |
| # JSON Object is always returned | |
| # { | |
| # dist: 'Distance Metric', | |
| # sim: 'Similarity Score', | |
| # same_person: 'Boolean Value' | |
| # } | |
| except requests.exceptions.RequestException as e: | |
| print(f"An error occurred: {e}") | |
| except json.JSONDecodeError as e: | |
| print(f"Error decoding JSON: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Determine if the provided faces represent the same individual or not using the FACEIO FACEVERIFY API Endpoint documented at: https://faceio.net/rest-api#faceverify