xtejs-detection

XteJS detection is a library that detects various things such as faces and licenses.
Introduction
XtejsDetection is a library that anyone can easily detect faces and objects in the browser.
We also offer a highly accurate face recognition platform and OCR.
For more information, please contact us via Facebook message (https://www.facebook.com/takuya.motoshima.7/) or email (developer.takuyamotoshima@gmail.com).
Browser Compatibility
XtejsDetection supports all browsers that are ES5-compliant (IE8 and below are not supported).
Example of detecting faces from webcam.
Example of detecting faces from images.
Example of detecting faces from video.
Installation
Install.
npm install xtejs-detection;
Copy model manifests and weights (shards) required for face detection to public directory
cp -a node_modules/xtejs-detection/dist/models {Your public directory path};
Usage
Face detection from web camera.
// HTML: <video id="webcam" playsinline muted></video> ; // Open web cameraconst webcam = document;webcamsrcObject = await navigatormediaDevices;await webcam; // Face detector instanceconst detector = document; // Attach the face detectorawait detector; // Detector event listenersdetector; // Start face detectiondetector;
Detect face from video.
// HTML: <video id="video" src="sample.mp4" playsinline loop></video> ; // Face detector instanceconst detector = document; // Attach the face detectorawait detector; // Detector event listenersdetector; // Play videodocument; // Start face detectiondetector; // Stop face detectiondetector;
Detect face from image.
// HTML: <img id="image" src="sample.png"> ; // Face detector instanceconst detector = document; // Attach the face detectorawait detector; // Detect face from imageconst results = await detector; for let result of results || // Draw face bounding box result; // Get Face image in base64 format const thumbnail = resultthumbnail;
API Reference
-
Class: FaceDetector
This class detects faces from web cameras, images, and videos.
-
new FaceDetector(input)
Construct a new FaceDetector
Parameters:
Name Type Description input HTMLImageElement|HTMLVideoElement Media elements for webcams, videos and images that detect faces Examples:
// HTML: <video id="webcam" playsinline muted></video>;// Open web cameraconst webcam = document;webcamsrcObject = await navigatormediaDevices;await webcam;// Face detector instanceconst detector = document; -
Methods
-
async attach(options)
Attach face detection features to devices
Parameters:
Name Type Description options Object Options to attach face detector to device
PropertyName Type Description models string The path where the model manifest and weights (shards) files are stored.
These are located in "https://github.com/takuya-motoshima/xtejs-detection/tree/master/dist/models", so copy them to your application's public directory.numberOfDetection number Maximum number of faces to detect.
The default is 100.motions boolean Detects facial motion.
When on, the head angle is added to the detection results.
The default is off.Returns:
Promise<void>
Examples:
// Attach the face detectorawait detector; -
async detection()
Detect face
Returns:
Returns the detection result object.
If the option numberOfDetection is 1, FaceDetectResult object is returned. If it is 2 or more, FaceDetectResult array is returned. If not detected, NULL is returned.Promise<FaceDetectResult[]|FaceDetectResult|null>
Examples:
// Detect faceconst results = await detector;// results:// [// {// rect: {// x: 545.91,// y: 190.72,// width: 277.37,// height: 212.27// },// thumbnail: 'data:image/png;base64,iVBORw0...',// roll: 40.16// }// ] -
realTimeDetection()
Start real-time face detection.
This is used when detecting a face from a web camera or video where the image is constantly changing.Examples:
// Start face detectiondetector; -
cancelRealTimeDetection()
Stop real-time face detection.
It is used when the WEB camera and video are paused.Examples:
// Stop face detectiondetector; -
on(type, listener)
Set up a real-time detection event for the face detector.
Parameters:
Name Type Description type string Event name Event name Description detected Invoke when face detection is completed. beforedetection Invokes just before detecting a face. listener Function A callback that receives notification of events.
Callback parametersEvent name Parameters detected Name Type Description results FaceDetectResult[]|FaceDetectResult|null Returns the detection result object.
If the option numberOfDetection is 1, FaceDetectResult object is returned. If it is 2 or more, FaceDetectResult array is returned. If not detected, NULL is returned.beforedetection There are no parameters. Returns:
FaceDetector
Examples:
// Detector event listenersdetector;// Start face detectiondetector;
-
-
-
Class: FaceDetectResult
This is the face detection result.
-
Members
-
readonly rect: Object
The bounding box of the detected face.
Property
Name Type Description x number The X coordinate of the face bounding box. y number The Y coordinate of the face bounding box. width number The width of the face bounding box. height number The height of the face bounding box. -
readonly roll: numbe
The roll angle of the head.
-
readonly thumbnail: string
A face image detected in Base64 format.
-
-
Methods
-
drawFaceRect()
Draw face bounding box.
Examples:
// When detecting faces from images/// Detect face from imageconst results = await detector;// Draw face bounding boxfor let result of results || result;// When detecting a face from a web camera or video// Detector event listenersdetector;// Start face detectiondetector;
-
-
Examples
There are some examples in "./examples" in this package.Here is the first one to get you started.
Credits
The original model, weights, code, etc. was created by face-api.js and can be found at https://github.com/justadudewhohacks/face-api.js/ This port and my work is in no way related to face-api.js.