Image Tracker
The Image Tracker recognizes and tracks planar images. It can demonstrate not only 3D objects but also videos, even the transparent one.
Starting / Stopping the Tracker
Using the Tracking Information
Setting a Target Image
Adding / Replacing a Target Image
Changing Tracking Mode
Starting / Stopping the Tracker
To start / stop Tracker after loading the map, refer to the following code.
>ImageTrackerViewController.mm
- (void)resumeAR { ... TrackerManager::getInstance()->startTracker(TRACKER_TYPE_IMAGE); } - (void)pauseAR { TrackerManager::getInstance()->stopTracker(); ... }
Using the Tracking Information
In the folder where SDK is installed, go to ‘data > SDKSample > Original > ImageTarget' folder, and there is sample target image. Print the image.
If you use the sample code, the following content will be augmented for each image.
- Blocks.jpg: The alpha video is augmented.
- Lego.jpg: The normal video is augmented.
- Glacier.jpg: The cube with the texture is augmented.
To apply tracking results to augmented objects, refer to the following code.
>ImageTrackerViewController.mm
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { ... ITrackingResult *result = &TrackerManager::getInstance()->getTrackingResult(); int trackingCount = (int)result->getCount(); if(trackingCount > 0) { for (int i = 0; i < (int)result->getCount(); i++) { ITrackable *trackable = result->getTrackable(i); if(trackable->getName() == "Lego") { ... } else if(trackable->getName() == "Blocks") { ... } else if(trackable->getName() == "Glacier") { gl_helper::Mat4 pose = trackable->getPose(); pose = projectionMatrix * pose; texturedCube>setTransform(pose); texturedCube>setPosition(0.0f, 0.0f, -0.05f); texturedCube>setScale(0.3f, 0.3f, 0.1f); texturedCube>draw(); } ... } } ... }
Setting a Target Image
By calling addTrackerData () to register the map file and calling loadTrackerData (), the target image can be tracked. To set a target image, refer to the following code.
>ImageTrackerViewController.mm
- (void)startEngine { ... NSString *blocksTrackerMapPath = [[NSBundle mainBundle] pathForResource:@"Blocks" ofType:@"2dmap" inDirectory:@"data/SDKSample"]; NSString *glacierTrackerMapPath = [[NSBundle mainBundle] pathForResource:@"Glacier" ofType:@"2dmap" inDirectory:@"data/SDKSample"]; NSString *legoTrackerMapPath = [[NSBundle mainBundle] pathForResource:@"Lego" ofType:@"2dmap" inDirectory:@"data/SDKSample"]; TrackerManager::getInstance()->startTracker(TRACKER_TYPE_IMAGE); ... TrackerManager::getInstance()->addTrackerData(std::string([blocksTrackerMapPath UTF8String])); TrackerManager::getInstance()->addTrackerData(std::string([glacierTrackerMapPath UTF8String])); TrackerManager::getInstance()->addTrackerData(std::string([legoTrackerMapPath UTF8String])); TrackerManager::getInstance()->loadTrackerData(); }
Adding / Replacing a Target Image
Create a map file refer to Documentation > Target Manager.
Download the file you created.
Unzip the downloaded file and copy it to the desired path.
Changing Tracking Mode
Image Tracker has three Tracking modes : normal, extended, and multi.
The default setting is normal mode.
- normal mode: This is the normal image tracker.
TrackerManager::getInstance()->setTrackingOption(NORMAL_TRACKING);
- extended mode: This function is traceable even when the distance from the target image is far away.
TrackerManager::getInstance()->setTrackingOption(EXTENDED_TRACKING);
- multi mode: This function allows you to recognize and track up to three target images at the same time.
TrackerManager::getInstance()->setTrackingOption(MULTI_TRACKING);