QR Code Tracker

Related documentations
Tracker Coordinate System

By recognizing / tracking QR Code, you can augment various contents. You can augment the information of QR Code used in real life, the URL link button using this information, the 3D model, or image. QR Code Model 2 or higher is supported.

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

Create Instants

>QRCodeTrackerViewController.swift


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

Start / Stop Tracker

To start / stop the tracker, refer to the following code.

>QRCodeTrackerViewController.swift


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

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

Use Tracking Information

The QR Code information is setted function 'getName' in 'MasTrackable'. You must be used Convert Matrix for Metal. ('metalMatrixConverter')

>QRCodeTrackerViewController.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 recogQRCode:String = "Recognized QRCode : "
        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
            
                recogQRCode = recogQRCode + trackable.getName() + ", "
                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)
            }
        }
        ...
    }

Change Tracking Mode

2 Tracking Modes of QR Code Tracker:

JITTER_REDUCTION_ACTIVATION, JITTER_REDUCTION_DEACTIVATION

  • JITTER_REDUCTION_ACTIVATION: Default Setting. Jitter reduction.
trackingManager.setTrackingOption(.JITTER_REDUCTION_ACTIVATION)
  • JITTER_REDUCTION_DEACTIVATION: Disable the jitter reduction option.
trackingManager.setTrackingOption(.JITTER_REDUCTION_DEACTIVATION)