SDK Detocated

This SDK He's deprecated. JAAK Visage SDK Web as a substitute.

facedetector@v.1.6.0 It's a web component that allows optimal face capture.

Introduction

The component FaceDetectorComponent That component forms part of an ecosystem with interoperable web components that are compatible with the main standards of the Web. Its architecture based on Shadow DOM, slots and style encapsulation allows for clear, secure and maintenance integration in any enabling environment.

Key functionality

  • Local file Loading: Users can select images from their device. The component valids the file and, if they meet the criteria of a legible document, emits the encoded result at Base64.
  • Camera capture: It activates the device's camera to automatically detect a face in real time. By detecting one under best conditions, capture and emits encoded data also at Base64.

Installation

Use the following command to install the package from NPM:

  1. Requires:

    • Node.js and npm installed.
    • Download from: https://nodejs.org
    • Check the installation:
      node -v
      npm -v
      
  2. Start your project (if applicable):

    npm init
    
  3. Install package:

npm install @jaak.ai/face-detecto
  1. Confirm the installation: Check that the package is listed at package.json.

Alternative installation option

Also you can install the component directly with a label <script> at the head head HTML:

<script
  type="module"
  src="https://unpkg.com/@jaak.ai/document-detector"></script>

Rapid Use

<face-detector
  config={{
    width: '640px',
    height: '480px',
    enableMicrophone: true,
    mode: 'video-camera',
    placeholder: 'Put your document up.',
    buttonText: 'Subir',
    documentAccept: 'image/*',
    description: 'Please put up a legible image.',
    size: 2048
  }}
  onStatus={(event) => handleStatusChange(event.detail)}
  onComponentError={(event) => handleComponentError(event.detail)}
  onFileResult={(event) => handleFileResult(event.detail)}
></face-detector>

Component properties

Component Setup config: ConfigComponent (optional)

