Marker Tracker

Related documentations
Marker
Tracker Coordinate System

By recognizing and tracking the provided markers, you can augment images, 3D objects or videos especially when there are plenty of targets. 8,192 markers will be provided which were developed by MAXST itself.

Create Instants
Start / Stop Tracker
Use Tracking Information
Change Tracking Mode

Create Instants

>MarkerTrackerViewController.swift

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

Start / Stop Tracker

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

>MarkerTrackerViewController.swift

@objc func resumeAR() {
        trackingManager.start(.TRACKER_TYPE_MARKER)
        openCamera()
}

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

Use Tracking Information

You can get marker information in 'MasTrackable'. Marker Number is setted function 'getId' in 'MasTrackable'.

You must be used Convert Matrix for Metal.('metalMatrixConverter')

>MarkerTrackerViewController.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()
    
    var recogMarkerID:String = "Recognized Marker ID : "
    if trackingCount > 0 {
        for i in stride(from: 0, to: trackingCount, by: 1) {
            let trackable:MasTrackable = result.getTrackable(i)
            let poseMatrix:matrix_float4x4 = trackable.getPose() * metalMatrixConverter
            
            recogMarkerID = recogMarkerID + trackable.getId() + ", "
            textureCube!.setProjectionMatrix(projectionMatrix: projectionMatrix)
            textureCube!.setPoseMatrix(poseMatrix: poseMatrix)
            textureCube!.setTranslation(x: 0.0, y: 0.0, z: -0.05)
            textureCube!.setScale(x: 1.0, y: 1.0, z: 0.1)
            textureCube!.draw(commandEncoder: commandEncoder)
        }
    }
    ...
}

Set Target Marker

Once you enter the target marker size (m) and call the addTrackerData, you can track the marker in real scale. Refer to the following code to set a target marker.

>MarkerTrackerViewController.swift

func startEngine() {
...
        self.trackingManager.start(.TRACKER_TYPE_MARKER)
        self.trackingManager.setTrackingOption(.ENHANCED_TRACKING)
        self.trackingManager.addTrackerData("{\"marker\":\"scale\",\"all\":1.3, \"id0\" : 0.5, \"id1\" : 0.5, \"id3\" : 0.4, \"id10\" : 1.5}");
        self.trackingManager.loadTrackerData()
    }

Change Tracking Mode

4 Tracking Modes of Marker Tracker:

NORMAL_TRACKING, ENHANCED_TRACKING, JITTER_REDUCTION_ACTIVATION, JITTER_REDUCTION_DEACTIVATION

  • NORMAL_TRACKING: Default Setting. Traceable multiple target image.
trackingManager.setTrackingOption(.NORMAL_TRACKING)
  • ENHANCED_TRACKING: This feature tracks the marker intensively that recognizes the first.
trackingManager.setTrackingOption(.ENHANCED_TRACKING)
  • JITTER_REDUCTION_ACTIVATION: Jitter reduction.
trackingManager.setTrackingOption(.JITTER_REDUCTION_ACTIVATION)
  • JITTER_REDUCTION_DEACTIVATION: Disable the jitter reduction option.
trackingManager.setTrackingOption(.JITTER_REDUCTION_DEACTIVATION)