Find distance between iOS Device Camera and user's face - ios

I am trying to find distance between iOS device's front-facing camera and user's face in the real world.
So far, I have tried ARKit/SceneKit, and using ARFaceAnchor I am able to detect user's face distance from camera; but it works only in close proximity (up to about 88 cm). My application requires face distance detection up to 200 cms.
I am assuming this could be achieved without the use of trueDepth data (which is being used in ARFaceAnchor).
Can you put me in the right direction?

In order to get the distance between the device and the user's face you should convert position of the detected user's face into camera's coordinate system. To do this, you will have to use the convertPosition method from SceneKit to switch coordinate space, from face coordinate space to camera coordinate space.
let positionInCameraSpace = theFaceNode.convertPosition(pointInFaceCoordinateSpace, to: yourARSceneView.pointOfView)
theFaceNode is the SCNNode created by ARKit representing the user's face. The pointOfView property of your ARSCNView returns the node from which the scene is viewed, basically the camera.
pointInFaceCoordinateSpace could be any vertices of the face mesh or just the position of theFaceNode (which is the origin of the face coordinate system). Here, positionInCameraSpace is a SCNVector3, representing the position of the point you gave, in camera coordinate space. Then you can get the distance between the point and the camera using the x,y and z value of this SCNVector3 (expressed in meters).
these are some links that may help you :
-Distance between face and camera using ARKit
-https://github.com/evermeer/EVFaceTracker
-https://developer.apple.com/documentation/arkit/arfacetrackingconfiguration
-How to measure device distance from face with help of ARKit in iOS?

Related

Using ArUco to synchronize pan/tilt/zoom cameras

I start with two pan/tilt/zoom cameras oriented so they can both see an ArUco marker. These cameras have been calibrated to determine the camera matrix, and the size of the marker is known. I can determine the rotation and translation vectors from the marker to each camera, and the cameras' current pan, tilt, and zoom positions are known.
If I move the marker and turn one camera to follow it, I can note the new pan/tilt/zoom position and determine the new rotation and translation vectors. Now I want to turn the second camera to face the marker. How can I determine the new pan and tilt settings required?
I think I understand how to build a combined transformation matrix from the two sets of rotation and translation vectors, but I don't know how to account for changing pan/tilt values.
I put some code in a Google Colab to better illustrate what I'm trying to do.

Real Distance of object from camera using camera matrix

How can I calculate the distance of an object of known size (e.g. aruco marker of 0.14m printed on paper) from camera. I know the camera matrix (camMatx) and my fx,fy ~= 600px assuming no distortion. From this data I am able to calculate the pose of the aruco marker and have obtained [R|t]. Now the task is to get the distance of the aruco marker from the camera. I also know the height of the camera from ground plane (15m).
How should I go about solving this problem. Any help would be appreciated. Also please note I have also seen approach of similar triangles, but that would work on knowing the distance of the object, which doesnt apply in my case as I have to calculate the distance.
N.B: I dont know the camera sensor height. But I know how high the camera is located above ground.
I know the dimensions of the area in which my object is moving (70m x 45m). In the end I would like to plot the coordinate of the moving object on a 2D map drawn to the scale.

GPS to Pixel coordinate

I want to display Radar information on the vessel identified in the Camera image.
At this point, the work is complete.
Camera Image: The ship was identified by object recognition.
Radar information: Identified the latitude, longitude, distance, and azimuth of the vessel (A, B, C).
Three sea-going vessels and a radar plot
The camera and radar are located at the same position and know the latitude, longitude, roll, and pitch values.
How can we match GPS information by converting pixel coordinates?
Same three vessels annotated with distances
You want to project the 3D coordinates to the image plane. A more detailed information about the theory behind can be found in the OpenCV documentation.
This is a brief description of how it could be done:
Compute your vessel's 3D coordinates relative to your camera position.
You need a calibrated camera. You need the interior camera parameters to compute the projection from 3D coordinates to 2D image coordinates.
Use e.g. OpenCV and projectPoints (see doc here) to compute the 2D image coordinates based on the relative 3D coordinates and your camera parameters. Because you use the relative position of the vessel you don't need the exterior orientation of your camera. So translation and rotation become zero.

Augmented Reality - Distance between marker image and Camera in ArKit?

I want to calculate the distance between any marker image saved in the iOS project which is used for detecting in Augmented Reality and your current position i.e. camera position using ARKIT ?
As Apple’s documentation and sample code note:
A detected image is reported to your app as an ARImageAnchor object.
ARImageAnchor is a subclass of ARAnchor.
ARAnchor has a transform property, which indicates its position and orientation in 3D space.
ARKit also provides you an ARCamera on every frame (or you can get it from the session’s currentFrame).
ARCamera also has a transform property, indicating the camera’s position and orientation in 3D space.
You can get the translation vector (position) from a 4x4 transform matrix by extracting the last column vector.
That should be enough for you to connect the dots...
If you're using SceneKit and have the SCNNode* that came with -(void) renderer:(id<SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forAnchor:(ARAnchor*)anchor then [node convertPosition:{0,0,0} toNode:self.sceneView.pointOfView].z is distance to camera.

How to calculate coordinates of center of image from an aerial camera whose FOV, attitude and position are given

I have a problem that involves a UAV flying with a camera mounted below it. Following information is provided:
GPS Location of the UAV in Lat/Long
GPS Height of the UAV in meters
Attitude of the UAV i.e. roll, pitch, and yaw in degrees
Field of View (FOV) of the camera in degrees
Elevation of the camera w.r.t UAV in degrees
Azimuth of camera w.r.t UAV in degrees
I have some some images taken from that camera during a flight and my task is to compute the locations (in Lat/Long) of 4 corners points and the center points of the image so that the image can be placed on the map at proper location.
I found a document while searching the internet that can be downloaded at the following link:
http://www.siaa.asn.au/get/2411853249.pdf
My maths background is very weak so I am not able to translate the document into a working solution.
Can somebody provide me a solution to my problem in the form of a simple algorithm or preferable in the form of code of some programming language?
Thanks.
As I see, it does not related to image-processing, because you need to determine coordinates of center of image (you even do not need FOV). You have to find intersection of camera principal ray and earth surface (if I've understood your task well). This is nothing more then basic matrix math.
See wiki:Transformation.

Resources