PropertyTypeDescription
widthstringWidth of the component (e.g. '640px'). Default: '500px'
heightstringHeight of the component (e.g. '480px'). Default: '400px'
enableMicrophonebooleanTurn on the bug. false
modelstringOperating mode: 'video-camera' or 'upload-file'
placeholderstringField text to upload file
buttonTextstringLoading button text
documentstringRequired file types (e.g. image/*)
descriptionstringDescription shown next to the input
sizenumberMaximum permitted size (KB)
videonumbervideo duration in seconds
videoMediumVideo restrictions (resolution, fps). See class details here.
cameraSourcestringCamera to use: 'user' or 'environment'
videostringVideo format: '1920x1080\ @ 30', etc.
autoRecorderbooleanRecord automatically if you detect a face
HideFaceTrackerbooleanHide facial detection figure
FaceDetectionbooleanUntiring facial detection
progressbooleanCan record multiple consecutive videos without automatically stopping
muteFaceDetectionMessagesbooleanSilent messages from the detection system
HideTimerbooleanHide the recording indicator
timerStylesTimerStylesTimer Style
faceTrackerStylesFaceTrackerStylesStyle of figure that sets face
offlinesModelbooleanLoad model without network requests (offline)
enableInstructionsbooleanIt allows you to display instructions to guide the user in face detection.
delayInstructionsnumberTime in milliseconds to show each instruction during first run. By default: 3000ms.
delayReplayInstructionsnumberTime in milliseconds to show each instruction during repetitions. By default: 3000ms.
instructionsButtonstringText that will be displayed in the button that allows users to play the instructions.

Interface TimerStyles

Define the collection indicator style at the configuration property timerStyles:

PropertyTypeDescription
colorstringTimer text color
circlestringColor of the circle of progress
circlestringColor of the circle bottom
circlestringColor while successfully complete
widthnumberCircle width
heightnumberCircle stop
fondSizenumbertext size
posXnumberHorizontal position (0 - 100)
posYnumberVertical position (0 - 100)
strokeWidthnumberTrack width
dashArraystringStretch pattern

Interface FaceTrackerStyles

Customize the detection colors at the configuration property faceTrackerStyles:

PropertyTypeDescription
validColorstringvalid detection color
InvalidColorstringInvalid detection color

Show Instructions for Use

Enabling property enableInstructions within component configuration object config: ConfigComponent, using the following properties to customize the instructions.

PropertyTypeDescription
instructionsAnimationstring[]I fix routes to the animation archives used for instructions.
instructionsTextstring[]Settle text chains to display with every training animation.

You can customize the animated instructions and associated texts following the following example:

const faceDetector = document.querySelector('face-detector');

// Enabling instructions at config
faceDetector.config = {
  // ... other properties of ConfigCompact
  enableInstructions: true,
};

// Animated instructions (.lav format from an URL)
faceDetector.instructionsAnimation = [
  "https://raw.githubusercontent.com/jaak-ai/jaak-storage/main/animations/rive/glasses.riv",
  "https://raw.githubusercontent.com/jaak-ai/jaak-storage/main/animations/rive/hat.riv",
  "https://raw.githubusercontent.com/jaak-ai/jaak-storage/main/animations/rive/headphones.riv",
  "https://raw.githubusercontent.com/jaak-ai/jaak-storage/main/animations/rive/light.riv",
];

// A descriptive text associated with each animation
faceDetector.instructionsText = [
  "No lenses",
  "No hat",
  "No hearing aids",
  "Adjust light without contralux",
];

Events

EventNameDescription
statusStatusFaceDetectorCurrent status of component
componentErrorwebComponentErrorErrors occurring within component
fileResultFileResultResult of the captured file
faceDetectionMessageFaceDetectionMessageResults of face detection system

Methods

MethodParametersReformsDescription
turnOffFaceDetectornonevoidStarts facial detection
switchMode'video-camera' / 'upload-file'voidSwitch
stopComponentnonevoidStops all operations
restartComponentnonevoidReboot component
getModenonestringReturns current mode
recordVideononestring (Base64)Begins and returns video
takeSnapshotnonestring (Base64)Capture an image
getVideoElementnoneHTMLVideoElementReforms video item
getStreamnoneMediaStreamReforms the stream of the camera
toggleCameranonevoidSwitch between cameras (front and back)
stopVideoStreamnonevoidStops video stream
restartVideoStreamnonevoidReboot video stream
resetFaceDetectorresetHard: booleanvoidReboot internal configuration

Additional interfaces

FileResult

Reacts data from face detection result

PropertyTypeDescription
base64stringFile encoded at base64
TypestringMIME type (optional)
namestringOriginal name of file (optional)
sizenumberFile size in bytes (optional)

FaceDetectionMessage

Returns message data during face detection

PropertyTypeDescription
LabelstringGeneral description of the result
detailsstringAdditional details
faceExistbooleanindicates if a face was detected
receptPositionbooleanindicates if his face's in the right place

webComponentError

Returns data from the resulting error

PropertyTypeDescription
LabelstringMessage of error
codestringError code (optional)
detailsanyAdditional information about error (optional)

Example of Basic Implementation

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Face Detector Usage</title>
		<script type="module" src="https://unpkg.com/@jaak.ai/face-detector"></script>
	</head>
	<body>
		<div class="content">
			<face-detector id="faceDetector"></face-detector>
		</div>
	</body>
	<style>
		.content {
			height: 90vh;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 10px;
			margin-top: 1rem;
		}
	</style>

	<script type="module">
		// Select the face-detector component
		const faceDetector = document.querySelector('face-detector');

		// Configure component with initial adjustments
		const config = {
			mode: 'video-camera',
			timerStyles: {
				width: 80,
				height: 80,
				fontSize: 40,
				posY: 70,
			},
			width: '100%',
			height: '100%',
			offlineModel: false,
			validateCamera: true,
			enableInstructions: true,
			delayInstructions: 1000,
			delayReplayInstructions: 3000,
			autoRecorder: true,
		};

		faceDetector.config = config;

		// Handling mistakes
		faceDetector.addEventListener('componentError', (event) => {
			console.error('Failed event:', event.detail);
			// Display error messages to user
		});

		// Handling file results
		faceDetector.addEventListener('fileResult', (event) => {
			console.log('Successful capture video:');
			// Procure the result of the file, for example, display the image or video
			console.log(event.detail.base64);
		});
	</script>
</html>

Additional

Example Repository

Can be supported with a functional example at the following repository: https://github.com/jaak-ai/face-detector-js-example