Object Tracker

Related documentations
Visual SLAM Tool
Tracker Coordinate System
Visual SLAM Learning Guide

The Object Tracker loads the map file and renders 3D object on it.

Please refer Visual SLAM Learning Guide to create a map more precisely while scanning 3D space.

Create Instants
Start / Stop Tracker
Use Tracking Information
Set Map
Add / Replace Map
Change Tracking Mode

Create Instants

>ObjectTrackerViewController.swift

var cameraDevice:MasCameraDevice = MasCameraDevice()
var sensorDevice:MasSensorDevice = MasSensorDevice()
var trackingManager:MasTrackerManager = MasTrackerManager()

Start / Stop Tracker

To start / stop Tracker after loading the map, refer to the following code.

>ObjectTrackerViewController.swift

@objc func resumeAR()
{
    ...
    trackingManager.start(.TRACKER_TYPE_OBJECT)
}

@objc func pauseAR()
{
    trackingManager.stopTracker()
    ...
}

Use Tracking Information

To use the Tracking information, refer to the following code.

You must use Convert Matrix for Metal.('metalMatrixConverter')

>ObjectTrackerViewController.swift

func draw(in view: MTKView) {
    ...
    
    let trackingState:MasTrackingState = trackingManager.updateTrackingState()
    let result:MasTrackingResult = trackingState.getTrackingResult()
    
    let backgroundImage:MasTrackedImage = trackingState.getImage()
    var backgroundProjectionMatrix:matrix_float4x4 = cameraDevice.getBackgroundPlaneProjectionMatrix()
    
    let metalMatrixConverter:matrix_float4x4 = getScaleMatrix(1.0, y: -1.0, z: 1.0)
    backgroundProjectionMatrix = backgroundProjectionMatrix * metalMatrixConverter
    
    let projectionMatrix:matrix_float4x4 = cameraDevice.getProjectionMatrix()
    
    if let cameraQuad = backgroundCameraQuad {
        cameraQuad.setProjectionMatrix(projectionMatrix: backgroundProjectionMatrix)
        cameraQuad.draw(commandEncoder: commandEncoder, image: backgroundImage)
    }
    
    let trackingCount:Int32 = result.getCount()
    
    for i in stride(from: 0, to: trackingCount, by: 1) {
        let trackable:MasTrackable = result.getTrackable(i)
        let poseMatrix:matrix_float4x4 = trackable.getPose() * metalMatrixConverter
        
        textureCube.setProjectionMatrix(projectionMatrix: projectionMatrix)
        textureCube.setPoseMatrix(poseMatrix: poseMatrix)
        textureCube.setTranslation(x: 0.0, y: 0.0, z: -0.15)
        textureCube.setScale(x: 0.3, y: 0.3, z: 0.3)
        textureCube.draw(commandEncoder: commandEncoder)
    }
    ...
}

Set Map

By calling function addTrackerData to register the map file and calling function loadTrackerData, Space can be tracked. To set a map, refer to the following code.

>ObjectTrackerViewController.swift

func startEngin()
{
    ...
    trackingManager.addTrackerData(objectTrackerMapPath)
    trackingManager.loadTrackerData()
}

Add / Replace Map

※ You can add multiple 3dmaps to recognize one of multiple objects. We recommend to add up to three maps.

  1. Create a map file refer to Visual SLAM Tool.

  2. Copy the received map file to the desired path.

  3. Set a map.

  4. If you have an existing map file, call function 'addTrackerData' and function 'loadTrackerData' after calling trackingManager.removeTrackerData()

Change Tracking Mode

2 Tracking Modes of Object Tracker:

NORMAL_TRACKING, EXTENDED_TRACKING

  • EXTENDED_TRACKING: Default Setting. Track surrounded environment beyond a trained object.
trackingManager.setTrackingOption(.EXTENDED_TRACKING)
  • NORMAL_TRACKING: Track only a trained object.
trackingManager.setTrackingOption(.NORMAL_TRACKING)