3/9/2023
First, you need to create an account on Luxand.cloud and obtain an API key. Install the required libraries by running the following command in your terminal:
pip install requests
#!/usr/bin/env python3
import requests
import json
Define a function to add faces to the database:
def add_face(api_key, image_path, name):
url = "https://api.luxand.cloud/subject/v2"
headers = {"token": api_key}
data = {"name": name}
files = {"photo": open(image_path, "rb")}
response = requests.post(url, headers=headers, data=data, files=files)
result = json.loads(response.text)
if response.status_code == 200:
print(f"Face added: {name}, ID: {result['id']}")
return result['id']
else:
print(f"Error adding face: {result['error']}")
api_key = "your_api_key"
image_path = "path_to_image"
name = "person_name"
subject_id = add_face(api_key, image_path, name)
Replace your_api_key, path_to_image, and person_name with your actual API key, image file path, and the person's name, respectively.
def recognize_face(api_key, image_path):
url = "https://api.luxand.cloud/photo/search"
headers = {"token": api_key}
files = {"photo": open(image_path, "rb")}
response = requests.post(url, headers=headers, files=files)
result = json.loads(response.text)
if response.status_code == 200:
if result['status'] == "success":
print(f"Recognized face: {result['name']}, ID: {result['id']}, Confidence: {result['confidence']}")
else:
print("No match found")
else:
print(f"Error recognizing face: {result['error']}")
image_path_recognition = "path_to_image_for_recognition"
recognize_face(api_key, image_path_recognition)
Replace path_to_image_for_recognition with the actual image file path for recognition.