How to switch between Face and Hand Tracking?
In this tutorial, you will learn how to switch between face tracking and hand tracking in your AR application using our Web SDK. Face tracking allows you to augment jewellery on face, while hand tracking enables you to augment jewellery on hand.
Step 1: Switch to Hand Tracking
If you are running face tracking then you can switch to hand tracking using the following code.
import { TrackingTypeEnum } from "@mirrar-sdm/ar-engine/lib/TrackingManagers/MachineLearningTrackingManager"
let handTrackingSetupStarted = false
let handTrackingSetupDone = false
function setupHandTracking(progressFunction, onComplete, video) {
if(handTrackingSetupStarted) {
console.warn("Already started the hand tracking setup. Reusing that.")
return
}
arEngine.setReferenceFrame(video)
let trackType = TrackingTypeEnum.Hand
handTrackingSetupStarted = true
arEngine.setupTracking(TrackingTypeEnum.Hand, progressFunction, (data) => {
handTrackingSetupDone = true
onComplete(data)
})
}
if(handTrackingSetupDone) {
arEngine.startTracking(TrackingTypeEnum.Hand)
} else {
setupHandTracking(progressFunction, onComplete, video)
}
Step 2: Switch to Face Tracking
If you are running hand tracking then you can switch to face tracking using the following code.
import { TrackingTypeEnum } from "@mirrar-sdm/ar-engine/lib/TrackingManagers/MachineLearningTrackingManager"
let faceTrackingSetupStarted = false
let faceTrackingSetupDone = false
function setupFaceTracking(progressFunction, onComplete) {
if(faceTrackingSetupStarted) {
console.warn("Already started the face tracking setup. Reusing that.")
return
}
faceTrackingSetupStarted = true
arEngine.setupTracking(TrackingTypeEnum.Face, progressFunction, (data) => {
faceTrackingSetupDone = true
onComplete(data)
})
}
if(faceTrackingSetupDone) {
arEngine.startTracking(TrackingTypeEnum.Face)
} else {
setupFaceTracking(progressFunction, onComplete)
}