IOS vuforia cloud and video merge tutorials


In this article, i will introduce how to integrate vuforia cloud and video both in one sample . 

Step 1 
go to vuforia website and download sample from this link 
https://developer.vuforia.com/downloads/samples 
In this sample, you can found cloud Recognition

Step 2  Download video play back sample 

Go to advance topic and download "vuforia-samples-advanced-ios-6-2-11.zip" File 
Now you have both file 

Step 3 Merge both 
Video sample add in cloud sample  like this 

Step 4 VideoPlaybackViewController File some changes 

VideoPlaybackViewController.h


VideoPlaybackViewController.mm 

Import this two file 

#import <Vuforia/ImageTarget.h> // Cloud
#import <Vuforia/TargetFinder.h> // Cloud

your cloud access key 

static const char* const kAccessKey = "722c4855b3f7e32071b32c4c742e28539487be0b";
static const char* const kSecretKey = "3078696d4aa9ab51a31789a02d75baab9d4d4f0b";


No need to change in whole file , just changes only those places which are mentioned below 

Step 5 
doLoadTrackersData function comment and add new code 

//..................  Cloud

- (bool) doLoadTrackersData {
    Vuforia::TrackerManager& trackerManager = Vuforia::TrackerManager::getInstance();
    Vuforia::ObjectTracker* objectTracker = static_cast<Vuforia::ObjectTracker*>(trackerManager.getTracker(Vuforia::ObjectTracker::getClassType()));
    if (objectTracker == NULL)
    {
        NSLog(@">doLoadTrackersData>Failed to load tracking data set because the ImageTracker has not been initialized.");
        return NO;
        
    }
    
    // Initialize visual search:
    Vuforia::TargetFinder* targetFinder = objectTracker->getTargetFinder();
    if (targetFinder == NULL)
    {
        NSLog(@">doLoadTrackersData>Failed to get target finder.");
        return NO;
    }
    
    NSDate *start = [NSDate date];
    
    // Start initialization:
    if (targetFinder->startInit(kAccessKey, kSecretKey))
    {
        targetFinder->waitUntilInitFinished();
        
        NSDate *methodFinish = [NSDate date];
        NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:start];
        
        NSLog(@"waitUntilInitFinished Execution Time: %lf", executionTime);
    }
    
    int resultCode = targetFinder->getInitState();
    if ( resultCode != Vuforia::TargetFinder::INIT_SUCCESS)
    {
        NSLog(@">doLoadTrackersData>Failed to initialize target finder.");
        if (resultCode == Vuforia::TargetFinder::INIT_ERROR_NO_NETWORK_CONNECTION) {
            NSLog(@"CloudReco error:Vuforia::TargetFinder::INIT_ERROR_NO_NETWORK_CONNECTION");
        } else if (resultCode == Vuforia::TargetFinder::INIT_ERROR_SERVICE_NOT_AVAILABLE) {
            NSLog(@"CloudReco error:Vuforia::TargetFinder::INIT_ERROR_SERVICE_NOT_AVAILABLE");
        } else {
            NSLog(@"CloudReco error:%d", resultCode);
        }
        
        int initErrorCode;
        if(resultCode == Vuforia::TargetFinder::INIT_ERROR_NO_NETWORK_CONNECTION)
        {
            initErrorCode = Vuforia::TargetFinder::UPDATE_ERROR_NO_NETWORK_CONNECTION;
        }
        else
        {
            initErrorCode = Vuforia::TargetFinder::UPDATE_ERROR_SERVICE_NOT_AVAILABLE;
        }
        [self showUIAlertFromErrorCode: initErrorCode];
        return NO;
    } else {
        NSLog(@">doLoadTrackersData>target finder initialized");
    }
    
    return YES;
}


i have add image 

Step 6  function "doStartTrackers" changes 

- (bool) doStartTrackers {
    // Set the number of simultaneous targets to two
    Vuforia::setHint(Vuforia::HINT_MAX_SIMULTANEOUS_IMAGE_TARGETS, kNumVideoTargets);
    
    Vuforia::TrackerManager& trackerManager = Vuforia::TrackerManager::getInstance();
    Vuforia::Tracker* tracker = trackerManager.getTracker(Vuforia::ObjectTracker::getClassType());
    
    Vuforia::ObjectTracker* objectTracker = static_cast<Vuforia::ObjectTracker*>(
                                                                                 trackerManager.getTracker(Vuforia::ObjectTracker::getClassType()));
    
//    if(tracker == 0) {
//        
//         NSLog(@"------ Nishant  Failed to start Object Tracker, as it is null.");
//        return false;
//    }
//    
//    
//    tracker->start();
    //......now is icloud
    
   
    
    // Start cloud based recognition if we are in scanning mode:
    if (objectTracker == 0) {
        NSLog(@"---- Nishant Failed to start Object Tracker, as it is null.");
        return NO;
    }
    objectTracker->start();
    
    // Start cloud based recognition if we are in scanning mode:
    if (scanningMode)
    {
        Vuforia::TargetFinder* targetFinder = objectTracker->getTargetFinder();
        if (targetFinder != 0) {
            isVisualSearchOn = targetFinder->startRecognition();
        }
    }

    return true;
}


STEP 7 function "onVuforiaUpdate" changes

