

{"id":115305,"date":"2023-06-26T09:00:06","date_gmt":"2023-06-26T03:30:06","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=115305"},"modified":"2026-06-01T14:33:05","modified_gmt":"2026-06-01T09:03:05","slug":"swift-face-detection-app","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/","title":{"rendered":"Swift Face Detection App \u2013 See Beyond the Surface"},"content":{"rendered":"<p>In this project, we will learn how to create a Face Detection app using Swift in the Storyboard interface. Face Detection is a powerful technology that allows us to detect faces in real-time camera feeds and perform various tasks based on the detected faces. By the end of this project, you will have a functional Face Detection app that can detect faces and mark them with bounding boxes in real-time.<\/p>\n<h3>About Swift Face Detection App<\/h3>\n<p>The objective of this project is to create a Face Detection app that utilizes the Vision framework in Swift to detect faces in the camera feed and display bounding boxes around them.<\/p>\n<h3>Prerequisites for Face Detection App using Swift<\/h3>\n<p>To follow along with this project, you should have basic knowledge of Swift programming language and familiarity with Xcode. You will also need a Mac running macOS and Xcode installed on it.<\/p>\n<h3>Download Swift Face Detection App Project<\/h3>\n<p>Please download the source code of the Face Detection App Project from the following link: <a href=\"https:\/\/drive.google.com\/file\/d\/1gCGODSsBlzONSiTUJ3Q82h3B6px5M7r7\/view?usp=drive_link\"><strong>Swift Face Detection App <\/strong><\/a><a href=\"https:\/\/data-flair.s3.ap-south-1.amazonaws.com\/swift-projects\/face-detection.zip\"><strong>Project Code<\/strong><\/a>.<\/p>\n<h3>Steps to Create a Face Detection App Using Swift<\/h3>\n<p>Following are the steps for developing the Swift Face Detection App Project:<\/p>\n<p><strong>Step 1:<\/strong> Create a new project in Xcode.<br \/>\n<strong>Step 2:<\/strong> Setting up the User Interface<br \/>\n<strong>Step 3:<\/strong> Setting up the Camera<br \/>\n\u200b\u200b<strong>Step 4:<\/strong> Implementing Face Detection<br \/>\n<strong>Step 5:<\/strong> Starting and Stopping the Camera Session<br \/>\n<strong>Step 6:<\/strong> Running Face Detection on Sample Buffers<br \/>\n<strong>Step 7<\/strong>: Requesting Camera Permission<\/p>\n<h4>Step 1: Create a new project in Xcode.<\/h4>\n<p><strong>a.<\/strong> Open Xcode and Click on the \u201cCreate a new Xcode Project\u201d option.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-output-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115724 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-output-scaled.webp\" alt=\"face detection output\" width=\"2560\" height=\"1545\" \/><\/a><\/p>\n<p><strong>b.<\/strong> Now select the platform as \u201cmacOS\u201d and application type as \u201cApp\u201d. We are using Mac because the code is almost the same for iOS, and we require a physical device with a camera to run the app.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-face-detection-app-output-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115725 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-face-detection-app-output-scaled.webp\" alt=\"swift face detection app output\" width=\"2560\" height=\"1550\" \/><\/a><\/p>\n<p><strong>c.<\/strong> Now, Enter the name of the app and organization identifier, and select Storyboard interface for building the UI of the app. Also, select Swift as the language for creating the app.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-app-output-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115726 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-app-output-scaled.webp\" alt=\"face detection app output\" width=\"2560\" height=\"1556\" \/><\/a><\/p>\n<p><strong>d.<\/strong> Select the folder where you want to save the app and click on Create.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-project-face-detection-output-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115727 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-project-face-detection-output-scaled.webp\" alt=\"swift project face detection output\" width=\"2560\" height=\"1554\" \/><\/a><\/p>\n<p><strong>e.<\/strong> Now your project is ready for development, and you will see something like below.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-swift-output-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115728 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-swift-output-scaled.webp\" alt=\"face detection swift output\" width=\"2560\" height=\"1557\" \/><\/a><\/p>\n<h4>Step 2: Setting up the User Interface<\/h4>\n<p><strong>a.<\/strong> Open the Main.storyboard file and then open the library using the shortcut command + shift + L (\u2318+\u21e7+L). Now search NSView and drag and drop it to the <strong>Main.storyboard<\/strong> UI view as shown below.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-app-face-detection-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115729 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-app-face-detection-scaled.webp\" alt=\"swift app face detection\" width=\"2560\" height=\"1545\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-output-app-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115730 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-output-app-scaled.webp\" alt=\"face detection output app\" width=\"2560\" height=\"1550\" \/><\/a><\/p>\n<p><strong>b.<\/strong> Create an IBOutlet for the View in the View Controller by right clicking on the View and dropping it on the ViewController. Then select the connection type to IBOutlet.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-swift-app-output-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115731 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-swift-app-output-scaled.webp\" alt=\"face detection swift app output\" width=\"2560\" height=\"1550\" \/><\/a><\/p>\n<h4>Step 3: Setting up the Camera<\/h4>\n<p><strong>a.<\/strong> Import the necessary frameworks: <strong>Cocoa, Vision<\/strong>, and <strong>AVFoundation<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import Cocoa\r\nimport Vision\r\nimport AVFoundation\r\n<\/pre>\n<p><strong>b.<\/strong> Add the <strong>AVCaptureVideoDataOutputSampleBufferDelegate<\/strong> protocol to the View Controller class declaration.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class ViewController: NSViewController, AVCaptureVideoDataOutputSampleBufferDelegate {\r\n}\r\n<\/pre>\n<p><strong>c.<\/strong> Implement the required methods for the <strong>AVCaptureVideoDataOutputSampleBufferDelegate<\/strong> protocol.<br \/>\n<strong>d.<\/strong> Create a function called <strong>setupCamera()<\/strong> to configure the camera capture session, input, output, and preview layer.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">func setupCamera() {\r\n       \/\/ Create a new video session\r\n       videoSession = AVCaptureSession()\r\n       \r\n       \/\/ Set the session preset to high quality\r\n       videoSession.sessionPreset = .high\r\n       \r\n       \/\/ Enable layer-backed drawing for the video view\r\n       videoView.wantsLayer = true\r\n       \r\n       \/\/ Get the default camera for video and create an input from it\r\n       guard let camera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front),\r\n           let input = try? AVCaptureDeviceInput(device: camera) else {\r\n               print(\"Failed to access the camera.\")\r\n               return\r\n       }\r\n       \r\n       \/\/ Add the input to the session if possible\r\n       if videoSession.canAddInput(input) {\r\n           videoSession.addInput(input)\r\n       }\r\n       \r\n       \/\/ Create a new preview layer from the session and set its properties\r\n       previewLayer = AVCaptureVideoPreviewLayer(session: videoSession)\r\n       previewLayer.videoGravity = .resizeAspectFill\r\n       previewLayer.frame = videoView.bounds\r\n       \r\n       \/\/ Add the preview layer as a sublayer of the video view's layer\r\n       videoView.layer?.addSublayer(previewLayer)\r\n       \r\n       \/\/ Create a new video data output and set its sample buffer delegate and queue\r\n       let videoOutput = AVCaptureVideoDataOutput()\r\n       videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: .userInteractive))\r\n       \r\n       \/\/ Add the output to the session if possible\r\n       if videoSession.canAddOutput(videoOutput) {\r\n           videoSession.addOutput(videoOutput)\r\n       }\r\n   }\r\n<\/pre>\n<p><strong>e.<\/strong> Call the setupCamera() function in the viewDidLoad() method of the View Controller.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \r\n        \/\/ Set up the camera and face detection when the view loads\r\n        setupCamera()\r\n    }\r\n<\/pre>\n<h4>\u200b\u200bStep 4: Implementing Face Detection<\/h4>\n<p><strong>a.<\/strong> Create a function called <strong>setupFaceDetection()<\/strong> to set up the face detection request using the <strong>VNDetectFaceRectanglesRequest<\/strong> class.<br \/>\n<strong>b.<\/strong> Implement the completion handler for the face detection request to handle the detected face observations.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">func setupFaceDetection() {\r\n    \/\/ Create a new face detection request with a completion handler that handles the results\r\n    let faceDetectionRequest = VNDetectFaceRectanglesRequest { request, error in\r\n        guard let results = request.results as? [VNFaceObservation] else {\r\n            return\r\n        }\r\n        \r\n        DispatchQueue.main.async {\r\n            self.handleFaceDetectionResults(results)\r\n        }\r\n    }\r\n    \r\n    \/\/ Store the face detection request for later use\r\n    self.faceDetectionRequest = faceDetectionRequest\r\n}\r\n<\/pre>\n<p><strong>c.<\/strong> Create a function called <strong>handleFaceDetectionResults(_:)<\/strong> to process the face detection results and display bounding boxes around the detected faces.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">func handleFaceDetectionResults(_ results: [VNFaceObservation]) {\r\n       \/\/ Remove any existing face markers\r\n       videoView.subviews.forEach { $0.removeFromSuperview() }\r\n       \r\n       \/\/ Loop through the face detection results\r\n       for face in results {\r\n           \/\/ Convert the face's bounding box from normalized coordinates to view coordinates\r\n           let faceBounds = face.boundingBox\r\n           let viewBounds = previewLayer.layerRectConverted(fromMetadataOutputRect: faceBounds)\r\n           \r\n           \/\/ Create a new box to mark the face and set its properties\r\n           let faceMarker = NSBox(frame: viewBounds)\r\n           faceMarker.boxType = .custom\r\n           faceMarker.borderWidth = 2.0\r\n           faceMarker.borderColor = NSColor.green\r\n           faceMarker.cornerRadius = 5.0\r\n           \r\n           \/\/ Add the face marker as a subview of the video view\r\n           videoView.addSubview(faceMarker)\r\n       }\r\n   }\r\n<\/pre>\n<p><strong>d.<\/strong> Call the <strong>setupFaceDetection()<\/strong> function in the <strong>viewDidLoad()<\/strong> method of the View Controller.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">override func viewDidLoad() {\r\n    super.viewDidLoad()\r\n    \r\n    \/\/ Set up the camera and face detection when the view loads\r\n    setupCamera()\r\n    setupFaceDetection()\r\n}`\r\n<\/pre>\n<h4>Step 5: Starting and Stopping the Camera Session<\/h4>\n<p><strong>a.<\/strong> Create functions startSession() and stopSession() to start and stop the camera session, respectively.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">func startSession() {\r\n    \/\/ Start the video session if it's not already running\r\n    if !videoSession.isRunning {\r\n        videoSession.startRunning()\r\n    }\r\n}\r\n\r\nfunc stopSession() {\r\n    \/\/ Stop the video session if it's running\r\n    if videoSession.isRunning {\r\n        videoSession.stopRunning()\r\n    }\r\n}\r\n<\/pre>\n<p><strong>b.<\/strong> Call the <strong>startSession()<\/strong> and <strong>stopSession()<\/strong> functions in the<strong> viewDidAppear()<\/strong> and<strong> viewWillDisappear()<\/strong> methods of the View Controller, respectively.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">override func viewDidAppear() {\r\n     super.viewDidAppear()\r\n     \r\n     \/\/ Start the video session when the view appears\r\n     startSession()\r\n }\r\n \r\n override func viewWillDisappear() {\r\n     super.viewWillDisappear()\r\n     \r\n     \/\/ Stop the video session when the view disappears\r\n     stopSession()\r\n }\r\n<\/pre>\n<h4>Step 6: Running Face Detection on Sample Buffers<\/h4>\n<p><strong>a.<\/strong> Implement the <strong>captureOutput(_:didOutput:from:)<\/strong> method of the A <strong>VCaptureVideoDataOutputSampleBufferDelegate<\/strong> protocol.<br \/>\n<strong>b.<\/strong> Extract the pixel buffer from the sample buffer.<br \/>\n<strong>c.<\/strong> Create a <strong>VNImageRequestHandler<\/strong> and perform the face detection request on the pixel buffer.<br \/>\n<strong>d.<\/strong> Handle any errors that occur during the face detection process.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {\r\n        \/\/ Get the pixel buffer from the sample buffer\r\n        guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {\r\n            return\r\n        }\r\n        \r\n        \/\/ Create a new image request handler from the pixel buffer and perform the face detection request\r\n        let requestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:])\r\n        \r\n        do {\r\n            try requestHandler.perform([faceDetectionRequest])\r\n        } catch {\r\n            print(\"Face detection request failed: \\(error)\")\r\n        }\r\n    }\r\n<\/pre>\n<p><strong>Now the full code will look like this.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import Cocoa\r\nimport Vision\r\nimport AVFoundation\r\nclass ViewController: NSViewController, AVCaptureVideoDataOutputSampleBufferDelegate {\r\n    \/\/ Outlet for the view that displays the video\r\n    @IBOutlet var videoView: NSView!\r\n    \r\n    \/\/ The preview layer displays the video from the camera\r\n    var previewLayer: AVCaptureVideoPreviewLayer!\r\n    \r\n    \/\/ The video session manages the input and output of the camera\r\n    var videoSession: AVCaptureSession!\r\n    \r\n    \/\/ The face detection request detects faces in the video frames\r\n    var faceDetectionRequest: VNRequest!\r\n    \r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \r\n        \/\/ Set up the camera and face detection when the view loads\r\n        setupCamera()\r\n        setupFaceDetection()\r\n    }\r\n    \r\n    override func viewDidAppear() {\r\n        super.viewDidAppear()\r\n        \r\n        \/\/ Start the video session when the view appears\r\n        startSession()\r\n    }\r\n    \r\n    override func viewWillDisappear() {\r\n        super.viewWillDisappear()\r\n        \r\n        \/\/ Stop the video session when the view disappears\r\n        stopSession()\r\n    }\r\n    \r\n    override func viewDidLayout() {\r\n        super.viewDidLayout()\r\n        \r\n        \/\/ Update the preview layer's frame when the view's bounds change\r\n        previewLayer.frame = videoView.bounds\r\n    }\r\n    \r\n    func setupCamera() {\r\n        \/\/ Create a new video session\r\n        videoSession = AVCaptureSession()\r\n        \r\n        \/\/ Set the session preset to high quality\r\n        videoSession.sessionPreset = .high\r\n        \r\n        \/\/ Enable layer-backed drawing for the video view\r\n        videoView.wantsLayer = true\r\n        \r\n        \/\/ Get the default camera for video and create an input from it\r\n        guard let camera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front),\r\n            let input = try? AVCaptureDeviceInput(device: camera) else {\r\n                print(\"Failed to access the camera.\")\r\n                return\r\n        }\r\n        \r\n        \/\/ Add the input to the session if possible\r\n        if videoSession.canAddInput(input) {\r\n            videoSession.addInput(input)\r\n        }\r\n        \r\n        \/\/ Create a new preview layer from the session and set its properties\r\n        previewLayer = AVCaptureVideoPreviewLayer(session: videoSession)\r\n        previewLayer.videoGravity = .resizeAspectFill\r\n        previewLayer.frame = videoView.bounds\r\n        \r\n        \/\/ Add the preview layer as a sublayer of the video view's layer\r\n        videoView.layer?.addSublayer(previewLayer)\r\n        \r\n        \/\/ Create a new video data output and set its sample buffer delegate and queue\r\n        let videoOutput = AVCaptureVideoDataOutput()\r\n        videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: .userInteractive))\r\n        \r\n        \/\/ Add the output to the session if possible\r\n        if videoSession.canAddOutput(videoOutput) {\r\n            videoSession.addOutput(videoOutput)\r\n        }\r\n    }\r\n    \r\n    func setupFaceDetection() {\r\n        \/\/ Create a new face detection request with a completion handler that handles the results\r\n        let faceDetectionRequest = VNDetectFaceRectanglesRequest { request, error in\r\n            guard let results = request.results as? [VNFaceObservation] else {\r\n                return\r\n            }\r\n            \r\n            DispatchQueue.main.async {\r\n                self.handleFaceDetectionResults(results)\r\n            }\r\n        }\r\n        \r\n        \/\/ Store the face detection request for later use\r\n        self.faceDetectionRequest = faceDetectionRequest\r\n    }\r\n    \r\n    func handleFaceDetectionResults(_ results: [VNFaceObservation]) {\r\n        \/\/ Remove any existing face markers\r\n        videoView.subviews.forEach { $0.removeFromSuperview() }\r\n        \r\n        \/\/ Loop through the face detection results\r\n        for face in results {\r\n            \/\/ Convert the face's bounding box from normalized coordinates to view coordinates\r\n            let faceBounds = face.boundingBox\r\n            let viewBounds = previewLayer.layerRectConverted(fromMetadataOutputRect: faceBounds)\r\n            \r\n            \/\/ Create a new box to mark the face and set its properties\r\n            let faceMarker = NSBox(frame: viewBounds)\r\n            faceMarker.boxType = .custom\r\n            faceMarker.borderWidth = 2.0\r\n            faceMarker.borderColor = NSColor.green\r\n            faceMarker.cornerRadius = 5.0\r\n            \r\n            \/\/ Add the face marker as a subview of the video view\r\n            videoView.addSubview(faceMarker)\r\n        }\r\n    }\r\n    \r\n    func startSession() {\r\n        \/\/ Start the video session if it's not already running\r\n        if !videoSession.isRunning {\r\n            videoSession.startRunning()\r\n        }\r\n    }\r\n    \r\n    func stopSession() {\r\n        \/\/ Stop the video session if it's running\r\n        if videoSession.isRunning {\r\n            videoSession.stopRunning()\r\n        }\r\n    }\r\n    \r\n    func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {\r\n        \/\/ Get the pixel buffer from the sample buffer\r\n        guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {\r\n            return\r\n        }\r\n        \r\n        \/\/ Create a new image request handler from the pixel buffer and perform the face detection request\r\n        let requestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:])\r\n        \r\n        do {\r\n            try requestHandler.perform([faceDetectionRequest])\r\n        } catch {\r\n            print(\"Face detection request failed: \\(error)\")\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<h4>Step 7: Requesting Camera Permission<\/h4>\n<p><strong>a.<\/strong> Open the <strong>Info.plist<\/strong> file of your project.<br \/>\n<strong>b.<\/strong> Right-click on the list and select &#8220;Add Row&#8221; to add a new entry.<br \/>\n<strong>c.<\/strong> Set the Key to &#8220;Privacy &#8211; Camera Usage Description&#8221;.<br \/>\n<strong>d.<\/strong> In the Value column, add a brief description explaining why your app needs access to the camera. For example, &#8220;This app requires access to the camera to perform face detection.&#8221;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-swift-output-app-scaled.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115732 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-swift-output-app-scaled.webp\" alt=\"face detection swift output app\" width=\"2560\" height=\"1550\" \/><\/a><\/p>\n<h3>Swift Face Detection App Output:<\/h3>\n<h3><\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-app-project-output-1.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-115737 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/face-detection-app-project-output-1.gif\" alt=\"face detection app project output\" width=\"300\" height=\"374\" \/><\/a><\/p>\n<h3>Summary:<\/h3>\n<p>Congratulations! You have successfully created a Face Detection app using Swift and the Storyboard interface. In this project, you learned how to set up the camera capture session, configure face detection using the Vision framework, and display bounding boxes around the detected faces in real-time. You can now further enhance your app by adding additional features, such as face tracking or face recognition, based on your specific needs. Have fun exploring the world of computer vision and building amazing applications!<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2634,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1gCGODSsBlzONSiTUJ3Q82h3B6px5M7r7\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:210,&quot;href&quot;:&quot;https:\\\/\\\/data-flair.s3.ap-south-1.amazonaws.com\\\/swift-projects\\\/face-detection.zip&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251207142812\\\/https:\\\/\\\/data-flair.s3.ap-south-1.amazonaws.com\\\/swift-projects\\\/face-detection.zip&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 09:32:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-19 06:25:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-06 11:49:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-13 08:30:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-13 03:32:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-30 23:28:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 21:27:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-15 10:56:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-23 09:45:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-27 11:06:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-02 08:52:36&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-02 08:52:36&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project, we will learn how to create a Face Detection app using Swift in the Storyboard interface. Face Detection is a powerful technology that allows us to detect faces in real-time camera&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":115723,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27789],"tags":[27794,27795,27793,27792,27791,27790],"class_list":["post-115305","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swift-tutorials","tag-face-detection-app-project","tag-face-detection-project","tag-swift-face-detection-app-project","tag-swift-face-detection-project","tag-swift-project-ideas","tag-swift-projects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Swift Face Detection App \u2013 See Beyond the Surface - DataFlair<\/title>\n<meta name=\"description\" content=\"Discover the power of Swift face detection app: effortlessly detect and analyze faces with precision, speed, and exceptional accuracy.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift Face Detection App \u2013 See Beyond the Surface - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Discover the power of Swift face detection app: effortlessly detect and analyze faces with precision, speed, and exceptional accuracy.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-26T03:30:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T09:03:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-face-detection-app.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Swift Face Detection App \u2013 See Beyond the Surface - DataFlair","description":"Discover the power of Swift face detection app: effortlessly detect and analyze faces with precision, speed, and exceptional accuracy.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/","og_locale":"en_US","og_type":"article","og_title":"Swift Face Detection App \u2013 See Beyond the Surface - DataFlair","og_description":"Discover the power of Swift face detection app: effortlessly detect and analyze faces with precision, speed, and exceptional accuracy.","og_url":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-06-26T03:30:06+00:00","article_modified_time":"2026-06-01T09:03:05+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-face-detection-app.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Swift Face Detection App \u2013 See Beyond the Surface","datePublished":"2023-06-26T03:30:06+00:00","dateModified":"2026-06-01T09:03:05+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/"},"wordCount":821,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-face-detection-app.webp","keywords":["face detection app project","face detection project","swift face detection app project","swift face detection project","swift project ideas","swift projects"],"articleSection":["Swift Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/","url":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/","name":"Swift Face Detection App \u2013 See Beyond the Surface - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-face-detection-app.webp","datePublished":"2023-06-26T03:30:06+00:00","dateModified":"2026-06-01T09:03:05+00:00","description":"Discover the power of Swift face detection app: effortlessly detect and analyze faces with precision, speed, and exceptional accuracy.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-face-detection-app.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/06\/swift-face-detection-app.webp","width":1200,"height":628,"caption":"swift face detection app"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/swift-face-detection-app\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Swift Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/swift-tutorials\/"},{"@type":"ListItem","position":3,"name":"Swift Face Detection App \u2013 See Beyond the Surface"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/115305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=115305"}],"version-history":[{"count":10,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/115305\/revisions"}],"predecessor-version":[{"id":148726,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/115305\/revisions\/148726"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/115723"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=115305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=115305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=115305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}