Log in or register to post comments

How to get ID cloud image target?

April 22, 2013 - 1:54am #1

Hello, I need to get the ID of the target has recognized. That's when I use the recognition cloud target. I did when the target detected (cloud recognition) downloading the necessary files from the server for the scene of augmented reality, but now I need to for each target has download different files, but how to get the ID targeta I could not understand, please help me, я новичек в Vuforia SDK. Thanks in advance.

How to get ID cloud image target?

January 22, 2014 - 11:03am #9

Please see tthis code i am not able to Extract id from this.  Can u pllese just write 2 line of code . I will be thanksfull to you,,

 

class CloudReco_UpdateCallback : public QCAR::UpdateCallback
{
 
extern d;
    virtual void QCAR_onUpdate(QCAR::State& state)
    {
        // Get the tracker manager:
        QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
 
        // Get the image tracker:
        QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
                trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));
 
        // Get the target finder:
        QCAR::TargetFinder* finder = imageTracker->getTargetFinder();
 
        // Check if there are new results available:
        const int statusCode = finder->updateSearchResults();
 
        // Show a message if we encountered an error:
        if (statusCode < 0)
        {
            showErrorMessage(statusCode, state.getFrame().getTimeStamp());
        }
        else if (statusCode == QCAR::TargetFinder::UPDATE_RESULTS_AVAILABLE)
        {
            // Process new search results
            if (finder->getResultCount() > 0)
            {
                const QCAR::TargetSearchResult* result = finder->getResult(0);
 
                // Check if this target is suitable for tracking:
                if (result->getTrackingRating() > 0)
                {
                    // Create a new Trackable from the result:
                    QCAR::Trackable* newTrackable = finder->enableTracking(*result);
                    if (newTrackable != 0)
                    {
                        LOG("Successfully created new trackable '%s' with rating '%d'.",
                                newTrackable->getName(), result->getTrackingRating());
                                                
                        // Checks if the targets has changed
                        LOG( "Comparing Strings. currentTargetId: %s  lastTargetId: %s",
                                result->getUniqueTargetId(), lastTargetId);
             d=result->getUniqueTargetId();
 
                        if (strcmp(result->getUniqueTargetId(), lastTargetId) != 0)
                        {
                            // If the target has changed then regenerate the texture
                            // Cleaning this value indicates that the product Texture needs to be generated
                            // again in Java with the new Book data for the new target
                            deleteCurrentProductTexture = true;
 
                            // Starts the loading state for the product
                            renderState = RS_LOADING;
 
                            // Copies the new target Metadata
                            snprintf(targetMetadata, CONTENT_MAX, "%s", result->getMetaData());
 
                            // Calls the Java method with the current product texture
                            createProductTexture(targetMetadata);
 

How to get ID cloud image target?

January 22, 2014 - 4:50am #8

You need to use JNI to pass objects or primitive values from C++ to Java;

this is a quick introduction on JNI with Vuforia:

https://developer.vuforia.com/resources/dev-guide/java-native-interface

 

But a more comprehensive guide on JNI programming can be found here:

http://docs.oracle.com/javase/6/docs/technotes/guides/jni/

 

How to get ID cloud image target?

January 22, 2014 - 2:50am #7

But i am using vuforia 2.0.3 Sdk, So id is showing in cloudreco.cpp file but in cloudreco.java file id is not showing??  What code will i have to use to get that id in java file?? Plese proivde me solution..

Its very urgent.

Thanks in advance

 

How to get ID cloud image target?

January 11, 2014 - 12:58pm #6
I got this code in cloudreco.cpp file and in logcat Unique id is showing but How i will use this iid in cloud reco file,  I m little confused about using c++ file in Cloud reco.java file ,Please tell me the solution.
 
 
What code I will have to write in Cloud Reco file to get That unique ID.
 
 
class CloudReco_UpdateCallback : public QCAR::UpdateCallback
{
    virtual void QCAR_onUpdate(QCAR::State& state)
    {
        // Get the tracker manager:
        QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
 
        // Get the image tracker:
        QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
                trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));
 
        // Get the target finder:
        QCAR::TargetFinder* finder = imageTracker->getTargetFinder();
 
        // Check if there are new results available:
        const int statusCode = finder->updateSearchResults();
 
        // Show a message if we encountered an error:
        if (statusCode < 0)
        {
            showErrorMessage(statusCode, state.getFrame().getTimeStamp());
        }
        else if (statusCode == QCAR::TargetFinder::UPDATE_RESULTS_AVAILABLE)
        {
            // Process new search results
            if (finder->getResultCount() > 0)
            {
                const QCAR::TargetSearchResult* result = finder->getResult(0);
 
                // Check if this target is suitable for tracking:
                if (result->getTrackingRating() > 0)
                {
                    // Create a new Trackable from the result:
                    QCAR::Trackable* newTrackable = finder->enableTracking(*result);
                    if (newTrackable != 0)
                    {
                        LOG("Successfully created new trackable '%s' with rating '%d'.",
                                newTrackable->getName(), result->getTrackingRating());
                                                
                        // Checks if the targets has changed
                        LOG( "Comparing Strings. currentTargetId: %s  lastTargetId: %s",
                                result->getUniqueTargetId(), lastTargetId);
 
                       // System.out.println("valueeee"+result->getUniqueTargetId());
 
                        if (strcmp(result->getUniqueTargetId(), lastTargetId) != 0)
                        {
                            // If the target has changed then regenerate the texture
                            // Cleaning this value indicates that the product Texture needs to be generated
                            // again in Java with the new Book data for the new target
                            deleteCurrentProductTexture = true;
 
                            // Starts the loading state for the product
                            renderState = RS_LOADING;
 
                            // Copies the new target Metadata
                            snprintf(targetMetadata, CONTENT_MAX, "%s", result->getMetaData());
 
                            // Calls the Java method with the current product texture
                            createProductTexture(targetMetadata);
 
                        }
                        else
                            renderState = RS_NORMAL;
 
                        // Initialize the frames to skip variable, used for waiting
                        // a few frames for getting the chance to tracking before
                        // starting the transition to 2D when there is no target
                        pthread_mutex_lock(&framesToSkipMutex);
                        framesToSkipBeforeRenderingTransition = 10;
                        pthread_mutex_unlock(&framesToSkipMutex);
 
                        // Initialize state variables
                        showAnimation3Dto2D = true;
                        trackingStarted = false;
 
                        // Updates the value of the current Target Id with the new target found
                        pthread_mutex_lock(&lastTargetIdMutex);
                        strcpy(lastTargetId, result->getUniqueTargetId());
                        pthread_mutex_unlock(&lastTargetIdMutex);
 
                        enterContentMode();
                    }
                    else
                        LOG("Failed to create new trackable.");
                }
            }
        }
    }
};
 

How to get ID cloud image target?

January 11, 2014 - 8:10am #5

How to get ID cloud image target?

January 10, 2014 - 11:34pm #4

But how i will get Unique target Id from  Cloud Recognition App vufora Sample??  I  have serched in cloudreco.cpp file , but that is not showing any id in that.

How to get ID cloud image target?

April 22, 2013 - 5:18am #3

Hi TokiTok,

you can definitely look at the code snippet that NalinS has shared;

in addition to what NalinS has suggested, you can also query the "unique target ID" of the cloud Target (if that's what you mean by "ID");

the code to add is just:

string uniqueID = targetSearchResult.UniqueTargetId;

This will return the unique target id generated by the Cloud when you uploaded the target.

How to get ID cloud image target?

April 22, 2013 - 3:17am #2

Hi TokiTok,

I am not quite sure what you mean by ID?

The best thing to do is to study the CloudRecoEventHandler.cs and this has a callback as shown below that is called on each new search result.  Here you can check for the metadata that was uploaded for each target as a way of uniquely identifiying them.

This example is from the cloud reco sample.  Over at this thread I posted up a very simple handler which simply displays an augmentation for a CloudReco target:  https://developer.vuforia.com/forum/cloud-recognition/creating-my-books-json-ios

One other suggestion also is to read through the CloudReco forums as there is lots of information there and you can learn from the experiences of other developers.

 

HTH

N

 

 

    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)

    {

        // This code demonstrates how to reuse an ImageTargetBehaviour for new search results and modifying it according to the metadata

        // Depending on your application, it can make more sense to duplicate the ImageTargetBehaviour using Instantiate(), 

        // or to create a new ImageTargetBehaviour for each new result

 

        // Vuforia will return a new object with the right script automatically if you use

        // TargetFinder.EnableTracking(TargetSearchResult result, string gameObjectName)

        

        //Check if the metadata isn't null

        if(targetSearchResult.MetaData == null)

        {

            return;

        }

 

        // enable the new result with the same ImageTargetBehaviour:

        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate);

 

        if (imageTargetBehaviour != null)

        {

            // stop the target finder

            mCloudRecoBehaviour.CloudRecoEnabled = false;

            

            // Calls the TargetCreated Method of the SceneManager object to start loading

            // the BookData from the JSON

            mContentManager.TargetCreated(targetSearchResult.MetaData);

        }

    }

 

 

 

Log in or register to post comments