如何在Vuforia上覆盖云识别图像目标上的对象?

时间:2018-03-10 04:36:22

标签: vuforia android-augmented-reality vuforia-cloud-recognition

我几天前开始使用Vuforia库开发一个Android AR应用程序。我可以在我们提供的vuforia示例应用程序中将我的自定义图像覆盖在预定义的stone-and-chips目标上。在Cloud Reco示例中,它识别目标图像,并且我能够获取相同的元数据。我现在如何将自定义图像叠加在此识别的目标上?

在给定的用户定义目标示例中,它会在运行时创建一个图像目标,并覆盖我的图像,但我希望它仅覆盖在云识别的目标上。

  1. 所以我尝试将它集成到CloudReco.java中,这样当一个对象被云识别时,它会在运行时从中构建一个目标。

    @覆盖 public void onVuforiaUpdate(州州) {     //获取跟踪器管理器:     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();
            }
        }
    } 
    

    }

  2. 但是我收到以下错误:`

    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. 我还尝试调整UserDefinedTargets.java,以便在构建Image Target之前,TargetFinder会检查对象是否与云目标匹配。但似乎这里的相同图像不匹配。 这是经过调整的代码:
    2. 单击相机时:

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

      建立目标:

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

      异步任务:

      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: 我愿意改变实现这一结果的方法。 只需要将图像与我在Vuforia web db上的目标匹配,然后从另一台服务器获取图像以覆盖它。

0 个答案:

没有答案