Smart TV
API References
ObjectDetection API
To use Samsung Product API,
<script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script>
Should be loaded in index.html
This module defines the functions of object detection using AIFW
that are provided as the Tizen Samsung Product API.
Since : 9.0
Product : TV
Summary of Interfaces and Methods
1. Type Definitions
1.1 ObjectDetectionType
Specifies the object detection type.
enum ObjectDetectionType {
"FACE",
"BODY"
};
The following values are supported
FACE : detection type is face.
BODY : detection type is body.
1.2 ObjectDetectionHandle
Defines the handle of the object detection. It is created through create(), and the created handle is
invalid after destroy() is called. The Object Detection API identifies the Detection created through
the ObjectDetectionHandle parameter.
typedef DOMString ObjectDetectionHandle;
2. Interfaces
2.1 Roi
Roi(region of interest) information, value is between 0 and 1.
[NoInterfaceObject] interface Roi {
readonly attribute double x;
readonly attribute double y;
readonly attribute double width;
readonly attribute double height;
};
Attributes
readonly double x
Indicates x-coordinate of top, left corner of the roi
readonly double y
Indicates y-coordinate of top, left corner of the roi
readonly double width
Width of the roi
readonly double height
Height of the roi
2.2 OutputInfo
Object detection information.
[NoInterfaceObject] interface OutputInfo {
readonly attribute DOMString lableName;
readonly attribute double lableIndex;
readonly attribute double confidence;
readonly attribute Roi roi;
};
Attributes
readonly DOMString lableName
The label's text description
readonly double lableIndex
Reserved variable, it's used to indicate the label's index among
all the labels supported by the classifier which maybe used in the
feature.
readonly double confidence
The confidence of the detection information.
readonly Roi roi
The Roi information of detected object
2.3 ObjectDetectionManagerObject
Defines a WebApi object instance of the Tizen Samsung Product API.
The webapis.objectdetection object enables access to Object
Detection API functionality.
[NoInterfaceObject] interface ObjectDetectionManagerObject {
readonly attribute ObjectDetectionManager objectdetection;
};
WebApi implements ObjectDetectionManagerObject;
Attributes
2.4 ObjectDetectionManager
Provides methods for Object Detection functionalities.
[NoInterfaceObject] interface ObjectDetectionManager {
DOMString getVersion();
ObjectDetectionHandle create();
void init(ObjectDetectionHandle handle, ObjectDetectionType detectionType);
OutputInfo[] run(ObjectDetectionHandle handle, DOMString url);
OutputInfo[] runWithBuffer(ObjectDetectionHandle handle, DOMString buffer);
void deinit(ObjectDetectionHandle handle);
void destroy(ObjectDetectionHandle handle);
};
Methods
getVersion
Retrieves the plugin version number.
DOMString getVersion();
Return Value :
DOMString : Plugin version
Exceptions :
WebAPIException
with error type NotSupportedError, if this API is called for products which don't support object detection.
Code Example :
try {
let value = webapis.objectdetection.getVersion();
console.log("version value = " + value);
} catch (error) {
console.error("error code = " + error.code + ", error name = " + error.name + ", error message = " + error.message);
}
create
Create a new instance of object detection. You should call the method first to use object detection.
ObjectDetectionHandle create();
Return Value :
Exceptions :
WebAPIException
with error type NotSupportedError, if this API is called for products which don't support object detection.
with error type UnknownError, for any other error.
Code Example :
try {
let handle = webapis.objectdetection.create();
} catch (error) {
console.error("error code = " + error.code + ", error name = " + error.name + ", error message = " + error.message);
}
init
Initialize object detection.
There are two types, "FACE" or "BODY".
If you want to detect face, it should be "FACE" type.
If you want to detect body, it should be "BODY" type.
void init(ObjectDetectionHandle handle, ObjectDetectionType detectionType);
Parameters :
handle : handle of object detection.
detectionType : object detection type "FACE" or "BODY".
Exceptions :
WebAPIException
with error type NotSupportedError, if this API is called for products which don't support object detection.
with error type TypeMismatchError, if the type of the parameters passed into the function is incorrect.
with error type InvalidValuesError, if any input parameter contains an invalid value.
with error type UnknownError, for any other error.
Code Example :
try {
let handle = webapis.objectdetection.create();
webapis.objectdetection.init(handle, detectionType); //you should call init() before calling run().
} catch (e) {
console.error("error code = " + error.code + ", error name = " + error.name + ", error message = " + error.message);
}
run
Run object detection with a content URL to get the detected object rois from it.
OutputInfo[] run(ObjectDetectionHandle handle, DOMString url);
Parameters :
handle : handle of object detection
url : Content URL,It should be an absolute local path of a PNG image
Return Value :
OutputInfo [] : a array which include all detected objects info, see the description of OutputInfo
Exceptions :
WebAPIException
with error type NotSupportedError, if this API is called for products which don't support object detection.
with error type TypeMismatchError, if the type of the parameters passed into the function is incorrect.
with error type InvalidValuesError, if any input parameter contains an invalid value.
with error type UnknownError, for any other error.
Code Example :
try {
let handle = webapis.objectdetection.create();
webapis.objectdetection.init(handle, "FACE");
let outputs = webapis.objectdetection.run(handle, "/opt/media/USBDriveA1/images/face.png"); //you should call run() after calling init().
console.log("Detected objects number:" + outputs.length);
for (let i = 0; i < outputs.length; i ++) {
console.log("the detected information of Object[" + i + "] is as following:");
console.log("lableName: " + outputs[i].lableName + ", labelIndex: " + outputs[i].labelIndex + ", confidence: " + outputs[i].confidence);
console.log("roi: [" + outputs[i].roi.x + ", " + outputs[i].roi.y + ", " + outputs[i].roi.width + ", " + outputs[i].roi.height + "]");
}
} catch (e) {
console.error("error code = " + error.code + ", error name = " + error.name + ", error message = " + error.message);
}
runWithBuffer
Run object detection with a base64 encoded buffer parameter to get the detected object rois from it.
OutputInfo[] runWithBuffer(ObjectDetectionHandle handle, DOMString buffer);
Parameters :
handle : handle of object detection
buffer : It should be base64 encoded buffer data of a PNG image file
Return Value :
OutputInfo [] : a array which include all detected objects info, see the description of OutputInfo
Exceptions :
WebAPIException
with error type NotSupportedError, if this API is called for products which don't support object detection.
with error type TypeMismatchError, if the type of the parameters passed into the function is incorrect.
with error type InvalidValuesError, if any input parameter contains an invalid value.
with error type UnknownError, for any other error.
Code Example :
try {
let handle = webapis.objectdetection.create();
webapis.objectdetection.init(handle, "FACE");
let outputs = webapis.objectdetection.runWithBuffer(handle, "/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPU..."); //you should call runWithBuffer() after calling init().
console.log("Detected objects number:" + outputs.length);
for (let i = 0; i < outputs.length; i ++) {
console.log("the detected information of Object[" + i + "] is as following:");
console.log("lableName: " + outputs[i].lableName + ", labelIndex: " + outputs[i].labelIndex + ", confidence: " + outputs[i].confidence);
console.log("roi: [" + outputs[i].roi.x + ", " + outputs[i].roi.y + ", " + outputs[i].roi.width + ", " + outputs[i].roi.height + "]");
}
} catch (e) {
console.error("error code = " + error.code + ", error name = " + error.name + ", error message = " + error.message);
}
deinit
Deinitialize object detection. If you have called init function, you should call deinit before terminating your application.
void deinit(ObjectDetectionHandle handle);
Parameters :
handle : handle of object detection
Exceptions :
WebAPIException
with error type NotSupportedError, if this API is called for products which don't support object detection.
with error type TypeMismatchError, if the type of the parameters passed into the function is incorrect.
with error type UnknownError, for any other error.
Code Example :
try {
let handle = webapis.objectdetection.create();
webapis.objectdetection.init(handle, "FACE");
webapis.objectdetection.run(handle, "/opt/media/USBDriveA1/images/face.png");
webapis.objectdetection.deinit(handle); //you should call deinit() after using object detection.
} catch (e) {
console.error("error code = " + error.code + ", error name = " + error.name + ", error message = " + error.message);
}
destroy
Destroy an instance of object detection. If you have called create function, you should call destroy before terminating your application.
void destroy(ObjectDetectionHandle handle);
Parameters :
handle : handle of object detection
Exceptions :
WebAPIException
with error type NotSupportedError, if this API is called for products which don't support object detection.
with error type TypeMismatchError, if the type of the parameters passed into the function is incorrect.
with error type UnknownError, for any other error.
Code Example :
try {
let handle = webapis.objectdetection.create();
webapis.objectdetection.init(handle, "FACE");
webapis.objectdetection.run(handle, "/opt/media/USBDriveA1/images/face.png");
webapis.objectdetection.deinit(handle);
webapis.objectdetection.destroy(handle);
} catch (e) {
console.error("error code = " + error.code + ", error name = " + error.name + ", error message = " + error.message);
}
3. Full WebIDL
module ObjectDetection {
enum ObjectDetectionType {
"FACE",
"BODY"
};
typedef DOMString ObjectDetectionHandle;
[NoInterfaceObject] interface Roi {
readonly attribute double x;
readonly attribute double y;
readonly attribute double width;
readonly attribute double height;
};
[NoInterfaceObject] interface OutputInfo {
readonly attribute DOMString lableName;
readonly attribute double lableIndex;
readonly attribute double confidence;
readonly attribute Roi roi;
};
[NoInterfaceObject] interface ObjectDetectionManagerObject {
readonly attribute ObjectDetectionManager objectdetection;
};
WebApi implements ObjectDetectionManagerObject;
[NoInterfaceObject] interface ObjectDetectionManager {
DOMString getVersion();
ObjectDetectionHandle create();
void init(ObjectDetectionHandle handle, ObjectDetectionType detectionType);
OutputInfo[] run(ObjectDetectionHandle handle, DOMString url);
OutputInfo[] runWithBuffer(ObjectDetectionHandle handle, DOMString buffer);
void deinit(ObjectDetectionHandle handle);
void destroy(ObjectDetectionHandle handle);
};
};