How to overlay object on Cloud Recognized Image Target in Vuforia?

1

I started developing an android AR app using Vuforia library a few days ago. I am able to overlay my custom image over pre-defined stones-and-chips target in the vuforia sample app provided. In Cloud Reco sample, it recognizes the target image and i am able to fetch the meta data for the same. How can I now overlay my custom image over this recognized target?

In the given User Defined Target sample, it creates an Image Target at runtime, and overlays my image, but i want it overlayed only on cloud-recognized targets.

  1. So I tried integrating it in CloudReco.java, so that when an object is cloud-recognized, it builds a target out of it at runtime.

    @Override public void onVuforiaUpdate(State state) { // Get the tracker manager: TrackerManager trackerManager = TrackerManager.getInstance();

    // Get the object tracker:
    ObjectTracker objectTracker = (ObjectTracker) trackerManager
        .getTracker(ObjectTracker.getClassType());
    
    // Get the target finder:
    TargetFinder finder = objectTracker.getTargetFinder();
    
    // Check if there are new results available:
    final int statusCode = finder.updateSearchResults();
    
    // Show a message if we encountered an error:
    if (statusCode < 0)
    {
    
        boolean closeAppAfterError = (
            statusCode == UPDATE_ERROR_NO_NETWORK_CONNECTION ||
            statusCode == UPDATE_ERROR_SERVICE_NOT_AVAILABLE);
    
        showErrorMessage(statusCode, state.getFrame().getTimeStamp(), closeAppAfterError);
    
    } else if (statusCode == TargetFinder.UPDATE_RESULTS_AVAILABLE)
    {
        // Process new search results
        if (finder.getResultCount() > 0)
        {
            TargetSearchResult result = finder.getResult(0);
    
            // Check if this target is suitable for tracking:
            if (result.getTrackingRating() > 0)
            {
                Trackable trackable = finder.enableTracking(result);
    
                // Trying out the below method
                // ==================================================
    
                String targetMetaData = result.getMetaData();
                Log.d("TargetMetaData", targetMetaData);
    
                // Create the data set:
                dataSetUserDef = objectTracker.createDataSet();
    
                if (!objectTracker.activateDataSet(dataSetUserDef))
                {
                    Log.d(LOGTAG, "Failed to activate data set.");
                    return;
                }
    
                Log.d(LOGTAG, "Successfully loaded and activated data set.");
    
                // Build a target out of the selected image object
                ImageTargetBuilder targetBuilder = objectTracker
                        .getImageTargetBuilder();
    
                if (targetBuilder != null)
                {
                    if (targetBuilder.getFrameQuality() == ImageTargetBuilder.FRAME_QUALITY.FRAME_QUALITY_LOW)
                    {
                        Log.d("Cloud Reco", "Low Frame Quality");
                    }
    
                    String name;
                    if (!targetBuilder.build("randomName", 320.0f)) {
                        Log.d("CloudReco", "could not build target");
                    }
                }
    
                // ===================================================
    
                if (mExtendedTracking)
                    trackable.startExtendedTracking();
            }
        }
    } 
    

    }

