Extras
This section describes additional functions of the VIRNECT Track Framework for Android.
Get Framework Log Messages
The internal framework logs can be dumped to the console with the following command:
Track.dumpLog()
Regardless of the internal log level, the dumpLog
method will always use Android log level Info
Get Target Meta Information
Meta information about targets, like their type or physical size, can be retrieved by calling getTargetInfo
.
The method requires an array of types, TargetInformation
that is pre-initialized with the requested target names.
// Assuming targetNames is of type String[]
val targetInfos = targetNames.map{Common.TargetInformation(it)}.toTypedArray()
Track.getTargetInfo(targetInfos)
Modify Trackable Targets at Runtime
The tracking of each target can be activated or deactivated during runtime by modifying the target meta information.
To do so, set the mIgnore
property of the target information accordingly.
// Assuming targetNames is of type String[]
val targetInfos = targetNames.map{Common.TargetInformation(it)}.toTypedArray()
// Get target meta information
Track.getTargetInfo(targetInfos)
// Deactivate tracking for first target
targetInfos[0].ignore = true
// Apply target meta information
trackingFramework.setTargetInformation(targetInfos)
Changing any other property of the target meta information will not affect the framework.
Get 3D Model data
In case a CAD model is used as a target, the 3D mesh information of this model can be loaded from the framework:
// Preinitialize CAD model instance
var cadModel = Common.CADModel()
// Retrieve model information
Track.getCADModel(cadModel)
The returned CADModel
contains the vertex data and vertex IDs, which can be used for visualization of the tracked model.
Retrieve Image from Image Source
You can retrieve a shallow copy of the latest processed image as an RGBA ByteBuffer
for visualization purposes.
// Get last processed image as ByteBuffer
val RGBAImage = Track.getFrame()
Use a File Sequence as Image Source
For development and debugging purposes, the Track framework can also be used with a file sequence instead of camera input. Therefore the path to the file sequence needs to be specified before calling the initialization method.
// Set file sequence path before initializing Track framework
Track.setFileSequencePath("/sdcard/fileSequence/")
Track.initialize(context)
When the file sequence is active, the camera does not invoke the processing methods.
Since the process
or processWithCallback
method should not be called on UI/Main thread, a separate thread is needed:
Thread {
while (Track.processWithCallback()) {
SystemClock.sleep(16) // Limit to 60 FPS
}
Log.e(TAG, "File sequence finished")
}.start()
Record a file sequence
VIRNECT Track provides the functionality to record a file sequence.
The startRecording
method needs to be called when the framework is initialized and already running.
It takes the path to save the images as a first parameter and a boolean flag to choose between JPG and PGM format as a second.
fun toggleRecording(){
if(Track.isRecording())
Track.stopRecording()
else
Track.startRecording("/sdcard/recording/",false) // Record JPG images
}
Use the map recorder
To record a Map target, the map recording mode needs to be enabled before the initialization of the framework.
To initialize the recording, one image target needs to be set as well.
Once the recording is finished, the map can be saved by calling saveMapTarget
.
// Enable map recording
Track.enableMapTargetGeneration(true, "mapTargetName", targetDataPath)
// Set Image target for initialization
Track.setTargetNames(arrayOf("ImageTargetName"))
// Initialize framework
Track.initialize(context)
// Listen for user interaction to save map target
saveMapButton.setOnClickListener { Track.saveMapTarget() }
Get 3D Map points
To visualize Map targets, the tracked 3D points can be loaded from the framework. To reduce the amount of data retrieved with this command, the version of the Map should be checked beforehand. When the Map data updates internally, the version number will be increased.
// Save latest retrieved version
var lastRetrievedVersion = 0;
void renderMap(){
// Check MAP data version
val currentVersion = Track.getMapPointsVersion(targetName)
if( currentVersion > lastRetrievedVersion){
// Update version
lastRetrievedVersion = currentVersion;
// Retrieve tracked MAP points
val points:Common.Vec3[] = Track.getMapPoints(targetName)
// Visualize points
...
}
}