Log in or register to post comments

Changing Datasets Successfully but...

May 30, 2012 - 7:43am #1

Hello!!

Context: I'm using the Qualcomm example @ImageTargets, the example by it`s own can change the datasets with a method called in cpp that changes the value of a flag that is being constantly checked by QCAR_onUpdateCallback (Or something alike, it`s the first class in the ImageTargets.cpp)

What did i do? i commented the "if" that verifies the flag value, letting just the "if" that checks the currently active dataset and they change between them on a loop

The issue: It stopped reading the images, i have checked with log and it is changing the datasets and it`s calling the renderframe, but doesnt read the trackable images. What could be happend?

The Code:

class ImageTargets_UpdateCallback : public QCAR::UpdateCallback
{   
    virtual void QCAR_onUpdate(QCAR::State& /*state*/)
    {
        //if (switchDataSetAsap)
        //{
            //switchDataSetAsap = false;

            // Get the image tracker:
            QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
            QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
                trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));
            if (imageTracker == 0 || dataSetStonesAndChips == 0 || dataSetTarmac == 0 ||
                imageTracker->getActiveDataSet() == 0)
            {
                LOG("Failed to switch data set.");
                return;
            }
            
            if (imageTracker->getActiveDataSet() == dataSetStonesAndChips)
            {
                imageTracker->deactivateDataSet(dataSetStonesAndChips);
                imageTracker->activateDataSet(dataSetTarmac);
                LOG("Dataset change from stones->tarmac");
            }
            else
            {
                imageTracker->deactivateDataSet(dataSetTarmac);
                imageTracker->activateDataSet(dataSetStonesAndChips);
                LOG("Dataset change from tarmac->stones");
            }
        //}
    }
};

No compile errors, no runtime errors. I just know the datasets are being successfully changed, renderFrame its being executed, but it won`t recognize the trackables on them

Help please

Re: Changing Datasets Successfully but...

June 1, 2012 - 10:11pm #8
DavidBeard wrote:

Correct. But the Tracker can only analyze active DataSets, and only one DataSet can be active. The example shows how you can switch from one DataSet to the next when a Trackable is found. If you want to iterate through multiple DataSets, and to switch DataSets regardless of whether a Trackable is detected, I think that you're going to need to execute the DataSet switching based on a time interval, or perhaps frame count. That is, to allow the Tracker to analyze a DataSet for N seconds, or N frames, before activating the next DataSet. This delay interval will need to be based on the number of Trackables in each DataSet. Also device characteristics play a role, though to a lesser extent. So some testing will be required to determine an appropriate interval based on the total number of Trackables, and Trackables per DataSet, that you'll require.

Correct. I tought the same and i'm trying to formulate that reading time based on the number of... oh well, now i realize i was a little.. out of the road, but my idea is: if the dataset has... 200 trackables, multiply that value for a constant that gives it enought time to read 1 trackable, so it would be able to read all the trackables in a dataset, based in the quantity of the trackables in the dataset. But i would have a solution for a device :/ maybe

Re: Changing Datasets Successfully but...

June 1, 2012 - 8:31pm #7

Correct. But the Tracker can only analyze active DataSets, and only one DataSet can be active. The example shows how you can switch from one DataSet to the next when a Trackable is found. If you want to iterate through multiple DataSets, and to switch DataSets regardless of whether a Trackable is detected, I think that you're going to need to execute the DataSet switching based on a time interval, or perhaps frame count. That is, to allow the Tracker to analyze a DataSet for N seconds, or N frames, before activating the next DataSet. This delay interval will need to be based on the number of Trackables in each DataSet. Also device characteristics play a role, though to a lesser extent. So some testing will be required to determine an appropriate interval based on the total number of Trackables, and Trackables per DataSet, that you'll require.

Re: Changing Datasets Successfully but...

June 1, 2012 - 7:44pm #6

Hey

So i have tested this piece of code and i got another result tha expected:

for testing, i'm working with 3 datasets, so that's the reason why i found the.. unexpected result.

What is doing this code is that, when a trackable is recognized in the current dataset, it changes the active trackables to 1 and because switchdataset will be nowalong always true, is despicable.

So, when it reads a trackable, change the dataset for the next, but won't be always checking all the datasets available.

if i try to read a trackable in a dataset that is not active, it won't change.

Re: Changing Datasets Successfully but...

May 31, 2012 - 10:07pm #5

OK thank you!

I'll be testing this code :D will feedback as soon as i get it done (or not done it xD)

Re: Changing Datasets Successfully but...

May 31, 2012 - 5:03pm #4

The following may be an easier approach. By checking getNumActiveTrackables(), you can avoid the rapid switching that arises from reacting to every state update. This example will only respond to states that carry at least one active trackable instance. It's going to alternate between the two DataSets included w/ the ImageTargets sample. I've tested this, and it works as expected. The DataSets are swapped, and you're able to detect the associated Trackables for each active DataSet.

To test this, implement the following, and then press the 'menu' button on your device to present the sample UI. Then select to swap the DataSets. Once you done this the first time, the swapping will occur automatically any time a Trackable is detected.

// Object to receive update callbacks from QCAR SDK
class ImageTargets_UpdateCallback : public QCAR::UpdateCallback
{   
    virtual void QCAR_onUpdate(QCAR::State& state)
    {
        if (switchDataSetAsap && state.getNumActiveTrackables() > 0 )
        {
           // switchDataSetAsap = false;
        	LOG("Num Active Trackables = %d ", state.getNumActiveTrackables() );
            // Get the image tracker:
            QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
            QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
                trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));
            if (imageTracker == 0 || dataSetStonesAndChips == 0 || dataSetTarmac == 0 ||
                imageTracker->getActiveDataSet() == 0)
            {
                LOG("Failed to switch data set.");
                return;
            }
            
            if (imageTracker->getActiveDataSet() == dataSetStonesAndChips)
            {
            	LOG("SWITCHING TO TARMAC");
                imageTracker->deactivateDataSet(dataSetStonesAndChips);
                imageTracker->activateDataSet(dataSetTarmac);
            }
            else
            {
            	LOG("SWITCHING TO S&C");
                imageTracker->deactivateDataSet(dataSetTarmac);
                imageTracker->activateDataSet(dataSetStonesAndChips);
            }
        }
    }
};

Re: Changing Datasets Successfully but...

May 30, 2012 - 1:35pm #3
DavidBeard wrote:

So you are attempting to switch datasets on every State update?

What happens if you retain the check on the switchDataSetAsap boolean and call the switchDatasetAsap() method instead?

Exactly. I'm not so sure how wrong is that, but as i think it works, after renderFrame runs, it should run Update callback, changing the dataset and then when renderFrame runs again, checks with the new dataset. This is what i'm trying to do.

When i tried your suggestion, it happends the same thing. I think they need to be synched (updatecallback and renderframe), but i don't know how to do that. For now i'm "buying" some time so renderFrame can actually check all the trackables for the active dataset.

Re: Changing Datasets Successfully but...

May 30, 2012 - 8:57am #2

So you are attempting to switch datasets on every State update?

What happens if you retain the check on the switchDataSetAsap boolean and call the switchDatasetAsap() method instead?

Log in or register to post comments