However I am getting the below error :`

03-10 08:17:15.330 291-28912/? D/ae_mgr: ae_mgr [doPvAEmonitor()][getPreviewFlare] i2FlareOffset = 27 i2FlareGain = 515 
03-10 08:17:15.339 28797-28882/com.vuforia.samples.VuforiaSamples I/AR: Successfully created ImageTarget.
03-10 08:17:15.340 291-28927/? D/MtkCam/MtkCamUtils: [queryRawStride]imgFmt(269), imgWidth(1632), stride(1640)
03-10 08:17:15.341 291-28927/? I/iio/ifunc: [_config] path(2),CQ(4),en1(0x40300000),en2(0x38a00003),dma(0x00280080),fmt(0x00000106),ctl(0x00010050),tcm_en(0x98100003),isIspOn(0x1),muxS2(0xc0080308)
03-10 08:17:15.341 291-28927/? I/MdpMgr: [init] +,cqIndex(4),sceID(8)
03-10 08:17:15.341 28797-28882/com.vuforia.samples.VuforiaSamples D/TargetMetaData: {"id":1,"image_url":"\/home\/lakshay\/repos\/barium-repos\/scormREPO\/3\/1\/mobile\/5wAhJHu04Ht_DX1600_DY1600_CX800_CY480.png5wAhJHu04Ht_DX1600_DY1600_CX800_CY480.png"}
03-10 08:17:15.343 28797-28882/com.vuforia.samples.VuforiaSamples I/AR: ObjectTracker: Successfully created dataset
03-10 08:17:15.344 291-28913/? D/flash_mgr_m.cpp: flash_mgr_m.cpp isAFLampOn 0
03-10 08:17:15.345 28797-28882/com.vuforia.samples.VuforiaSamples D/CloudReco: Successfully loaded and activated data set.
03-10 08:17:15.346 28797-28882/com.vuforia.samples.VuforiaSamples E/AR: Could not initiate UserDef Target build process
03-10 08:17:15.346 28797-28882/com.vuforia.samples.VuforiaSamples E/AR: Not in scanning state or invalid frame quality reading of -1. Call build() again in scanning mode with valid frame quality values.
03-10 08:17:15.346 28797-28882/com.vuforia.samples.VuforiaSamples D/CloudReco: could not build target
03-10 08:17:15.355 28797-28810/com.vuforia.samples.VuforiaSamples I/BufferQueueProducer: [SurfaceTexture--1-28797-1](this:0x8731e000,id:1,api:4,p:291,c:28797) queueBuffer: slot 1 is dropped, handle=0x854ba300
  1. I also tried tweaking the UserDefinedTargets.java so that before building the Image Target, the TargetFinder checks if it the object matches the cloud targets. But seems like the same image here is not matching. Here is the tweaked code :

when camera is clicked :

// Button Camera clicked
public void onCameraClick(View v)
{
    if (isUserDefinedTargetsRunning())
    {
        // Shows the loading dialog
        loadingDialogHandler
            .sendEmptyMessage(LoadingDialogHandler.SHOW_LOADING_DIALOG);

        // Builds the new target
        //startBuild();

        //// Calling startBuild as an async task instead
        // since it involves network calls
        SyncIncoData syncIncoData = new SyncIncoData();
        syncIncoData.execute(new String[] { null });
    }
}

building targets :

void startBuild()
{
    TrackerManager trackerManager = TrackerManager.getInstance();
    ObjectTracker objectTracker = (ObjectTracker) trackerManager
        .getTracker(ObjectTracker.getClassType());

    if (objectTracker != null)
    {
        ImageTargetBuilder targetBuilder = objectTracker
            .getImageTargetBuilder();
        if (targetBuilder != null)
        {
            if (targetBuilder.getFrameQuality() == ImageTargetBuilder.FRAME_QUALITY.FRAME_QUALITY_LOW)
            {
                 showErrorDialogInUIThread();
            }

            // Tried below code for cloud-reco on this object
            // ======================================================

            // Initialize target finder:
            TargetFinder targetFinder = objectTracker.getTargetFinder();

            // Start initialization:
            if (targetFinder.startInit(kAccessKey, kSecretKey))
            {
                Log.d("TargetFind", "init");
                targetFinder.waitUntilInitFinished();
            }

            Log.d("TargetFind", "init over");

            int resultCode = targetFinder.getInitState();
            if (resultCode != TargetFinder.INIT_SUCCESS)
            {
                if(resultCode == TargetFinder.INIT_ERROR_NO_NETWORK_CONNECTION)
                {
                    Log.d("TargetFinder", "no net");
                }
                else
                {
                    Log.d("TargetFinder", "no service");
                }

                Log.e(LOGTAG, "Failed to initialize target finder.");
                return;
            }

            Log.d("TargetFinder", "validated");

            // Get the target finder:
            TargetFinder finder = objectTracker.getTargetFinder();

            Log.d("TargetFinder", "found");
            // Check if there are new results available:
            final int statusCode = finder.updateSearchResults();

            Log.d("Status Code", String.valueOf(statusCode));
            //// status is coming 1 => TargetFinder.UPDATE_NO_REQUEST ////

            // Show a message if we encountered an error:
            if (statusCode < 0)
            {
                Log.d("CloudFind", "not found");
                return;
            }
            else if (statusCode == TargetFinder.UPDATE_RESULTS_AVAILABLE) {

                //// Not coming here ////

                Log.d("CloudFind", "found");
                // Process new search results
                if (finder.getResultCount() > 0) {
                    TargetSearchResult result = finder.getResult(0);
                    String targetMetaData = result.getMetaData();
                    Log.d("TargetMetaData", targetMetaData);

                    // Check if this target is suitable for tracking:
                    // Only if the target is matched and suitable for tracking
                    // then the Image target should be built
                    if (result.getTrackingRating() > 0) {
                        String name;
                        do
                        {
                            name = "UserTarget-" + targetBuilderCounter;
                            Log.d(LOGTAG, "TRYING " + name);
                            targetBuilderCounter++;
                        } while (!targetBuilder.build(name, 320.0f));

                        refFreeFrame.setCreating();
                    }
                }
            }


        }
    }
}

async task :

private class SyncIncoData extends AsyncTask<String, String, String> {


    @Override
    protected String doInBackground(String... ot) {

        startBuild();

        return null;
    }

    @Override
    protected void onPreExecute() {

        super.onPreExecute();

    }

    @Override
    protected void onPostExecute(String result) {


    }

    @Override
    protected void onProgressUpdate(String... values) {
        super.onProgressUpdate(values);
    }
}

PS : I am open to change the approach to achieve this result. Just need to match the image against a target, which i have on Vuforia web db, and fetch an image from another server to overlay on it.

vuforia
android-augmented-reality
vuforia-cloud-recognition
asked on Stack Overflow Mar 10, 2018 by Aashish Tyagi • edited Mar 10, 2018 by Aashish Tyagi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0