How to stop tracking a image in ARcore

496 views Asked by At

I when I use the augemnted image function,the program will stuck in tracking state.

case TRACKING:
          
          fitToScanView.setVisibility(View.GONE);
          if (!augmentedImageMap.containsKey(augmentedImage)) {
            SnackbarHelper.getInstance().showMessage(this, "showing");
            node = new AugmentedImageNode(this);
            this.image = augmentedImage;


            node.setImage(this.image);
            augmentedImageMap.put(this.image, node);
            arFragment.getArSceneView().getScene().addChild(node);
          }
          break; 

I have tried to remove the node with this function,but it didn't work

public void clearDetect(View view) {
    Collection<Anchor> anchors = arFragment.getArSceneView().getSession().getAllAnchors();

    for(Anchor anchor : anchors) {
      anchor.detach();
      Log.d("leolog2",anchor.getTrackingState().toString());
    }

    fitToScanView.setVisibility(View.VISIBLE);

    Iterator<Map.Entry<AugmentedImage, AugmentedImageNode>> iter =
            augmentedImageMap.entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry<AugmentedImage, AugmentedImageNode> entry = iter.next();
      AugmentedImage face = entry.getKey();
      AugmentedImageNode faceNode = entry.getValue();
      faceNode.setParent(null);
      iter.remove();
      augmentedImageMap.remove(this.image);

    }
  }

do anybody know how to leave the tracking state and detect another image?

1

There are 1 answers

0
Yash Shah On

Please try below code it's may be helpfull

  when (augmentedImage.trackingState) {
            TrackingState.TRACKING -> {
                if (augmentedImage.trackingMethod == AugmentedImage.TrackingMethod.FULL_TRACKING) {
                   // Image tracked
                  
                            Log.d(TAG, "TEST = ${augmentedImage.name}")
                       
                   
                } else {
                   
                        //Image not tracked 
                            Log.d(TAG, "AR = ${augmentedImage.name}")
                     
                   
                }
            }
            else -> {
                Log.d(TAG, "TEST AR = ${augmentedImage.name}")
            }
        }