- (void) onVuforiaUpdate: (Vuforia::State *) state
{
    // Get the tracker manager:
    Vuforia::TrackerManager& trackerManager = Vuforia::TrackerManager::getInstance();
    
    // Get the image tracker:
    Vuforia::ObjectTracker* objectTracker = static_cast<Vuforia::ObjectTracker*>(trackerManager.getTracker(Vuforia::ObjectTracker::getClassType()));
    
    // Get the target finder:
    Vuforia::TargetFinder* finder = objectTracker->getTargetFinder();
    
    // Check if there are new results available:
    const int statusCode = finder->updateSearchResults();
    if (statusCode < 0)
    {
        // Show a message if we encountered an error:
        NSLog(@"update search result failed:%d", statusCode);
        if (statusCode == Vuforia::TargetFinder::UPDATE_ERROR_NO_NETWORK_CONNECTION) {
            [self showUIAlertFromErrorCode:statusCode];
        }
    }
    else if (statusCode == Vuforia::TargetFinder::UPDATE_RESULTS_AVAILABLE)
    {
        
        // Iterate through the new results:
        for (int i = 0; i < finder->getResultCount(); ++i)
        {
            const Vuforia::TargetSearchResult* result = finder->getResult(i);
            
            // Check if this target is suitable for tracking:
            if (result->getTrackingRating() > 0)
            {
                // Create a new Trackable from the result:
                Vuforia::Trackable* newTrackable = finder->enableTracking(*result);
                if (newTrackable != 0)
                {
                    //  Avoid entering on ContentMode when a bad target is found
                    //  (Bad Targets are targets that are exists on the CloudReco database but not on our
                    //  own book database)
                    NSLog(@"Successfully created new trackable '%s' with rating '%d'.",
                          newTrackable->getName(), result->getTrackingRating());
                    NSString *video_url = [NSString stringWithFormat:@"%s",result->getMetaData()];
                    NSLog(@"%@",video_url);
                    if([video_url length]!=0)
                    {
                       [eaglView preparePlayers_st:video_url];
                    }else
                    {
                        NSLog(@"<------ Stop --->");
                        //[self doInitTrackers];
                        //[self doUnloadTrackersData];
                        [eaglView No_url_available];
                        //[self normal_alert];
                      
                        
                    }
                   
                    //NSLog(@"Nishant Checking ---> %s",result->getMetaData());
                    
                    if (extendedTrackingEnabled) {
                        newTrackable->startExtendedTracking();
                    }
                }
                else
                {
                    NSLog(@"Failed to create new trackable.");
                }
            }
        }
    }

}


STEP 8 function "doStopTrackers" changes


- (bool) doStopTrackers {

    Vuforia::TrackerManager& trackerManager = Vuforia::TrackerManager::getInstance();
    Vuforia::ObjectTracker* objectTracker = static_cast<Vuforia::ObjectTracker*>(
                                                                                 trackerManager.getTracker(Vuforia::ObjectTracker::getClassType()));
    if(objectTracker != 0) {
        objectTracker->stop();
        
        // Stop cloud based recognition:
        Vuforia::TargetFinder* targetFinder = objectTracker->getTargetFinder();
        if (targetFinder != 0) {
            isVisualSearchOn = !targetFinder->stop();
        }
    }
    return YES;
}

STEP 8 function "doUnloadTrackersData" changes


- (bool) doUnloadTrackersData {
    // Get the image tracker:
    Vuforia::TrackerManager& trackerManager = Vuforia::TrackerManager::getInstance();
    Vuforia::ObjectTracker* objectTracker = static_cast<Vuforia::ObjectTracker*>(trackerManager.getTracker(Vuforia::ObjectTracker::getClassType()));
    
    if (objectTracker == NULL)
    {
        NSLog(@"Failed to unload tracking data set because the ObjectTracker has not been initialized.");
        return NO;
    }
    
    // Deinitialize visual search:
    Vuforia::TargetFinder* finder = objectTracker->getTargetFinder();
    finder->deinit();
    return YES;

}


My Next tutorial is how to play URL Video in Vuforia Video play back sample 

Comments

  1. Its not working. i've already fetched target_id by book_sample_code. but now its playing that defaults videos.

    ReplyDelete
    Replies
    1. let me know the issue you are facing , what you want to do either play url or detection of cloud object

      Delete
  2. Hi Nishant Bhai, there is a possibility to download the entire project?

    ReplyDelete
  3. Hello Nishant,

    I have been checking your blogs about Vuforia Video Playback with Cloud Reco

    http://nishantchandwani.blogspot.com/2017/06/ios-vuforia-cloud-and-video-merge.html

    I hope your effort helps many people..but currently, It was outdated. So I am requesting you to update the blog and if possible share Github link for same. It very much appreciated.

    Thanks in Advance.

    ReplyDelete
  4. Has top vetted Vuforia developers available for hire. Find the best freelance developer for your job or project — chat with us now.

    ReplyDelete
  5. SEM is the collection of tactics and mediums marketers can use to advertise to their audience through search engines through paid ads on a cost-per-click basis. SEO services include tactics to increase “organic” traffic through back-end code optimizations, content planning and strategic keyword research/usage on your website to organically grow in rank on search results pages. Both organic and paid search marketing strategies are essential for your internet marketing strategy, and should be used in an integrated way to complement each other https://growth-loops.com .

    ReplyDelete

Post a Comment