Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Vargas Casaseca committed Mar 28, 2020
1 parent 4e3a5c2 commit 016338e
Show file tree
Hide file tree
Showing 17 changed files with 877 additions and 194 deletions.
90 changes: 90 additions & 0 deletions .gitignore
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/
21 changes: 2 additions & 19 deletions Warhol/SampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,19 @@
// AppDelegate.swift
// SampleApp
//
// Created by Cesar Vargas on 22.03.20.
// Created by Cesar Vargas on 23.03.20.
// Copyright © 2020 Cesar Vargas. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {


var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

21 changes: 21 additions & 0 deletions Warhol/SampleApp/Assets.xcassets/Face.imageset/Contents.json
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.
63 changes: 63 additions & 0 deletions Warhol/SampleApp/CameraFrontView.swift
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()
}
}


21 changes: 0 additions & 21 deletions Warhol/SampleApp/ContentView.swift

This file was deleted.

62 changes: 62 additions & 0 deletions Warhol/SampleApp/ImageViewController.swift
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()
}
}
23 changes: 6 additions & 17 deletions Warhol/SampleApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,14 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>NSCameraUsageDescription</key>
<string>Needs Camera to try Warhol</string>
<key>UIMainStoryboardFile~iphone</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
Loading

0 comments on commit 016338e

Please sign in to comment.