Log in or register to post comments

Detect & track FrameMarkers & ImageTargets simultaneously

June 12, 2012 - 7:43am #1

Hi! I'm a developer using Vuforia for the first time. I'm trying to detect and track a frame marker sitting on an image target, I've nitialized both the IMAGE_TRACKER and MARKER_TRACKER in QCARutils.mm.

I'm trying to use the ImageTargets sample. I've rewritten initTracker as follows, but it only detects the image targets… Please, help!

- (int)initTracker
{
    int res = 0;  
    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
    
    QCAR::Tracker* trackerBase = trackerManager.initTracker(QCAR::Tracker::IMAGE_TRACKER);
    if (trackerBase == NULL) {
        NSLog(@"Failed to initialize ImageTracker.");
    }
    else {
        NSLog(@"Successfully initialized ImageTracker.");
        res = 1;
    }
    

    QCAR::Tracker* trackerBase2 = trackerManager.initTracker(QCAR::Tracker::MARKER_TRACKER);
    if (trackerBase2 == NULL) {
        NSLog(@"Failed to initialize MarkerTracker.");            
    }
    else {
        NSLog(@"Successfully initialized MarkerTracker.");
        
        QCAR::MarkerTracker* markerTracker = static_cast<QCAR::MarkerTracker*>(trackerBase2);
        if (markerTracker == NULL) {
            NSLog(@"Failed to get MarkerTracker.");
        }
        else {
            NSLog(@"Successfully got MarkerTracker.");
            
            if (!markerTracker->createFrameMarker(0, "MarkerQ", QCAR::Vec2F(50,50)) ||
                !markerTracker->createFrameMarker(1, "MarkerC", QCAR::Vec2F(50,50)) ||
                !markerTracker->createFrameMarker(2, "MarkerA", QCAR::Vec2F(50,50)) ||
                !markerTracker->createFrameMarker(3, "MarkerR", QCAR::Vec2F(50,50)))
            {
                NSLog(@"Failed to create frame markers.");
            }
            else {
                NSLog(@"Successfully created frame markers.");
                res = 1;
            }
        }
    }
    if (res == 0) {
        appStatus = APPSTATUS_ERROR;
        errorCode = QCAR_ERRCODE_INIT_TRACKER;
    }
    return res;
}

Detect & track FrameMarkers & ImageTargets simultaneously

October 1, 2014 - 6:26am #9

Never mind.. There's an obvious error in my code; my call to create markerTracker in doInitTrackers is using the trackerBase variable which draws from the ImageTracker type; instead I added a new line:

QCAR::Tracker* trackerBase2 = trackerManager.initTracker(QCAR::MarkerTracker::getClassType());

and replaced the line to create markerTracker with:

QCAR::MarkerTracker* markerTracker = static_cast<QCAR::MarkerTracker*>(trackerBase2);

Detect & track FrameMarkers & ImageTargets simultaneously

September 29, 2014 - 7:48am #8

Good to see this is feasible.  I've tried following your lead with the new Vuforia 3.0.5 syntax modifying the 3.0.5 samples app (CloudRecoViewController.mm).  The only way I could get the marker tracker to start() was by moving the start call into doInitTrackers; rather than in doStartTrackers as shown in the demo. 

 

<pre class="brush: cpp">

