-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cesar Vargas Casaseca
committed
Mar 28, 2020
1 parent
4e3a5c2
commit 016338e
Showing
17 changed files
with
877 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## User settings | ||
xcuserdata/ | ||
|
||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) | ||
*.xcscmblueprint | ||
*.xccheckout | ||
|
||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) | ||
build/ | ||
DerivedData/ | ||
*.moved-aside | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
|
||
## App packaging | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
# Package.resolved | ||
# *.xcodeproj | ||
# | ||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata | ||
# hence it is not needed unless you have added a package configuration file to your project | ||
# .swiftpm | ||
|
||
.build/ | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# Pods/ | ||
# | ||
# Add this line if you want to avoid checking in source code from the Xcode workspace | ||
# *.xcworkspace | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build/ | ||
|
||
# Accio dependency management | ||
Dependencies/ | ||
.accio/ | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. | ||
# Instead, use fastlane to re-generate the screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
# Code Injection | ||
# | ||
# After new code Injection tools there's a generated folder /iOSInjectionProject | ||
# https://github.com/johnno1962/injectionforxcode | ||
|
||
iOSInjectionProject/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Warhol/SampleApp/Assets.xcassets/Face.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "faceImage.jpeg", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// FaceView.swift | ||
// SampleApp | ||
// | ||
// Created by Cesar Vargas on 24.03.20. | ||
// Copyright © 2020 Cesar Vargas. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Warhol | ||
import UIKit | ||
|
||
final class FaceView: UIView, CameraFrontView { | ||
var viewModel: FaceViewModel? | ||
|
||
override func draw(_ rect: CGRect) { | ||
guard let context = UIGraphicsGetCurrentContext(), | ||
let viewModel = viewModel else { | ||
return | ||
} | ||
|
||
context.saveGState() | ||
|
||
defer { | ||
context.restoreGState() | ||
} | ||
|
||
context.addRect(viewModel.boundingBox) | ||
|
||
UIColor.red.setStroke() | ||
context.strokePath() | ||
UIColor.white.setStroke() | ||
|
||
draw(landmark: viewModel.leftEye, closePath: true, in: context) | ||
draw(landmark: viewModel.rightEye, closePath: true, in: context) | ||
|
||
draw(landmark: viewModel.leftEyebrow, closePath: false, in: context) | ||
draw(landmark: viewModel.rightEyebrow, closePath: false, in: context) | ||
|
||
draw(landmark: viewModel.nose, closePath: false, in: context) | ||
|
||
draw(landmark: viewModel.outerLips, closePath: true, in: context) | ||
draw(landmark: viewModel.innerLips, closePath: true, in: context) | ||
|
||
draw(landmark: viewModel.faceContour, closePath: false, in: context) | ||
} | ||
|
||
private func draw(landmark: FaceLandmark, closePath: Bool, in context: CGContext) { | ||
guard !landmark.isEmpty else { | ||
return | ||
} | ||
|
||
context.addLines(between: landmark) | ||
|
||
if closePath { | ||
context.closePath() | ||
} | ||
|
||
context.strokePath() | ||
} | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// ImageViewController.swift | ||
// SampleApp | ||
// | ||
// Created by Cesar Vargas on 26.03.20. | ||
// Copyright © 2020 Cesar Vargas. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import Warhol | ||
|
||
final class ImageViewController: UIViewController { | ||
@IBOutlet weak var imageView: UIImageView! | ||
@IBOutlet weak var faceView: FaceView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
imageView.image = UIImage(named: "Face") | ||
Warhol.detectLandmarks(in: imageView, completion: { (viewModel, context) in | ||
context.saveGState() | ||
|
||
defer { | ||
context.restoreGState() | ||
} | ||
|
||
context.addRect(viewModel.boundingBox) | ||
|
||
UIColor.red.setStroke() | ||
context.strokePath() | ||
UIColor.blue.setStroke() | ||
|
||
self.draw(landmark: viewModel.leftEye, closePath: true, in: context) | ||
self.draw(landmark: viewModel.rightEye, closePath: true, in: context) | ||
|
||
self.draw(landmark: viewModel.leftEyebrow, closePath: false, in: context) | ||
self.draw(landmark: viewModel.rightEyebrow, closePath: false, in: context) | ||
|
||
self.draw(landmark: viewModel.nose, closePath: false, in: context) | ||
|
||
self.draw(landmark: viewModel.outerLips, closePath: true, in: context) | ||
self.draw(landmark: viewModel.innerLips, closePath: true, in: context) | ||
|
||
self.draw(landmark: viewModel.faceContour, closePath: false, in: context) | ||
}) | ||
} | ||
|
||
private func draw(landmark: FaceLandmark, closePath: Bool, in context: CGContext) { | ||
guard !landmark.isEmpty else { | ||
return | ||
} | ||
|
||
context.addLines(between: landmark) | ||
|
||
if closePath { | ||
context.closePath() | ||
} | ||
|
||
context.strokePath() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.