Skip to content

Extras

This section describes additional functions of the VIRNECT Track Framework.

Get Framework Log Messages

The Track framework provides three methods in the LOG namespace to retrieve log messages:

#import <VARAPI/TrackingFramework/Log.hpp>    

  • Latest log message
    To retrieve the latest log message as a string, simply call the following method:

    // Retrieve the latest log message
    const std::string lastLogMessage = VIRNECT::LOG::getLastLogMessage();
    
  • All log messages
    To retrieve a vector containing all log messages call:

    // Retrieve all log messages
    const std::vector<std::string> allLogMessages = VIRNECT::LOG::getAllLogMessages();
    
  • Register a callback function
    To automatically invoke a custom method on a logging event, you can register a callback function:

    // Register callback function for logging
    VIRNECT::LOG::registerLogCallbackFunction(logCallback);
    

    Example declaration for such a callback function:

    /**
    * @brief Callback function that will be invoked when Track logs a message
    * @param message Log message
    * @param level Log level
    */
    void logCallback(const std::string& message, VIRNECT::LOG::LogLevel level)
    {
        std::cout << message << std::endl;
    }
    


Get Target Meta Information

Meta information about targets, like their type or physical size, can be retrieved by calling the following method:

// Get target meta information
const std::unordered_map<std::string, VIRNECT::TargetInformation> targetInfo = self.mTrackingFramework->getTargetInformation();

Modify Trackable Targets at Runtime

By modifying the target meta information, you can activate and deactivate the tracking for each individual target during runtime. To do so, set the mIgnore property of the target information accordingly.

// Get target meta information

std::unordered_map<std::string, VIRNECT::TargetInformation> targetInfo = self.mTrackingFramework->getTargetInformation();

// Deactivate tracking for target "VARIMG_000"
targetInfo["VARIMG_000"].mIgnore = true;

// Set target meta information
self.mTrackingFramework->setTargetInformation(targetInfo);

Changing any other property of the target meta information will have no effect on the framework.


Camera Intrinsic Parameter

If your iOS device supports isCameraIntrinsicMatrixDeliverySupported, you can fetch intrinsic parameter from device.

- (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{

if ([connection isCameraIntrinsicMatrixDeliveryEnabled]) {
    NSData* intrinsics = (__bridge NSData*)CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, nil);

    matrix_float3x3* intrinsicsParameter = (matrix_float3x3 *)intrinsics.bytes;

    VIRNECT::CameraCalibration cameraCalibration;

    cameraCalibration.mResolution[0] = PROCESS_WIDTH;
    cameraCalibration.mResolution[1] = PROCESS_HEIGHT;

    cameraCalibration.mFocalLength[0] = intrinsicsParameter->columns[0][0];
    cameraCalibration.mFocalLength[1] = intrinsicsParameter->columns[1][1];
    cameraCalibration.mPrincipalPoint[0] = intrinsicsParameter->columns[2][0];
    cameraCalibration.mPrincipalPoint[1] = intrinsicsParameter->columns[2][1];
}
}

The Calibration Reader Tool enables a convenient reading of calibration data from a JSON file.

#import <VARAPI/TrackingFramework/Tools.hpp>

// Instantiate camera calibration object
VIRNECT::CameraCalibration cameraCalibration;

// Use the calibration reader tool to load camera calibration from JSON file
VIRNECT::TOOLS::readCalibrationFile(calibrationPath, cameraCalibration);

// Set camera calibration
self.mTrackingFramework->setCameraCalibration(cameraCalibration);

For more details about camera calibration and the JSON file format, please read the instructions of the Camera Calibration section.


Record Image Sequence

Track provides convenient methods to record the camera input stream as an image sequence:

#import <VARAPI/TrackingFramework/Tools.hpp>

#if TARGET_OS_IPHONE
NSString* documentPath = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject].path;
#else
NSString* documentPath = @"ROOT PATH";
#endif

// Start recording
VIRNECT::TOOLS::RECORDER::startRecording(documentPath.UTF8String);

self.mTrackingFramework->process();

// Retrieve recording state
VIRNECT::TOOLS::RECORDER::isRecording();

// Stop recording
VIRNECT::TOOLS::RECORDER::stopRecording();

To use the recording functionality the framework needs to be set up and running. Once recording is enabled via the startRecording method, each call of the process Method will record one frame.

Supported file formats are JPG & PGM.

A recorded file sequences can be used as an Image Source for the Track framework.

Back to top