- (bool) doInitTrackers {

    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();

    QCAR::Tracker* trackerBase = trackerManager.initTracker(QCAR::ImageTracker::getClassType());

    // Set the visual search credentials:

    QCAR::TargetFinder* targetFinder = static_cast<QCAR::ImageTracker*>(trackerBase)->getTargetFinder();

    if (targetFinder == NULL)

    {

        NSLog(@"Failed to get target finder for image targets.");

        return NO;

    }

    QCAR::MarkerTracker* markerTracker = static_cast<QCAR::MarkerTracker*>(trackerBase);

    if (markerTracker == NULL)

    {

        NSLog(@"Failed to get MarkerTracker.");

        return NO;

    }

    // Create frame markers:

    if (!markerTracker->createFrameMarker(0, "MarkerQ", QCAR::Vec2F(50,50)) ||

        !markerTracker->createFrameMarker(1, "MarkerC", QCAR::Vec2F(50,50)) ||

        !markerTracker->createFrameMarker(2, "MarkerA", QCAR::Vec2F(50,50)) ||

        !markerTracker->createFrameMarker(3, "MarkerR", QCAR::Vec2F(50,50)))

    {

        NSLog(@"Failed to create frame markers.");

        return NO;

    }   

    markerTracker->start();//Is this doing anything?

    NSLog(@"Successfully initialized ImageTracker and marker tracker."); //This is printing successfully

    return YES;

}

</pre>

 

And in CloudRecoEAGLView.h:

<pre class="brush: cpp">

...

for (int i = 0; i < state.getNumTrackableResults(); ++i) {

        // Get the trackable

        const QCAR::TrackableResult* result = state.getTrackableResult(i);

        if(result->isOfType(QCAR::MarkerResult::getClassType())){

            NSLog(@"Found marker"); //this doesn't work; but my marker works in the markers demo

        }else if(result->isOfType(QCAR::ImageTargetResult::getClassType())){

            NSLog(@"Found image target");//This still works

        }

...

</pre>

 

Any advice would be greatly appreciated..  I see that the doLoadData call is being run in between init and start; however when I look at the FrameMarkers sample code, it seems there is nothing to do there.

Cheers!

Reece.

Re: Detect & track FrameMarkers & ImageTargets simultaneously

June 13, 2012 - 9:10am #7

Thanks for this

So basically you set up a tracker for each type of target rather than a combined tracker.

Cheers,

N

Re: Detect & track FrameMarkers & ImageTargets simultaneously

June 13, 2012 - 8:04am #6

In startCamera method (QCARutils.mm):

QCAR::Tracker* tracker = trackerManager.getTracker(QCAR::Tracker::MARKER_TRACKER);

            if(tracker != 0)
                tracker->start();
            
QCAR::Tracker* tracker2 = trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER);
            
            if(tracker2 != 0)
                tracker2->start();

Instead of:

QCAR::Tracker* tracker = trackerManager.getTracker(targetType == TYPE_FRAMEMARKERS ?
                                                               QCAR::Tracker::MARKER_TRACKER :
                                                               QCAR::Tracker::IMAGE_TRACKER);

Re: Detect & track FrameMarkers & ImageTargets simultaneously

June 13, 2012 - 5:34am #5

Great to hear :)

Please could you share your solution and or what the problem was?

N

Re: Detect & track FrameMarkers & ImageTargets simultaneously

June 13, 2012 - 4:26am #4

Solved!! :)

Re: Detect & track FrameMarkers & ImageTargets simultaneously

June 12, 2012 - 12:48pm #3

It seems to be ok, but when I focus the marker on the camera state.getNumActiveTrackables() gives me 0... As I said, I don't know if It's necessary some extra coding or modify the original sample.

2012-06-12 21:41:50.535 ImageTargets[433:707] APPSTATUS_INIT_TRACKER
2012-06-12 21:41:50.556 ImageTargets[433:707] Successfully initialized ImageTracker.
2012-06-12 21:41:50.560 ImageTargets[433:707] Successfully initialized MarkerTracker.
2012-06-12 21:41:50.561 ImageTargets[433:707] Successfully got MarkerTracker.
2012-06-12 21:41:50.563 ImageTargets[433:707] INFO/AR(433) 2012-06-12 21:41:50: Creating FrameID marker detector
2012-06-12 21:41:50.565 ImageTargets[433:707] Successfully created frame markers.

Re: Detect & track FrameMarkers & ImageTargets simultaneously

June 12, 2012 - 9:33am #2

Hi diegovillaran

What does the log say regarding MarkerTracker initialization?

N

Log in or register to post comments