Distance Calculation

52 views
Skip to first unread message

Manikandan R

unread,
Aug 23, 2023, 11:02:20 AM8/23/23
to camerax-d...@android.com

Hi,
      I am using Camerax to capture my image, I want find the distance from camera to object. 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() })




Thanks & Regards,
R. Manikandan
Reply all
Reply to author
Forward
0 new messages