Home > Software engineering >  Internal error has occurred when executing ML Kit tasks
Internal error has occurred when executing ML Kit tasks

Time:06-19

I'm trying to integrate ARCore with ML Kit in Android Studio as suggested in ARCore documentation official. This is my JAVA code:

ObjectDetector objectDetector = createObjectDetector();
  Image cameraImage = null;
  try {
    cameraImage = frame.acquireCameraImage();
        // Process `cameraImage` using your ML inference model.
        objectDetector.process(InputImage.fromMediaImage(cameraImage, getRotationCompensation("1", this, false)))
                .addOnSuccessListener(
                        new OnSuccessListener<List<DetectedObject>>() {
                          @Override
                          public void onSuccess(List<DetectedObject> detectedObjects) {
                            // Task completed successfully
                            // The list of detected objects contains one item if multiple
                            // object detection wasn't enabled.
                            for (DetectedObject detectedObject : detectedObjects) {
                            Rect boundingBox = detectedObject.getBoundingBox();
                            Integer trackingId = detectedObject.getTrackingId();
                            for (DetectedObject.Label label : detectedObject.getLabels()) {
                              String text = label.getText();
                              if (PredefinedCategory.FOOD.equals(text)) {
                              }
                              int index = label.getIndex();
                              if (PredefinedCategory.FOOD_INDEX == index) {
                              }
                              float confidence = label.getConfidence();
                            }
                            }
                          }
                        })
                .addOnFailureListener(
                        new OnFailureListener() {
                          @Override
                          public void onFailure(@NonNull Exception e) {
                            // Task failed with an exception
                            Log.e("Failure Listener", e.getMessage());
                          }
                        });
      } catch (NotYetAvailableException e) {
        // NotYetAvailableException is an exception that can be expected when the camera is not ready
        // yet. The image may become available on a next frame.
      } catch (RuntimeException e) {
        // A different exception occurred, e.g. DeadlineExceededException, ResourceExhaustedException.
        // Handle this error appropriately.
        Log.e("Error", e.toString());
      } catch (CameraAccessException e) {
        e.printStackTrace();
      } finally {
        if (cameraImage != null) {
          cameraImage.close();
        }
      }

I'm getting the following errors:

Internal error has occurred when executing ML Kit tasks Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4faee70000000 in tid 14906 ...

The error appears because of objectDetector.process(...) but I'm not sure what I did wrong

CodePudding user response:

It worked when I commented the initial closing of the image and closed the image in the OnCompleteListener instead. This is my modified code:

ObjectDetector objectDetector = createObjectDetector();
  Image cameraImage = null;
  try {
    cameraImage = frame.acquireCameraImage();
        // Process `cameraImage` using your ML inference model.
        Image finalCameraImage = cameraImage;
        objectDetector.process(InputImage.fromMediaImage(finalCameraImage, getRotationCompensation("1", this, false)))
                .addOnSuccessListener(
                        new OnSuccessListener<List<DetectedObject>>() {
                          @Override
                          public void onSuccess(List<DetectedObject> detectedObjects) {
                            // Task completed successfully
                            // The list of detected objects contains one item if multiple
                            // object detection wasn't enabled.
                            for (DetectedObject detectedObject : detectedObjects) {
                            Rect boundingBox = detectedObject.getBoundingBox();
                            Log.d("Bounding Box", boundingBox.toString());
                            Integer trackingId = detectedObject.getTrackingId();
                            for (DetectedObject.Label label : detectedObject.getLabels()) {
                              String text = label.getText();
                              if (PredefinedCategory.FOOD.equals(text)) {
                              }
                              int index = label.getIndex();
                              if (PredefinedCategory.FOOD_INDEX == index) {
                              }
                              float confidence = label.getConfidence();
                            }
                            }
                          }
                        })
                .addOnFailureListener(
                        new OnFailureListener() {
                          @Override
                          public void onFailure(@NonNull Exception e) {
                            // Task failed with an exception
                            Log.e("Failure Listener", e.getMessage());
                          }
                        }).addOnCompleteListener(new OnCompleteListener<List<DetectedObject>>() {
      @Override
      public void onComplete(@NonNull Task<List<DetectedObject>> task) {
        finalCameraImage.close();
      }
    });
  } catch (NotYetAvailableException e) {
    // NotYetAvailableException is an exception that can be expected when the camera is not ready
    // yet. The image may become available on a next frame.
  } catch (RuntimeException e) {
    // A different exception occurred, e.g. DeadlineExceededException, ResourceExhaustedException.
    // Handle this error appropriately.
    Log.e("Error", e.toString());
  } catch (CameraAccessException e) {
    e.printStackTrace();
  } finally {
//  if (cameraImage != null) {
//          cameraImage.close();
//        }
      }
  • Related