InspireFaceInspireFace1.2.4.d3
Home
Get started
Get and build the SDK
Examples
  • English
  • 简体中文
GitHub
Home
Get started
Get and build the SDK
Examples
  • English
  • 简体中文
GitHub
  • Introduction
  • Get started
  • Features
  • Guides

    • Architecture and lifetime
    • Model packs
    • Image inputs and coordinates
    • Sessions and tracking
    • Face analysis
    • Recognition and FeatureHub
    • Facial landmarks
    • Liveness detection
    • Face capture
    • More API recipes
  • Language and platform

    • C API
    • C++
    • Python
    • Android
    • Apple
    • iOS
    • macOS
    • HarmonyOS
  • Get and build the SDK

    • Overview and downloads
    • Source and common options
    • Linux
    • macOS
    • Android
    • iOS
    • HarmonyOS
    • NVIDIA TensorRT
    • Rockchip NPU
    • Python packaging
  • Hardware deployment

    • ARM
    • NVIDIA TensorRT
    • Rockchip NPU
    • Python on Rockchip
  • InspireCV
  • Complete examples
  • API coverage
  • Performance
  • Image processing benchmarks
  • Troubleshooting

HarmonyOS

The ArkTS API provides sessions, image streams, detection, landmarks, embeddings, pipeline analysis and FeatureHub through a HAR module. The build and examples below use InspireFace 1.2.4.

The HarmonyOS build chapter covers toolchain setup, the native SDK, HAR staging and package checks.

Build the module

Prepare the InspireFace source dependencies, install an OpenHarmony Native SDK, and run from the repository root:

OHOS_NATIVE_HOME=/path/to/native-sdk/native \
  ./command/build_harmonyos_napi.sh

The staged HAR project is written to:

build/inspireface-harmonyos-napi-arm64-v8a/install/HarmonyOS/har

Import that directory as a module in DevEco Studio, or package it through your project's Hvigor workflow. The native library is staged at src/main/libs/arm64-v8a/libinspireface_napi.so. Its declarations are under src/main/cpp/types/libinspireface_napi.

The standard HAR build targets arm64-v8a and uses MNN CPU inference with raw-buffer image input. Build the module locally, then validate it on your target device before connecting the application workflow.

Add the module to an application

  1. Copy the staged har directory into your project as an inspireface module. Use the installed directory from the build, since it contains the compiled .so as well as the ArkTS sources.
  2. Register the module in the app project and add a local dependency from the entry module. For the layout project/entry and project/inspireface, the entry module's oh-package.json5 can include:
{
  "dependencies": {
    "@hyperinspire/inspireface": "file:../inspireface"
  }
}
  1. Sync dependencies in DevEco Studio. Package Index.ets, the native type declarations and src/main/libs/arm64-v8a/libinspireface_napi.so together.
  2. Put the model in an app-readable file location. If bundled as a raw resource, copy it to the app's files directory first, then pass that filesystem path to launch.

Verify packaging before camera integration

Use a small, known RGBA frame for the first call. Confirm width × height × 4 bytes, the model path and native-library packaging on an arm64 target, then connect the camera's actual format and stride handling.

Detect an RGBA frame

Copy the model pack into an application-accessible file and pass its path to launch. The example below receives tightly packed RGBA bytes from its caller:

import { DetectMode, Feature, ImageFormat, InspireFace, Rotation, Session }
  from '@hyperinspire/inspireface';

export function detectCount(resourcePath: string, rgba: Uint8Array,
                            width: number, height: number): number {
  InspireFace.launch(resourcePath);
  let session: Session | undefined = undefined;
  try {
    session = InspireFace.createSession({
      featureMask: Feature.NONE,
      detectMode: DetectMode.ALWAYS_DETECT,
      maxFaces: 5
    });
    const image = InspireFace.createImageStream(
      rgba, width, height, ImageFormat.RGBA, Rotation.DEGREE_0);
    try {
      const faces = session.track(image);
      try {
        return faces.detectedNum;
      } finally {
        session.releaseFaceResult(faces);
      }
    } finally {
      image.close();
    }
  } finally {
    if (session !== undefined) session.close();
    InspireFace.terminate();
  }
}

For video, move launch and session creation outside the frame loop. Use a tracking mode, feed one sequence per session and release each result after the matching pipeline or feature-extraction calls.

Ownership and workers

ObjectResponsibility
ImageStreamCopies input bytes on creation. Close it after processing.
ImageBitmapOwns bitmap storage. Call close() when finished.
Result from Session.track()Owns a detection snapshot. Release with session.releaseFaceResult(result).
SessionHolds inference and tracking state. Call close() after processing finishes.

The methods are synchronous. Run processing on a worker and keep each session and its native handles on that worker. Retain the matching frame pixels alongside a detection snapshot if you need feature extraction or pipeline analysis later.

Analysis and a gallery

Create the session with a feature mask, such as Feature.QUALITY | Feature.LIVENESS, then call session.processPipeline(image, faces) with the result from the matching frame. Check the face count before indexing output arrays.

FeatureHub uses bigint IDs for the native signed 64-bit range. Keep IDs as bigint throughout the application, for example 1001n.

Feature examples

Choose the HarmonyOS tab in these guides. The examples use the ArkTS objects exported by @hyperinspire/inspireface.

TaskArkTS entry pointsGuide
Tracking and session settingsSession.track, configure, clearTrackingTracking
Dense and five-point landmarksgetDenseLandmarks, getFiveKeyPointsLandmarks
Quality, mask, attributes and expressionSession.processPipeline, detectFaceQualityFace analysis
RGB liveness and actionsSession.processPipelineLiveness
Embeddings and a gallerySession.extractFeature, compareFeatures, FeatureHubRecognition
Capture and detection snapshotsFaceCaptureSession, Session.releaseFaceResultFace capture
Aligned images, scores and diagnosticsgetFaceAlignmentImage, similarityToPercentage, getDiagnosticInformationAPI recipes

See the ArkTS declarations for all exported types. Image inputs covers formats and rotation; session architecture explains runtime and worker lifetime.

Edit this page
Last Updated:: 9/28/26, 3:20 PM
Contributors: Jingyu
Prev
macOS