How to Create an AR Face Project on iOS

How to Create an AR Face Project on iOS

Creating the app can use the camera to recognize your facial expression by AR

Introduction

This Tutorial is for people who already know how to develop App on Xcode but didn’t try to create an AR app. Here is the whole project on Github. The app can use the camera to recognize your facial expression by AR. 1_KUJfKKr69DG2T_6LyCyY6g.png

Create Project

The first step is to create the project. We going to choose the template of the “App”. 1_oEYVuOVHLMTEZE9dZeV2uw.png

  1. Layout 2 elements to the position you like. The picture below is my layout style. 1_I8-5R6ETB2CudiRwDOnxrw.png Set your “Info.plist” Add permission for using devices’ camera Add row “Privacy — Camera Usage Description” on “Info.plist” 1_JV4BGnDg7seXv3Id0Xexfw.png

    Set your ViewContoller

    Import 2 kits which are “SceneKit” and “ARKit” and import protocol “ARSCNViewDelegate” like the picture below. 1_VxOdvnK5gxDY-yJz-DLT1w.png et your ViewContoller
  2. Link 2 element you just created to “ViewContoller.swift”, and create a variable called “action” for sending the text to “label” 1_vl7NZ1AJqd-ST0_AGN0AEA.png
  3. Set “ViewDidLoad” Active your “sceneView” and Check your device if it supports AR Camera 1_tAskD245e5SCGiti9-jkRA.png
  4. Set “viewWillAppear” and “viewWillDisappear”. “viewWillAppear” is place to let you code something before render/refresh screen. In here, I set up the AR Face config and active the “sceneView”. In “viewWillDisappear”, it leaves a action to stop your “sceneView”. But we haven’t other screen, there is extra code for the further function. 1_Qf3hWhjZNoZ4f784erks6w.png
  5. Set “renderer” “renderer” is part of the “ARSCNViewDelegate”. Basically, “renderer” is for get the information by “ARSCNViewDelegate” like recognizing facial expressions. 1_W6vpsiaHbiP4kS_d-RLHEQ.png
  6. Set “expression” this function is for the management of what text will show on the “label”. If you want to customize your action, you could read the docs about “ARFaceAnchor” 1_5QvzyKPRDS6mgiW8w8JzIw.png Congrats!!! Try to RUN it! 🎉🎉🎉🤞🤞🤞 If you got errors, you could check my “ ViewController.swift ”. Naipie is a beginner in Swift. I hope to write down what I have learned to help me understand or help other learners. If there are mistakes and different opinions, please point them out in the comments.