Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to track Eye-Ball movements #3

Open
saiios opened this issue Aug 22, 2019 · 3 comments
Open

Need to track Eye-Ball movements #3

saiios opened this issue Aug 22, 2019 · 3 comments

Comments

@saiios
Copy link

saiios commented Aug 22, 2019

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.

@mattlawer
Copy link
Owner

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
Copy link
Owner

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)
    }

}

@kaleemasadmughal
Copy link

@saiios did you get any success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants