Public API
JSHG provides the following functions for you to integrate it with your applications:
1. JSHG.init()
Description: This function must be called before running JSHG. It initializes all necessary components, variables for JSHG and creates a secondary thread to detect hand gestures from the frames of web camera.
Parameters: It requires a javascript object as a parameter. That object contains following properties:
Name | Type | Required | Description |
---|---|---|---|
actionCallback | function | yes | the function JSHG will call to pass a HandGesture object detected from web camera frames. More details about the HandGesture object can be found at here. |
learnCallback | function | no | the function JSHG will call when it finishes the learning process. No argument is passed to this function. |
learnDivId | string | no | the id of a <div> on DOM where you want JSHG to show web camera video to learn skin color from users. |
gestureDivId | string | no | the id of a <div> on DOM where you want JSHG to show the gesture images. |
settings | Object | no | you can customize JSHG by passing an object to this parameter. The available options are mentioned at here. |
workerConfig | Object | no | This parameter should be used by advanced users. If you create your own worker to detect hand gestures, you can pass configs to the worker by this parameter. JSHG uses JSCV library by default. Only one property is available. It is "parallelMode", accepts "true" or "false". |
<div id="gestureShownHere"></div>
<script>
var actionMapper = function(gesture) {
if (gesture.isLeft)
console.log("Hey, your hand is on the left side");
...
}
JSHG.init({
"actionCallback": actionMapper,
"learnDivId": "gestureShownHere",
"gestureDivId": "gestureShownHere",
"settings": {
"cameraWidth": 500,
"cameraHeight": 400,
"gestureDisplayWidth": 100,
"gestureDisplayHeight": 80
},
});
</script>
2. JSHG.run()
Description: this function is called to start JSHG. It starts reading the web camera frame and process the image data.
Precondition: JSHG.init() must be called before calling this function.
3. JSHG.learnSkinColor()
Description: This function is to start the learning process. After the learning process, JSHG.run() is called automatically and the learned colors are saved into localStorage.
Precondition: JSHG.init() must be called before calling this function.
4. JSHG.stop()
Description: This function is to stop JSHG. It does not release any resources. It just pauses the camera video and remain the status of KSHG
Precondition: JSHG.run() or JSHG.learnSkinColor() must be called before calling this function.
5. JSHG.delete()
Description: This function releases all resources. After calling this function, JSHG.init() must be called before JSHG can be used.
6. JSHG.isRunning()
Description: it returns true if JSHG is running; otherwise, returns false.