FaceLandmarksDetection icon indicating copy to clipboard operation
FaceLandmarksDetection copied to clipboard

Need to track Eye-Ball movements

Open saiios opened this issue 4 years ago • 3 comments

Hi mattlawer, I went through your code, it is good.

But I am looking for different one like, how to detect the eye ball movements tracking using swift language. I want to merge this feature for Facial recognization while login in to our app.

Could you help me to track the eye-ball movements.

Thanks In advance.

saiios avatar Aug 22 '19 10:08 saiios

Hi, you may use the leftPupil and rightPupil of the VNFaceLandmarks2D detected. But I strongly recommend using ARFaceAnchor leftEyeTransform and rightEyeTransform properties if you are using a FaceID enabled device.

mattlawer avatar Aug 22 '19 12:08 mattlawer

Here's a sample code you can use. Also you can learn more on how to use the transforms here.

import UIKit
import ARKit

class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {

    let sceneView = ARSCNView()

    override func viewDidLoad() {
        super.viewDidLoad()
        sceneView.delegate = self
        sceneView.session.delegate = self
        sceneView.frame = view.bounds
        view.addSubview(sceneView)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        guard ARFaceTrackingConfiguration.isSupported else { return }
        let configuration = ARFaceTrackingConfiguration()
        sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        sceneView.session.pause()
    }

    // MARK: - ARSCNViewDelegate
    func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard let faceAnchor = anchor as? ARFaceAnchor else { return }
        update(withFaceAnchor: faceAnchor)
    }

    func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
        guard let faceAnchor = anchor as? ARFaceAnchor else { return }
        update(withFaceAnchor: faceAnchor)
    }

    func update(withFaceAnchor anchor: ARFaceAnchor) {

        // Do something here
        /// https://developer.apple.com/documentation/arkit/arfaceanchor/2968193-righteyetransform
        print(anchor.rightEyeTransform)
        print(anchor.leftEyeTransform)
    }

}

mattlawer avatar Aug 22 '19 13:08 mattlawer

@saiios did you get any success.

kaleemasadmughal avatar Oct 10 '19 12:10 kaleemasadmughal