Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make faces big by Vision and CoreGraphics

naru-jpn
March 02, 2018

Make faces big by Vision and CoreGraphics

“Can you make faces big?”

naru-jpn

March 02, 2018
Tweet

More Decks by naru-jpn

Other Decks in Technology

Transcript

  1. Make faces big
    by Vision and CoreGraphics
    VisionͱCoreGraphicsͰإΛσΧ͘͢Δ
    Naruki Chigira, Timers inc.
    @naruchigi
    Try! Swift 2018

    View full-size slide

  2. “Can you make faces big?”

    View full-size slide

  3. “In about a week.”

    View full-size slide

  4. Core Image
    want actual

    View full-size slide

  5. Core ML
    too much learning cost (also for me)

    View full-size slide

  6. Vision
    ɾFace Detection and Recognition
    ɾBarcode Detection
    ɾText Detection
    ɾHorizon Detection
    ɾObject Detection and Tracking

    View full-size slide

  7. VNFaceLandmarkRegion2D
    Class
    2D geometry information for a specific facial feature.
    VNFaceObservation
    Class
    Face or facial-feature information detected by an image
    analysis request.

    View full-size slide

  8. Face Couture
    [CGPoint]

    View full-size slide

  9. // 1. Create VNDetectFaceLandmarksRequest
    let request = VNDetectFaceLandmarksRequest() { (request, error) in
    guard let results = request.results else {
    return
    }
    let faceObservations = results.flatMap({ $0 as? VNFaceObservation })
    // 3. Handle results
    // …
    }
    // 2. Create VNImageRequestHandler and perform
    let handler = VNImageRequestHandler(cgImage: cgImage, options: [:])
    try! handler.perform([request])
    How to get VNFaceLandmarkRegion2D

    View full-size slide

  10. Face Couture

    View full-size slide

  11. Core Graphics

    View full-size slide

  12. CGPoint
    Structure
    A structure that contains a point in a two-dimensional
    coordinate system.

    View full-size slide

  13. CGAffineTransform
    Structure
    An affine transformation matrix for use in drawing 2D
    graphics.

    View full-size slide

  14. CGPoint
    Structure
    Instance Method
    func applying(_ t: CGAffineTransform) -> CGPoint

    View full-size slide

  15. O
    1. translate

    View full-size slide

  16. O
    1. translate
    2. rotate

    View full-size slide

  17. O
    1. translate
    2. rotate
    3. reverse + joint

    View full-size slide

  18. O
    1. translate
    2. rotate
    3. reverse + joint
    4. rotate-1

    View full-size slide

  19. O
    1. translate
    2. rotate
    3. reverse + joint
    4. rotate-1
    5. translate-1

    View full-size slide

  20. O
    A
    A-1
    }
    }
    1. translate
    2. rotate
    3. reverse + joint
    4. rotate-1
    5. translate-1

    View full-size slide

  21. Modify [CGPoint] in Swift
    // 1. Create CGAffineTransform A
    let A = CGAffineTransform(rotationAngle: -theta).translatedBy(x: x, y: y)
    // 2. Apply A
    let transformed = points.map { $0.applying(A) }
    // 3. Reverse & Joint
    let oval = transformed + transformed.map { CGPoint(x: -$0.x, y: -$0.y) }
    // 4. Apply A-1
    let result = oval.map { $0.applying(A.inverted()) }

    View full-size slide

  22. Summary
    Get facial features from Vision (iOS 11.0~)
    Process data using CoreGraphics (iOS 2.0~)
    +

    View full-size slide