所有导出的 C 函数可通过 Module._FunctionName() 在 JavaScript 中直接调用。WASM 模块通过 createAMTBioFeature() 加载。
Module Loading
import createAMTBioFeature from './amtbiofeature.js';
const Module = await createAMTBioFeature({ print, printErr });
Lifecycle
| Function | Return | Description |
|---|---|---|
Module._AMTBioFeatureWasm_Init(model_data, model_size, config_data, config_size) | int | Initialize SDK (pass null, 0, null, 0 for defaults) |
Module._AMTBioFeature_Init() | int | Alias — same as above with no args; returns 0 on success |
Module._AMTBioFeature_Release() | void | Release SDK and free all internal resources |
Module._AMTBioFeature_ReleaseHandle(handle) | void | Release a detection handle returned by DetectPixels |
Module._AMTBioFeature_Version() | char* | Return version string (use Module.UTF8ToString()) |
Configuration
| Function | Return | Description |
|---|---|---|
Module._AMTBioFeature_SetMinSize(min_size, cls) | void | Set minimum object size in px (cls=-1 for all, 1 for palm) |
Module._AMTBioFeature_SetMaxCount(max_count, cls) | void | Set max detections per frame |
Module._AMTBioFeature_SetThreshold(first, second, cls) | void | Set score thresholds (range 0.0–1.0) |
Module._AMTBioFeature_SetInputSize(width, height) | void | Set expected input image dimensions |
Detection
| Function | Return | Description |
|---|---|---|
Module._AMTBioFeature_DetectPixels(handlePtr, dataPtr, width, height, channels, format) | int | Zero-copy palm detection from raw RGB pixels. handlePtr is output (int*), format=0 for RGB. Returns 0 on success. |
Usage:
const rgb = new Uint8Array(pixelCount * 3); // RGB888 pixels
const dataPtr = Module._malloc(rgb.length);
Module.HEAPU8.set(rgb, dataPtr);
const handlePtr = Module._malloc(4);
const ret = Module._AMTBioFeature_DetectPixels(
handlePtr, dataPtr, width, height, 3, 0
);
if (ret === 0) {
const handle = Module.getValue(handlePtr, 'i32');
// ... get results ...
Module._AMTBioFeature_ReleaseHandle(handle);
}
Module._free(handlePtr);
Module._free(dataPtr);
Results
| Function | Return | Description |
|---|---|---|
Module._AMTBioFeature_GetObjectCount(handle) | int | Number of detected objects |
Module._AMTBioFeature_GetObject(handle, index, objPtr) | int | Populate TObject struct at objPtr. Returns 0 on success. |
TObject struct layout (52 bytes):
| Offset | Type | Field |
|---|---|---|
0 | i32 | class_id (1 = palm) |
4 | float | box.x |
8 | float | box.y |
12 | float | box.width |
16 | float | box.height |
20 | i32 (pointer) | landmarks pointer to TLandmark array |
24 | i32 | landmark_count (9 for palm) |
28 | float | yaw |
32 | float | roll |
36 | float | pitch |
40 | float | score (0.0–1.0) |
44 | i32 | track_id |
48 | i32 | state |
Quality & Direction
| Function | Return | Description |
|---|---|---|
Module._AMTBioFeature_GetQualityColor(handle, index, scorePtr) | int | Get visible-light palm quality score (0–100). Returns > 0 on success. |
Module._AMTBioFeature_GetDetectionQuality(handle, index, scorePtr) | int | Get overall detection quality score. Returns > 0 on success. |
Module._AMTBioFeature_GetPalmDirection(handle, index, scorePtr) | int | Get palm direction: >= 0.5 = left hand, < 0.5 = right hand. Returns 0 on success. |
License
| Function | Return | Description |
|---|---|---|
Module._AMTBioFeature_CheckLic() | int | Returns 0 if license is valid |
Module._AMTBioFeature_SetLic(content) | int | Set license key string. Returns 0 on success. |
Memory (Low-level)
| Function | Description |
|---|---|
Module._malloc(size) | Allocate size bytes in WASM linear memory, return pointer |
Module._free(ptr) | Free previously allocated memory |
Module.HEAPU8 | Uint8Array view of WASM memory for reading/writing pixel data |
Module.getValue(ptr, type) | Read a value at ptr ('i32', 'float', etc.) |
Module.UTF8ToString(ptr) | Convert null-terminated C string to JS string |
Complete Example
import createAMTBioFeature from './amtbiofeature.js';
const Module = await createAMTBioFeature();
// Initialize
Module._AMTBioFeature_Init();
// Configure for palm detection
Module._AMTBioFeature_SetMinSize(80, 1); // cls=1 = palm
Module._AMTBioFeature_SetMaxCount(1, 1);
Module._AMTBioFeature_SetThreshold(0.4, 0.5, 1);
// Prepare RGB888 pixel data
const dataPtr = Module._malloc(width * height * 3);
Module.HEAPU8.set(rgbPixels, dataPtr);
// Detect
const handlePtr = Module._malloc(4);
const ret = Module._AMTBioFeature_DetectPixels(
handlePtr, dataPtr, width, height, 3, 0
);
if (ret === 0) {
const handle = Module.getValue(handlePtr, 'i32');
const count = Module._AMTBioFeature_GetObjectCount(handle);
for (let i = 0; i < count; i++) {
const scorePtr = Module._malloc(4);
Module._AMTBioFeature_GetQualityColor(handle, i, scorePtr);
const quality = Module.getValue(scorePtr, 'float');
Module._AMTBioFeature_GetPalmDirection(handle, i, scorePtr);
const direction = Module.getValue(scorePtr, 'float');
const hand = direction >= 0.5 ? 'Left' : 'Right';
Module._free(scorePtr);
}
Module._AMTBioFeature_ReleaseHandle(handle);
}
Module._free(handlePtr);
Module._free(dataPtr);