All Projects → Willjay90 → Applefacedetection

Willjay90 / Applefacedetection

Face Detection with CoreML

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Applefacedetection

Facevision
iOS11 Vision framework example. Detection of face landmarks
Stars: ✭ 47 (-81.5%)
Mutual labels:  face-detection, ios11
Imagedetect
✂️ Detect and crop faces, barcodes and texts in image with iOS 11 Vision api.
Stars: ✭ 286 (+12.6%)
Mutual labels:  face-detection, ios11
Hellovision
Vision framework example for my article. https://medium.com/compileswift/swift-world-whats-new-in-ios-11-vision-456ba4156bad
Stars: ✭ 93 (-63.39%)
Mutual labels:  face-detection, ios11
Facecropper
✂️ Crop faces, inside of your image, with iOS 11 Vision api.
Stars: ✭ 479 (+88.58%)
Mutual labels:  face-detection, ios11
Facelandmarksdetection
Finds facial features such as face contour, eyes, mouth and nose in an image.
Stars: ✭ 130 (-48.82%)
Mutual labels:  face-detection, ios11
Vhlnavigation
导航栏切换之颜色过渡切换,导航栏背景图片切换,微信红包两种不同颜色切换,导航栏透明度,有无导航栏切换
Stars: ✭ 210 (-17.32%)
Mutual labels:  ios11
Tnn
TNN: developed by Tencent Youtu Lab and Guangying Lab, a uniform deep learning inference framework for mobile、desktop and server. TNN is distinguished by several outstanding features, including its cross-platform capability, high performance, model compression and code pruning. Based on ncnn and Rapidnet, TNN further strengthens the support and …
Stars: ✭ 3,257 (+1182.28%)
Mutual labels:  face-detection
Face Dataset
Face related datasets
Stars: ✭ 204 (-19.69%)
Mutual labels:  face-detection
Face toolbox keras
A collection of deep learning frameworks ported to Keras for face analysis.
Stars: ✭ 202 (-20.47%)
Mutual labels:  face-detection
Evfacetracker
Calculate the distance and angle of your device with regards to your face
Stars: ✭ 251 (-1.18%)
Mutual labels:  face-detection
Facepapercollection
A collection of face related papers
Stars: ✭ 241 (-5.12%)
Mutual labels:  face-detection
Ownphotos
Self hosted alternative to Google Photos
Stars: ✭ 2,587 (+918.5%)
Mutual labels:  face-detection
Spstorkcontroller
Now playing controller from Apple Music, Mail & Podcasts Apple's apps.
Stars: ✭ 2,494 (+881.89%)
Mutual labels:  ios11
Nike Collection
A Nike collection items style app
Stars: ✭ 228 (-10.24%)
Mutual labels:  ios11
Face.evolve.pytorch
🔥🔥High-Performance Face Recognition Library on PaddlePaddle & PyTorch🔥🔥
Stars: ✭ 2,719 (+970.47%)
Mutual labels:  face-detection
Cnn face detection
Implementation based on the paper Li et al., “A Convolutional Neural Network Cascade for Face Detection, ” 2015 CVPR
Stars: ✭ 251 (-1.18%)
Mutual labels:  face-detection
Inapppurchase
A Simple and Lightweight framework for In App Purchase
Stars: ✭ 202 (-20.47%)
Mutual labels:  ios11
Openseeface
Robust realtime face and facial landmark tracking on CPU with Unity integration
Stars: ✭ 216 (-14.96%)
Mutual labels:  face-detection
Facerecognition
Nextcloud app that implement a basic facial recognition system.
Stars: ✭ 226 (-11.02%)
Mutual labels:  face-detection
Measurearkit
An example of measuring app with ARKit in iOS 11
Stars: ✭ 220 (-13.39%)
Mutual labels:  ios11

Face Detection with Vision Framework

ios11+ swift4+

Previously, in iOS 10, to detect faces in a picture, you can use CIDetector (Apple) or Mobile Vision (Google)

In iOS11, Apple introduces CoreML. With the Vision Framework, it's much easier to detect faces in real time 😃

Try it out with real time face detection on your iPhone! 📱

You can find out the differences between CIDetector and Vison Framework down below.

Moving From Voila-Jones to Deep Learning


Details

Specify the VNRequest for face recognition, either VNDetectFaceRectanglesRequest or VNDetectFaceLandmarksRequest.

private var requests = [VNRequest]() // you can do mutiple requests at the same time

var faceDetectionRequest: VNRequest!
@IBAction func UpdateDetectionType(_ sender: UISegmentedControl) {
    // use segmentedControl to switch over VNRequest
    faceDetectionRequest = sender.selectedSegmentIndex == 0 ? VNDetectFaceRectanglesRequest(completionHandler: handleFaces) : VNDetectFaceLandmarksRequest(completionHandler: handleFaceLandmarks) 
}

Perform the requests every single frame. The image comes from camera via captureOutput(_:didOutput:from:), see AVCaptureVideoDataOutputSampleBufferDelegate

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer),
        let exifOrientation = CGImagePropertyOrientation(rawValue: exifOrientationFromDeviceOrientation()) else { return }
    var requestOptions: [VNImageOption : Any] = [:]

    if let cameraIntrinsicData = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, nil) {
      requestOptions = [.cameraIntrinsics : cameraIntrinsicData]
    }
    
    // perform image request for face recognition
    let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: exifOrientation, options: requestOptions)

    do {
      try imageRequestHandler.perform(self.requests)
    }

    catch {
      print(error)
    }

}

Handle the return of your request, VNRequestCompletionHandler.

  • handleFaces for VNDetectFaceRectanglesRequest
  • handleFaceLandmarks for VNDetectFaceLandmarksRequest

then you will get the result from the request, which are VNFaceObservations. That's all you got from the Vision API

func handleFaces(request: VNRequest, error: Error?) {
    DispatchQueue.main.async {
        //perform all the UI updates on the main queue
        guard let results = request.results as? [VNFaceObservation] else { return }
        print("face count = \(results.count) ")
        self.previewView.removeMask()

        for face in results {
            self.previewView.drawFaceboundingBox(face: face)
        }
    }
}
    
func handleFaceLandmarks(request: VNRequest, error: Error?) {
    DispatchQueue.main.async {
        //perform all the UI updates on the main queue
        guard let results = request.results as? [VNFaceObservation] else { return }
        self.previewView.removeMask()
        for face in results {
            self.previewView.drawFaceWithLandmarks(face: face)
        }
    }
}

Lastly, DRAW corresponding location on the screen! <Hint: UIBezierPath to draw line for landmarks>

func drawFaceboundingBox(face : VNFaceObservation) {
    // The coordinates are normalized to the dimensions of the processed image, with the origin at the image's lower-left corner.

    let transform = CGAffineTransform(scaleX: 1, y: -1).translatedBy(x: 0, y: -frame.height)

    let scale = CGAffineTransform.identity.scaledBy(x: frame.width, y: frame.height)

    let facebounds = face.boundingBox.applying(scale).applying(transform)

    _ = createLayer(in: facebounds)

}

// Create a new layer drawing the bounding box
private func createLayer(in rect: CGRect) -> CAShapeLayer {

    let mask = CAShapeLayer()
    mask.frame = rect
    mask.cornerRadius = 10
    mask.opacity = 0.75
    mask.borderColor = UIColor.yellow.cgColor
    mask.borderWidth = 2.0

    maskLayer.append(mask)
    layer.insertSublayer(mask, at: 1)

    return mask
}

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].