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

Make faces big by Vision and CoreGraphics

2bfb16e53b154afc9f141f831b4aaaf2?s=47 naru-jpn
March 02, 2018

Make faces big by Vision and CoreGraphics

“Can you make faces big?”

2bfb16e53b154afc9f141f831b4aaaf2?s=128

naru-jpn

March 02, 2018
Tweet

Transcript

  1. Make faces big by Vision and CoreGraphics VisionͱCoreGraphicsͰإΛσΧ͘͢Δ Naruki Chigira,

    Timers inc. @naruchigi Try! Swift 2018
  2. “Can you make faces big?”

  3. “In about a week.”

  4. None
  5. Core Image want actual

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

  7. Vision

  8. Vision ɾFace Detection and Recognition ɾBarcode Detection ɾText Detection ɾHorizon

    Detection ɾObject Detection and Tracking
  9. VNFaceLandmarkRegion2D Class 2D geometry information for a specific facial feature.

    VNFaceObservation Class Face or facial-feature information detected by an image analysis request.
  10. Face Couture [CGPoint]

  11. // 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
  12. Face Couture

  13. None
  14. None
  15. None
  16. None
  17. None
  18. Core Graphics

  19. CGPoint Structure A structure that contains a point in a

    two-dimensional coordinate system.
  20. CGAffineTransform Structure An affine transformation matrix for use in drawing

    2D graphics.
  21. CGPoint Structure Instance Method func applying(_ t: CGAffineTransform) -> CGPoint

  22. O

  23. O 1. translate

  24. O 1. translate 2. rotate

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

  26. O 1. translate 2. rotate 3. reverse + joint 4.

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

    rotate-1 5. translate-1
  28. O A A-1 } } 1. translate 2. rotate 3.

    reverse + joint 4. rotate-1 5. translate-1
  29. 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()) }
  30. Result

  31. None
  32. None
  33. Summary Get facial features from Vision (iOS 11.0~) Process data

    using CoreGraphics (iOS 2.0~) +
  34. Thank you!