[Solved] How to measure user distance from wall


In the comments, you shared a link to a video: http://youtube.com/watch?v=PBpRZWmPyKo.

That app is not doing anything particularly sophisticated with the camera, but rather appears to be calculate distances using basic trigonometry, and it accomplishes this by constraining the business problem in several critical ways:

  1. First, the app requires the user to specify the height at which the phone’s camera lens is being held.

  2. Second, the user is measuring the distance to something sitting on the ground and aligning the bottom of that to some known location on the screen (meaning you have a right triangle).

Those two constraints, combined with the accelerometer and the camera’s lens focal length, would allow you to calculate the distance.

If your target cross-hair was in the center of the screen, it greatly simplifies the problem and it becomes a matter of simple trigonometry, i.e. your d = h * tan(angle).

BTW, the “angle” code in the question appears to measure the rotation about the z-axis, the clockwise/counter-clockwise rotation as the device faces you. For this problem, though, you want to measure the rotation of the device about its x-axis, the forward/backward tilt. See https://stackoverflow.com/a/16555778/1271826 for example of how to capture the device orientation in space. Also, that answer uses CoreMotion, whereas the article referenced in your question is using an API that has since been deprecated.

3

solved How to measure user distance from wall