Hey @zqj2000 I'm getting hung up on this problem as well. Most likely in the rectification of the depth data so I can use 2 points in space to calculate the distance. Same as the OP.
My depth image coords (640,360), video image (1280,720) and intrinsicReference (4032,2268). If the depth is .389 (which is in meters) and my 2 points are (421.62951779, 475.694515546) and (428.601582527, 921.03613217) then I expect a length around 0.1651 meters. But I'm around .33 meters using the following code:
let xrwPoint1 = depthValue1 * (Float(convertedCGScreenPoint1.x) - adjustedCx) / adjustedFx
let yrwPoint1 = depthValue1 * (Float(convertedCGScreenPoint2.y) - adjustedCy) / adjustedFy
let xrwPoint2 = depthValue2 * (Float(convertedCGScreenPoint2.x) - adjustedCx) / adjustedFx
let yrwPoint2 = depthValue2 * (Float(convertedCGScreenPoint2.y) - adjustedCy) / adjustedFy
let point1In3D = simd_float3(xrwPoint1, yrwPoint1, distanceValue1)
let point2In3D = simd_float3(xrwPoint2, yrwPoint2, distanceValue2)
let dist = simd_precise_distance(point1In3D, point2In3D)
I should note that I do NOT get the same values on an iPhone 12 and iPad Pro. So the math must be inaccurate somewhere. If I was getting the same value but it was off, that would be encouraging.
There has to be more rectifying of the depth data, correct? Thank you for any advice!
Post
Replies
Boosts
Views
Activity
I should have added the code sample to my original post. The code is working on the Rear Camera but does not return results on the Front Camera. I'm wondering if it is because of the direction of the ray. For the Front Camera, if rayCast is supported, maybe it requires the ray to be cast in the negative z direction? Thanks again for any assistance!
let raycastQuery: ARRaycastQuery? = sceneView.raycastQuery(
from: sceneView.center,
allowing: .estimatedPlane,
alignment: .any)
let rayresults: [ARRaycastResult] = sceneView.session.raycast(raycastQuery!)
print(rayresults)