π¨JavaScript SDK
Streamline working with your Pop on the web
EyePop.ai has introduced a dedicated npm package for JavaScript developers, streamlining the process of integrating your Pop in the web. This package ensures an efficient and user-friendly setup experience.
https://www.npmjs.com/package/@eyepop.ai/javascript-sdk
npm:
npm install@eyepop.ai/javascript-sdk
cdn:
<script src="https://cdn.jsdelivr.net/npm/@eyepop.ai/javascript-sdk"></script>
Quick Start
Refer to the following page to quickly get the EyePopSDK JavaScript demo repository up and running on your local machine.
πΎJavaScript SDK DemosSDK Usage
Here's a barebones example of the SDK for uploading and displaying an image with object identification overlays.
<form>
<input type="file" id="file_upload">
</form>
<video id="myLocalVideo" playsinline controls muted style="width:1px;height:1px;"></video>
<div style="height: 600px; width:600px;">
<canvas id="mobilecanvas" style="background-color: transparent; opacity: 1; margin:auto auto;z-index:1000;" width="100%" height="100%"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/@eyepop.ai/javascript-sdk"></script>
<script>
var config = {};
// replace with your endpoint UUID
const pop_uuid = '<POP_UUID>';
// leave this empty to launch a 'login' popup, or enter a temporary token
const token = '';
// first, fetch the Pop info
EyePopSDK.EyePopAPI.FetchPopConfig(pop_endpoint, token)
.then((response) => {
config = response;
config.input = {
"name": "file_upload"
};
console.log("EyePopSDK config: ", config);
// then start the Pop
EyePopSDK.EyePopSDK.init(config);
});
</script>API
Table of Contents
EyePopSDK
EyePopSDK
instance
instanceThe static instance of theSDK.
init(config)
init(config)The initialization function required for the SDK. This starts all media streaming and uploading, as well as drawing on top of the provided canvas. This object is created with a call to EyePopAPI.FetPopConfig(pop_endpoint, token) and appended to with the following options:
Parameters:
Example:
EyePopAPI
lastmsg
lastmsgThe last message recieved from the Pop WebSocket. Useful for synchronizing video and the drawing loop.
Example:
OnDrawFrame()
OnDrawFrame()The callback method fired at the beginning of the draw loop.
Example:
OnDrawFrameEnd(jsonData)
OnDrawFrameEnd(jsonData)The callback method fired at the end of the draw loop.
Example:
OnPrediction(jsonData)
OnPrediction(jsonData)The callback method fired when a new prediction message is received.
Example:
OnPredictionTarget()
OnPredictionTarget()The callback method fired when a target is found in the prediction data.
Example:
OnPredictionEnd()
OnPredictionEnd()The callback method fired when the analysis is completed.
Example:
onPredictionEndBase()
onPredictionEndBase()The callback method fired when the Pop has closed for any reason.
Example:
Rules
The Rules class has been specifically crafted for processing the outputs of EyePop.ai's computer vision system. It provides functionalities to construct semantic rules, helping in the identification and extraction of specific features and attributes from photos and videos.
FindObject(label, object)
FindObject(label, object)Purpose: Filters the provided list of objects based on the specified class label.
Parameters:
βlabelβ: String representing the class label of the desired object.
βobjectsβ: Array of objects.
Returns:
Array of objects that match the specified class label.
Example:
Biggest(label, object)
Biggest(label, object)Purpose: Identifies the object with the largest bounding box area for a specific class label.
Parameters:
βlabelβ: String representing the class label of the object to compare.
βobjectsβ: Array of objects.
Returns:
Single object with the largest area.
Example:
Area(object, source_width, source_height)
Area(object, source_width, source_height)Purpose: Computes the relative area of an object to the source's dimensions.
Parameters:
βobjectβ: Object whose area needs to be determined.
βsource_widthβ: Width of the source.
βsource_heightβ: Height of the source.
Returns:
Relative area (fraction) of the object with respect to the source dimensions
Example:
Between(x, min, max)
Between(x, min, max)Purpose: Checks if a given value lies between a specified range.
Parameters:
βxβ: The value to be checked.
βminβ: Minimum value of the range.
βmaxβ: Maximum value of the range.
Returns:
Boolean value indicating whether x lies between min and max.
Example:
Amount(label, objects)
Amount(label, objects)Purpose: Counts the number of objects that match a specific class label.
Parameters:
βlabelβ: String representing the class label.
βobjectsβ: Array of objects.
Returns:
Boolean indicating presence of the pose point label.
Example:
PosePoint(label, personObject)
PosePoint(label, personObject)Purpose: Determines if a person object contains a specific pose point label.
Parameters:
βlabelβ: Pose point label.
βpersonObjectβ: Object containing pose information.
Returns:
Boolean indicating presence of the pose point label.
Example:
Emotion(emotionLabel, personObject)
Emotion(emotionLabel, personObject)Purpose: Checks the inferred emotion on a person's face.
Parameters:
βemotionLabelβ: The desired emotion label.
βpersonObjectβ: Object containing facial information.
Returns:
Boolean indicating the presence of the specified emotion.
Example:
Gender(genderLabel, personObject)
Gender(genderLabel, personObject)Purpose: Checks the inferred gender label of a person based on the identified facial features.
Parameters:
βgenderLabelβ: Gender label to check.
βpersonObjectβ: Person Object containing facial information.
Returns:
Boolean indicating if the identified gender label matches the specified personObject.
Example:
Position(object1, direction, object2)
Position(object1, direction, object2)Compares the relative positions of two objects based on the specified direction.
Parameters:
βobject1β: First object.
βdirectionβ: String representing the desired direction (above, below, left, right).
βobject2β: Second object.
Returns:
Boolean indicating the relative position of object1 with respect to object2 based on the given direction.
Example:
Check(resultSet, rules, rulesState)
Check(resultSet, rules, rulesState)Purpose: Evaluates a set of conditions on the provided resultSet and tracks the state of rule evaluations.
Parameters:
βresultSetβ: Data to be evaluated.
βrulesβ: Array containing conditions to evaluate on the resultSet.
βrulesStateβ: Object to track the state of rule evaluations.
Returns:
Array of results for each rule evaluation.
Example:
Last updated