Distance calculation.

271 views
Skip to first unread message
Assigned to xi...@google.com by wuj...@google.com

manika...@ivymobility.com

unread,
Aug 25, 2023, 1:19:37 AM8/25/23
to Android CameraX Discussion Group
Hi,
      I am using Camerax to capture my image, I want find the distance from camera to object it's either inbuild camerax or ARCore or MLKit. Trying to use ARFragment surface and arcore but couldn't find the distance. If implement ar core lib camera zoom and capture not working.

Code Snippet:
implementation "com.google.ar.sceneform.ux:sceneform-ux:1.15.0"
implementation 'com.google.ar:core:1.39.0'

arFragment = supportFragmentManager.findFragmentById(R.id.ar_fragment) as ArFragment
val imageAnalysis = ImageAnalysis.Builder()
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.build()
imageAnalysis.setAnalyzer(cameraExecutor, ImageAnalysis.Analyzer { image -> if (arFragment.arSceneView.session != null && arFragment.arSceneView.arFrame?.camera?.trackingState == TrackingState.TRACKING ) { // Perform hit test using ARFrame and image coordinates val hitResultList = arFragment.arSceneView.arFrame!!.hitTest( image.width / 2f, image.height / 2f ) if (hitResultList.isNotEmpty()) { val hitResult = hitResultList[0] val distance = hitResult.distance // Estimated distance in meters Log.d("Distance", "Estimated distance: $distance meters") } } image.close() })

Xi Zhang

unread,
Aug 29, 2023, 1:15:36 PM8/29/23
to Android CameraX Discussion Group, manika...@ivymobility.com
Unfortunately, there is no support for ARCore + CameraX.  I think your best chance is using ARCore with camera2

As for detecting distance without ARCore, I don't think MLKit supports it. 

Manikandan R

unread,
Aug 30, 2023, 12:50:40 AM8/30/23
to Xi Zhang, Android CameraX Discussion Group
Hi,
      Thanks for the reply.
Is there any other way to find distance using Camerax if available please share the sample.

Is it possible to use DepthAPI to find?.

We try to find distance using sensors but not deduct correctly.

Please suggest any default method or any other ways.



Thanks & Regards,
R. Manikandan

Xi Zhang (张熹)

unread,
Aug 30, 2023, 11:43:20 AM8/30/23
to Manikandan R, Android CameraX Discussion Group
I am not aware of a simple way to get depth with CameraX. camera2 does support a depth API but it requires 1) the device supports it and 2) the app uses camera2 API.

I think your best chance is using ARCore + camera2 like this tutorial.

Manikandan R

unread,
Sep 4, 2023, 12:45:17 AM9/4/23
to Xi Zhang (张熹), Android CameraX Discussion Group
Ok, thanks for the reply. 





Thanks & Regards,
R. Manikandan

Reply all
Reply to author
Forward
0 new messages