AI Face Detect API

CUTOS Face Recognition Service Features:

  • Supports native camera access via browser
  • Supports CUTOS client initialization and connection
  • Supports face registration, search, deregistration, and comparison
  • Supports face image display and real-time recognition
  • Supports custom gateway and client address configuration
Installation
npm install @cutos/core
npm install @cutos/gw-client
npm install @mediapipe/tasks-vision
Import Dependencies
import { CoreAPI } from "@cutos/core";
import { Face } from './lib/cutos-ai-face.js';
import { config } from './lib/config';

Face

Constructor for creating a face recognition service instance

const faceInstance = new Face();

Face.init

Initialize the face recognition gateway service

faceInstance.init([gwUrl]);
  • gwUrl: Face recognition server address.
    • If not provided: connects to the server associated with the device
    • If provided: connects to the specified server IP

Face.detectSingleFace

Detects a single face from the camera feed

faceInstance.detectSingleFace(videoElement);
  • videoElement: <video> DOM element
Example:
//index.html
 <video class="cam-video" autoplay muted playsinline id="cam"></video>
        ...
//main.js
const $cam = document.querySelector('#cam')
const result = faceInstance.detectSingleFace($cam);
console.log(result)
  • Example result:
{
  "face": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAA",
  "fullFrame": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAA",
  "score": 0.9609517455101013
}
  • result.face: Detected face image
  • result.fullFrame: Original captured frame image (base64 Blob)
  • result.score: Confidence score (0-1),Confidence score of face detection (0–1). Detection is considered successful if the score exceeds 0.9.

Face.register

Register a face image

faceInstance.register(fullFrame)
  • fullFrame: Image in base64 format
Example:
const id = faceInstance.register('data:image/jpeg;base64,/9jtUgA.../Z);')
console.log(id)
  • Example result:
"f956ac67-0dd8-4dc4-ae5b-55f37d99bc6b" // Returns ID after successful registration

Face.search

Search for a registered face

faceInstance.search(fullFrame)
  • fullFrame: Image in base64 format
Example:
const result = faceInstance.search('data:image/jpeg;base64,/9jtUgA.../Z);');
console.log(result)
  • Example result:
{
  "id": "f956ac67-0dd8-4dc4-ae5b-55f37d99bc6b",
  "payload": {},
  "score": 0.9953916239059821
}
  • result.id: Matched ID
  • result.score: Matching score

Face.unregister

Deregister a face ID

faceInstance.unregister(id);
Example:
const id = faceInstance.unregister("f956ac67-0dd8-4dc4-ae5b-55f37d99bc6b");
console.log(id)
  • Example result:
"f956ac67-0dd8-4dc4-ae5b-55f37d99bc6b" // Returns ID after successful deregistration

Face.compare

Compare two face images

faceInstance.compare(image1, image2);
  • image1: First face image in base64 format
  • image2: Second face image in base64 format
Example:
const score = faceInstance.compare('data:image/jpeg;base64,/9j/4...', 'data:image/jpeg;base64,/9j/4...');
console.log(score)
  • Example result:
0.9973043918609619 //Matching is considered successful if the score exceeds 0.9.

results matching ""

    No results matching ""