google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.91k stars 1.2k forks source link

"Image has too few landmarks" and "1 buffers were freed while being dequeued error" #1624

Open wasimsafdar opened 7 months ago

wasimsafdar commented 7 months ago

I wanted to calculate the Depth in millimeters from x and y position of the camera or view. I wanted to calculate distance from all depth pixels or data of the image. Now, this is a function that is described in the documentation.

fun getMillimetersDepth(depthImage: Image, x: Int, y: Int): Int {
  // The depth image has a single plane, which stores depth for each
  // pixel as 16-bit unsigned integers.
  val plane = depthImage.planes[0]
  val byteIndex = x * plane.pixelStride + y * plane.rowStride
  val buffer = plane.buffer.order(ByteOrder.nativeOrder())
  val depthSample = buffer.getShort(byteIndex)
  return depthSample.toInt()
}

However, when I call this function here, code crashes with below mentioned errors.

if (camera.trackingState == TrackingState.TRACKING && shouldGetDepthImage) {
      try {
        val depthImage = frame.acquireDepthImage16Bits()

        //Get center x and y position of surface
        val point = render.point

       val depthValue = getMillimetersDepth(depthImage, x, y)

        backgroundRenderer.updateCameraDepthTexture(depthImage)
        depthImage.close()
      } catch (e: NotYetAvailableException) {
        // This normally means that depth data is not available yet. This is normal so we will not
        // spam the logcat with this.
      }
    }

Error 1

E/native: E0000 00:00:1699282759.499613 26986 bundle_adjustment_initializer.cc:891] SSBA does not get enough landmarks. Found 5 < 16 E0000 00:00:1699282759.499762 26986 vio_initializer.cc:849] INTERNAL: [SSBA Initialization] Failed to initialize the network.; Initializer's SSBA failed to produce a valid output. === Source Location Trace: === third_party/redwood/perception/odometry/visual_inertial_initialization/bundle_adjustment_initializer.cc:257

Error 2

Failed: Image has too few landmarks. [Required: 9, Actual: 0].; Initializer's SSBA failed to produce a valid output. === Source Location Trace: === third_party/redwood/perception/odometry/visual_inertial_initialization/bundle_adjustment_initializer.cc:330

Error 3

E/Surface: freeAllBuffers: 1 buffers were freed while being dequeued! E/AndroidRuntime: FATAL EXCEPTION: GLThread 142 Process: com.example.arcoretest, PID: 26925 java.lang.IndexOutOfBoundsException: index=366200 out of bounds (limit=28800, nb=2) at java.nio.Buffer.checkIndex(Buffer.java:717) at java.nio.DirectByteBuffer.getShort(DirectByteBuffer.java:484) at com.google.ar.core.examples.kotlin.helloar.HelloArRenderer.getMillimetersDepth(HelloArRenderer.kt:432) at com.google.ar.core.examples.kotlin.helloar.HelloArRenderer.onDrawFrame(HelloArRenderer.kt:316) at com.example.arcoretest.java.common.samplerender.SampleRender$1.onDrawFrame(SampleRender.java:72) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1573) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)

Even if there is less depth data if available, it should calculate distance from all Depth values. Is there any better way of doing this? Why I am getting those errors? Any help? Thanks