Log in or register to post comments

How can i play a video if the image target is detected in cloudreco sample

April 17, 2013 - 1:22am #1

Dear All,

i am using cloudreco sample, now i want to play if the image target is detected, i also dont want to tap over the image, i need to start playing the video as soon as a image target is detected

How can i play a video if the image target is detected in cloudr

April 17, 2013 - 6:16am #8

hii, yes now i am able to get image name after detection.but unable  to pass name from cpp to java file.

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);

                        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.");
                }
            }
        }
    }
};

 

newTrackable->getName() here i was getting image target name, but i am unable to pass image name form cpp to java file, becuase it was not giving the current image target in render frame method.

 

How can i play a video if the image target is detected in cloudr

April 17, 2013 - 4:27am #7

Hi,

Can you try this line:

LOG("Cloud Target Name: %s", result->getTrackable().getName());

What does it logs ?

 

How can i play a video if the image target is detected in cloudr

April 17, 2013 - 4:10am #6

Hii, i tried it but not able to get image target name if i am targeting the image.

 const QCAR::TrackableResult* result = state.getTrackableResult(0);
        const QCAR::Trackable& trackable = result->getTrackable();
        js= env->NewStringUTF(trackable.getName());

 

i tried this and change the return type of renderframe method to string , but i am continuosly i am getting null name although it starts playing my default video for all images.

 

How can i play a video if the image target is detected in cloudr

April 17, 2013 - 2:12am #5

thanks for reply, once i will do i will let you know.

How can i play a video if the image target is detected in cloudr

April 17, 2013 - 2:00am #4

hi,

in order to associate different targets to different videos, you have muliple options:

  • use the target name (target.getName()): note that in this case you will need to make sure that each target has a unique name (i.e. if you gave the same name to two different targets when creating them, than this would not work)
  • use the target unique id (see line of code "result->getUniqueTargetId()" in CloudReco.cpp); this is just a string, and it is guaranteed to be universally unique (as it is automatically generated by the Cloud backend)
  • store the video URL (or filename) information in the metadata associated to each target, and read the metadata string as shown in CloudReco.cpp (see line of code with "result->getMetadata()" in CloudReco.cpp)

How can i play a video if the image target is detected in cloudr

April 17, 2013 - 1:52am #3

Hi, thanks for quick reply, yes now i am able to play video but i want to give different different action(different video ), if the different image target is detected, how can i do that, can i get the image target name in cloud reco sample.

 

How can i play a video if the image target is detected in cloudr

April 17, 2013 - 1:35am #2
Log in or register to post comments