The goal of this project is to create an iOS application that allows for automatic capturing of a selfie using the front-facing (selfie) camera. The app should provide a user experience as follows:
-
Face Positioning Guide:
- A rectangle is displayed on the screen within which the user is supposed to position their face along with a live preview from the selfie camera. As long as the face is positioned outside the expected area, the rectangle is red.
-
Automatic Capture:
- Once the face is correctly positioned within the bounds of the rectangle, its color changes to green, and the photo is taken automatically without any user interaction required.
-
Post-Capture Display:
- After the photo is taken, the captured image is displayed on the screen along with its color histogram.
To detect faces, the
Visionframework was used, and to draw the histogram,OpenCVwas utilized.
This project requires the opencv2.framework to function correctly. Please follow the steps below to set up the project on your local machine.
-
Download
opencv2.framework:- Obtain the framework from the specified location: https://github.com/opencv/opencv/releases/download/4.8.1/opencv-4.8.1-ios-framework.zip
-
Unpack the Framework:
- Once downloaded, unzip the framework from its archive.
-
Create Frameworks Directory:
- Navigate to the root directory of the project,
/FaceDetectionAndImageHistogram/. - Create a new folder named
Frameworks.
- Navigate to the root directory of the project,
-
Copy Framework:
- Copy the
opencv2.frameworkto the/FaceDetectionAndImageHistogram/Frameworks/directory you just created.
- Copy the
After completing these steps, the project should be ready to build and run using Xcode.
This project includes an implementation of automatic selfie capture using face detection. There are two versions available in this project:
-
Version 1: Utilizes
CVPixelBufferobtained fromcaptureOutputofAVCaptureVideoDataOutputSampleBufferDelegateto create a selfie. -
Version 2: Makes use of
AVCapturePhotoobtained fromphotoOutputofAVCapturePhotoCaptureDelegateto create a selfie.
By default, Version 1 is set up and ready to use. If you wish to test Version 2, you need to modify the AppFlowController file. Specifically, in the start method, replace displayFaceDetectionAndPixelBufferSavingScreen() with displayFaceDetectionAndCapturePhotoSavingScreen().