From aecd876b78f31303464450ed55b7b34df8679d35 Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Tue, 9 Jan 2018 10:22:04 -0800 Subject: [PATCH 01/16] migrated to swift 4 --- FaceTracking.xcodeproj/project.pbxproj | 8 ++++++-- FaceTracking/ViewController.swift | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/FaceTracking.xcodeproj/project.pbxproj b/FaceTracking.xcodeproj/project.pbxproj index 31b57b6..372c58b 100644 --- a/FaceTracking.xcodeproj/project.pbxproj +++ b/FaceTracking.xcodeproj/project.pbxproj @@ -109,6 +109,7 @@ E5AB7BCD1D9E92DA0079BE5B = { CreatedOnToolsVersion = 8.0; DevelopmentTeam = 27FAFL2WP5; + LastSwiftMigration = 0920; ProvisioningStyle = Automatic; }; }; @@ -279,7 +280,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -293,7 +295,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -316,6 +319,7 @@ E5AB7BE21D9E92DA0079BE5B /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index 2d25105..1d4e211 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -53,13 +53,13 @@ class ViewController: UIViewController { lazy var previewLayer: AVCaptureVideoPreviewLayer? = { var previewLay = AVCaptureVideoPreviewLayer(session: self.session!) - previewLay?.videoGravity = AVLayerVideoGravityResizeAspectFill + previewLay.videoGravity = AVLayerVideoGravity.resizeAspectFill return previewLay }() lazy var frontCamera: AVCaptureDevice? = { - guard let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) as? [AVCaptureDevice] else { return nil } + guard let devices = AVCaptureDevice.devices(for: AVMediaType.video) as? [AVCaptureDevice] else { return nil } return devices.filter { $0.position == .front }.first }() @@ -94,7 +94,7 @@ extension ViewController { guard let session = session, let captureDevice = frontCamera else { return } - session.sessionPreset = AVCaptureSessionPresetPhoto + session.sessionPreset = AVCaptureSession.Preset.photo do { let deviceInput = try AVCaptureDeviceInput(device: captureDevice) @@ -125,7 +125,7 @@ extension ViewController { } extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { - func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) { + func captureOutput(_ captureOutput: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate) let ciImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?) From 771346d12a00c3a1904f76dc0ddf7b57cf8d4add Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Tue, 9 Jan 2018 10:41:26 -0800 Subject: [PATCH 02/16] migrated to swift 4 and add plist key and string for camera permission --- FaceTracking.xcodeproj/project.pbxproj | 26 ++++++++++++++----- .../xcschemes/FaceTracking.xcscheme | 4 ++- FaceTracking/Info.plist | 2 ++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/FaceTracking.xcodeproj/project.pbxproj b/FaceTracking.xcodeproj/project.pbxproj index 372c58b..8451582 100644 --- a/FaceTracking.xcodeproj/project.pbxproj +++ b/FaceTracking.xcodeproj/project.pbxproj @@ -103,12 +103,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0800; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = "Pawel Chmiel"; TargetAttributes = { E5AB7BCD1D9E92DA0079BE5B = { CreatedOnToolsVersion = 8.0; - DevelopmentTeam = 27FAFL2WP5; + DevelopmentTeam = PZ83QFGZ4V; LastSwiftMigration = 0920; ProvisioningStyle = Automatic; }; @@ -186,7 +186,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -194,7 +196,12 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -236,7 +243,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -244,7 +253,12 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -274,13 +288,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = 27FAFL2WP5; + DEVELOPMENT_TEAM = PZ83QFGZ4V; INFOPLIST_FILE = FaceTracking/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; @@ -289,13 +303,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = 27FAFL2WP5; + DEVELOPMENT_TEAM = PZ83QFGZ4V; INFOPLIST_FILE = FaceTracking/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; diff --git a/FaceTracking.xcodeproj/xcshareddata/xcschemes/FaceTracking.xcscheme b/FaceTracking.xcodeproj/xcshareddata/xcschemes/FaceTracking.xcscheme index 37b0813..f81b6a7 100644 --- a/FaceTracking.xcodeproj/xcshareddata/xcschemes/FaceTracking.xcscheme +++ b/FaceTracking.xcodeproj/xcshareddata/xcschemes/FaceTracking.xcscheme @@ -1,6 +1,6 @@ @@ -45,6 +46,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/FaceTracking/Info.plist b/FaceTracking/Info.plist index d052473..883a1e3 100644 --- a/FaceTracking/Info.plist +++ b/FaceTracking/Info.plist @@ -20,6 +20,8 @@ 1 LSRequiresIPhoneOS + NSCameraUsageDescription + App requires camera to demo face tracking UILaunchStoryboardName LaunchScreen UIMainStoryboardFile From 704a7d9fa88ec72c50ea69bc15e421b83bf0ceae Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Tue, 9 Jan 2018 10:46:45 -0800 Subject: [PATCH 03/16] set device to require fullscreen portrait mode to clear xcode warning and removed unecessary cast to clear warning --- FaceTracking/Info.plist | 4 ++-- FaceTracking/ViewController.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/FaceTracking/Info.plist b/FaceTracking/Info.plist index 883a1e3..8334cd2 100644 --- a/FaceTracking/Info.plist +++ b/FaceTracking/Info.plist @@ -30,11 +30,11 @@ armv7 + UIRequiresFullScreen + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index 1d4e211..83cf5f2 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -59,7 +59,7 @@ class ViewController: UIViewController { }() lazy var frontCamera: AVCaptureDevice? = { - guard let devices = AVCaptureDevice.devices(for: AVMediaType.video) as? [AVCaptureDevice] else { return nil } + let devices = AVCaptureDevice.devices(for: AVMediaType.video) return devices.filter { $0.position == .front }.first }() From f5586c9d0d9ba8a36f9497526d423033c14c8f5f Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Tue, 9 Jan 2018 11:01:12 -0800 Subject: [PATCH 04/16] reversed eye label left/right description to reflect user experince rather than image orientation --- FaceTracking/ViewController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index 83cf5f2..a8c2dd0 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -125,6 +125,7 @@ extension ViewController { } extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { + func captureOutput(_ captureOutput: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate) @@ -132,6 +133,7 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { let options: [String : Any] = [CIDetectorImageOrientation: exifOrientation(orientation: UIDevice.current.orientation), CIDetectorSmile: true, CIDetectorEyeBlink: true] + let allFeatures = faceDetector?.features(in: ciImage, options: options) let formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer) @@ -143,8 +145,8 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { if let faceFeature = feature as? CIFaceFeature { let faceRect = calculateFaceRect(facePosition: faceFeature.mouthPosition, faceBounds: faceFeature.bounds, clearAperture: cleanAperture) let featureDetails = ["has smile: \(faceFeature.hasSmile)", - "has closed left eye: \(faceFeature.leftEyeClosed)", - "has closed right eye: \(faceFeature.rightEyeClosed)"] + "has closed right eye: \(faceFeature.leftEyeClosed)", + "has closed left eye: \(faceFeature.rightEyeClosed)"] update(with: faceRect, text: featureDetails.joined(separator: "\n")) } From 9162b0ae24c38cbc963b1a943d366d9ed8789a76 Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Wed, 10 Jan 2018 11:02:38 -0800 Subject: [PATCH 05/16] fixed tracking frame to work in all orientations and added rotation to detailView to follow device orientation --- FaceTracking/ViewController.swift | 50 ++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index a8c2dd0..7fe2e68 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -1,4 +1,4 @@ -// + // // ViewController.swift // AutoCamera // @@ -39,6 +39,10 @@ class DetailsView: UIView { class ViewController: UIViewController { + + var lastOrientation = UIDeviceOrientation.portrait + + var blinkCount = 0 var session: AVCaptureSession? var stillOutput = AVCaptureStillImageOutput() @@ -52,6 +56,7 @@ class ViewController: UIViewController { }() lazy var previewLayer: AVCaptureVideoPreviewLayer? = { + var previewLay = AVCaptureVideoPreviewLayer(session: self.session!) previewLay.videoGravity = AVLayerVideoGravity.resizeAspectFill @@ -88,7 +93,7 @@ class ViewController: UIViewController { } extension ViewController { - + func sessionPrepare() { session = AVCaptureSession() @@ -127,12 +132,17 @@ extension ViewController { extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { func captureOutput(_ captureOutput: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { + let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) + let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate) + let ciImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?) + let options: [String : Any] = [CIDetectorImageOrientation: exifOrientation(orientation: UIDevice.current.orientation), CIDetectorSmile: true, CIDetectorEyeBlink: true] + let allFeatures = faceDetector?.features(in: ciImage, options: options) @@ -143,12 +153,18 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { for feature in features { if let faceFeature = feature as? CIFaceFeature { + let faceRect = calculateFaceRect(facePosition: faceFeature.mouthPosition, faceBounds: faceFeature.bounds, clearAperture: cleanAperture) let featureDetails = ["has smile: \(faceFeature.hasSmile)", "has closed right eye: \(faceFeature.leftEyeClosed)", "has closed left eye: \(faceFeature.rightEyeClosed)"] - + update(with: faceRect, text: featureDetails.joined(separator: "\n")) + + if faceFeature.rightEyeClosed && faceFeature.leftEyeClosed { + blinkCount += 1 + print("Blinked! \(blinkCount)") + } } } @@ -161,6 +177,7 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { } func exifOrientation(orientation: UIDeviceOrientation) -> Int { + switch orientation { case .portraitUpsideDown: return 8 @@ -230,12 +247,37 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { extension ViewController { func update(with faceRect: CGRect, text: String) { + DispatchQueue.main.async { - UIView.animate(withDuration: 0.2) { + UIView.animate(withDuration: 0.2) { [unowned self] in self.detailsView.detailsLabel.text = text self.detailsView.alpha = 1.0 self.detailsView.frame = faceRect + + self.rotateDetailViewWithDeviceOrientation() } } } + + func rotateDetailViewWithDeviceOrientation() { + switch UIDevice.current.orientation { + + case .portrait: + self.detailsView.transform = CGAffineTransform(rotationAngle: 0) + + case .landscapeLeft: + self.detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2) + + case .landscapeRight: + self.detailsView.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2) + + case .portraitUpsideDown: + self.detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi) + + default: + // Nothing to do for the rest + print("default") + } + + } } From abca1bfaaf54025dcb69acd692872d34cd5f9805 Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Wed, 10 Jan 2018 11:06:31 -0800 Subject: [PATCH 06/16] removed random variables --- FaceTracking/ViewController.swift | 9 --------- 1 file changed, 9 deletions(-) diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index 7fe2e68..d964a19 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -39,10 +39,6 @@ class DetailsView: UIView { class ViewController: UIViewController { - - var lastOrientation = UIDeviceOrientation.portrait - - var blinkCount = 0 var session: AVCaptureSession? var stillOutput = AVCaptureStillImageOutput() @@ -160,11 +156,6 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { "has closed left eye: \(faceFeature.rightEyeClosed)"] update(with: faceRect, text: featureDetails.joined(separator: "\n")) - - if faceFeature.rightEyeClosed && faceFeature.leftEyeClosed { - blinkCount += 1 - print("Blinked! \(blinkCount)") - } } } From e1d5c8cb1b0143a6b07395927a2432f7b4737fde Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Fri, 19 Jan 2018 09:38:18 -0800 Subject: [PATCH 07/16] commit before reset branch --- FaceTracking.xcodeproj/project.pbxproj | 10 ++++++---- .../Assets.xcassets/AppIcon.appiconset/Contents.json | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/FaceTracking.xcodeproj/project.pbxproj b/FaceTracking.xcodeproj/project.pbxproj index 8451582..4ff45a4 100644 --- a/FaceTracking.xcodeproj/project.pbxproj +++ b/FaceTracking.xcodeproj/project.pbxproj @@ -224,12 +224,13 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -275,10 +276,11 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -290,7 +292,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEVELOPMENT_TEAM = PZ83QFGZ4V; INFOPLIST_FILE = FaceTracking/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -305,7 +307,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEVELOPMENT_TEAM = PZ83QFGZ4V; INFOPLIST_FILE = FaceTracking/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/FaceTracking/Assets.xcassets/AppIcon.appiconset/Contents.json b/FaceTracking/Assets.xcassets/AppIcon.appiconset/Contents.json index 1d060ed..d8db8d6 100644 --- a/FaceTracking/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/FaceTracking/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -84,6 +84,11 @@ "idiom" : "ipad", "size" : "83.5x83.5", "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { From 9121a8326067bf5fb295f05bfaaf91a31a29a5e7 Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Mon, 22 Jan 2018 15:48:58 -0800 Subject: [PATCH 08/16] removed code signing trying to pass Travis CI testing --- FaceTracking.xcodeproj/project.pbxproj | 13 ++++++------- FaceTracking/ViewController.swift | 7 ++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/FaceTracking.xcodeproj/project.pbxproj b/FaceTracking.xcodeproj/project.pbxproj index 4ff45a4..dcb480d 100644 --- a/FaceTracking.xcodeproj/project.pbxproj +++ b/FaceTracking.xcodeproj/project.pbxproj @@ -108,7 +108,6 @@ TargetAttributes = { E5AB7BCD1D9E92DA0079BE5B = { CreatedOnToolsVersion = 8.0; - DevelopmentTeam = PZ83QFGZ4V; LastSwiftMigration = 0920; ProvisioningStyle = Automatic; }; @@ -224,7 +223,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.3; + IPHONEOS_DEPLOYMENT_TARGET = 11.2; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -276,7 +275,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.3; + IPHONEOS_DEPLOYMENT_TARGET = 11.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -290,9 +289,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = PZ83QFGZ4V; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = FaceTracking/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.3; + IPHONEOS_DEPLOYMENT_TARGET = 11.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -305,9 +304,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = PZ83QFGZ4V; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = FaceTracking/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.3; + IPHONEOS_DEPLOYMENT_TARGET = 11.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index d964a19..607bce8 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -41,7 +41,7 @@ class DetailsView: UIView { class ViewController: UIViewController { var session: AVCaptureSession? - var stillOutput = AVCaptureStillImageOutput() + var stillOutput = AVCapturePhotoOutput() var borderLayer: CAShapeLayer? let detailsView: DetailsView = { @@ -60,9 +60,10 @@ class ViewController: UIViewController { }() lazy var frontCamera: AVCaptureDevice? = { - let devices = AVCaptureDevice.devices(for: AVMediaType.video) - return devices.filter { $0.position == .front }.first + let discoverySession = AVCaptureDevice.DiscoverySession.init(deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera], mediaType: .video, position: AVCaptureDevice.Position.front) + + return discoverySession.devices.count > 0 ? discoverySession.devices.first : nil }() let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: [CIDetectorAccuracy : CIDetectorAccuracyLow]) From dd9df6fd58c251a48239931b95c2f880b0f7932c Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Fri, 26 Jan 2018 09:49:57 -0800 Subject: [PATCH 09/16] Corrected issues from PChmiel regarding pull request --- FaceTracking/ViewController.swift | 37 ++++++++++++------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index 607bce8..1f2a5ad 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -1,4 +1,4 @@ - // +// // ViewController.swift // AutoCamera // @@ -61,9 +61,9 @@ class ViewController: UIViewController { lazy var frontCamera: AVCaptureDevice? = { - let discoverySession = AVCaptureDevice.DiscoverySession.init(deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera], mediaType: .video, position: AVCaptureDevice.Position.front) + let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera], mediaType: .video, position: AVCaptureDevice.Position.front) - return discoverySession.devices.count > 0 ? discoverySession.devices.first : nil + return discoverySession.devices.first }() let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: [CIDetectorAccuracy : CIDetectorAccuracyLow]) @@ -130,11 +130,11 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { func captureOutput(_ captureOutput: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { - let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) + guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } - let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate) + guard let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate) else { return } - let ciImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?) + let ciImage = CIImage(cvImageBuffer: pixelBuffer, options: (attachments as! [String : Any])) let options: [String : Any] = [CIDetectorImageOrientation: exifOrientation(orientation: UIDevice.current.orientation), CIDetectorSmile: true, @@ -153,8 +153,8 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { let faceRect = calculateFaceRect(facePosition: faceFeature.mouthPosition, faceBounds: faceFeature.bounds, clearAperture: cleanAperture) let featureDetails = ["has smile: \(faceFeature.hasSmile)", - "has closed right eye: \(faceFeature.leftEyeClosed)", - "has closed left eye: \(faceFeature.rightEyeClosed)"] + "has closed right eye: \(faceFeature.rightEyeClosed)", + "has closed left eye: \(faceFeature.leftEyeClosed)"] update(with: faceRect, text: featureDetails.joined(separator: "\n")) } @@ -169,7 +169,6 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { } func exifOrientation(orientation: UIDeviceOrientation) -> Int { - switch orientation { case .portraitUpsideDown: return 8 @@ -241,7 +240,7 @@ extension ViewController { func update(with faceRect: CGRect, text: String) { DispatchQueue.main.async { - UIView.animate(withDuration: 0.2) { [unowned self] in + UIView.animate(withDuration: 0.2) { self.detailsView.detailsLabel.text = text self.detailsView.alpha = 1.0 self.detailsView.frame = faceRect @@ -253,23 +252,15 @@ extension ViewController { func rotateDetailViewWithDeviceOrientation() { switch UIDevice.current.orientation { - case .portrait: - self.detailsView.transform = CGAffineTransform(rotationAngle: 0) - + detailsView.transform = CGAffineTransform(rotationAngle: 0) case .landscapeLeft: - self.detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2) - + detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2) case .landscapeRight: - self.detailsView.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2) - + detailsView.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2) case .portraitUpsideDown: - self.detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi) - - default: - // Nothing to do for the rest - print("default") + detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi) + default: () } - } } From 1a13c3c2d997ca7c3b01080f35c9c5464b73ca54 Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Fri, 26 Jan 2018 23:52:49 -0800 Subject: [PATCH 10/16] removed new lines and changed formatting to udate method --- FaceTracking/ViewController.swift | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index 1f2a5ad..721a9a6 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -52,7 +52,6 @@ class ViewController: UIViewController { }() lazy var previewLayer: AVCaptureVideoPreviewLayer? = { - var previewLay = AVCaptureVideoPreviewLayer(session: self.session!) previewLay.videoGravity = AVLayerVideoGravity.resizeAspectFill @@ -60,7 +59,6 @@ class ViewController: UIViewController { }() lazy var frontCamera: AVCaptureDevice? = { - let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera], mediaType: .video, position: AVCaptureDevice.Position.front) return discoverySession.devices.first @@ -90,7 +88,7 @@ class ViewController: UIViewController { } extension ViewController { - + func sessionPrepare() { session = AVCaptureSession() @@ -127,20 +125,14 @@ extension ViewController { } extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { - func captureOutput(_ captureOutput: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } - guard let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate) else { return } - let ciImage = CIImage(cvImageBuffer: pixelBuffer, options: (attachments as! [String : Any])) - let options: [String : Any] = [CIDetectorImageOrientation: exifOrientation(orientation: UIDevice.current.orientation), CIDetectorSmile: true, CIDetectorEyeBlink: true] - - let allFeatures = faceDetector?.features(in: ciImage, options: options) let formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer) @@ -150,7 +142,6 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { for feature in features { if let faceFeature = feature as? CIFaceFeature { - let faceRect = calculateFaceRect(facePosition: faceFeature.mouthPosition, faceBounds: faceFeature.bounds, clearAperture: cleanAperture) let featureDetails = ["has smile: \(faceFeature.hasSmile)", "has closed right eye: \(faceFeature.rightEyeClosed)", @@ -238,13 +229,11 @@ extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { extension ViewController { func update(with faceRect: CGRect, text: String) { - DispatchQueue.main.async { UIView.animate(withDuration: 0.2) { self.detailsView.detailsLabel.text = text self.detailsView.alpha = 1.0 self.detailsView.frame = faceRect - self.rotateDetailViewWithDeviceOrientation() } } From 83c7e4e37826c31c8a219104147edd874428a6e5 Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Thu, 8 Feb 2018 16:10:11 -0800 Subject: [PATCH 11/16] removed call to rotate face tracking view --- FaceTracking/ViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index 721a9a6..f739cb7 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -234,7 +234,6 @@ extension ViewController { self.detailsView.detailsLabel.text = text self.detailsView.alpha = 1.0 self.detailsView.frame = faceRect - self.rotateDetailViewWithDeviceOrientation() } } } From 47355334f91c25e1f74b9115ded790e3a807eb80 Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Thu, 8 Feb 2018 16:13:17 -0800 Subject: [PATCH 12/16] removed methods to rotate view --- FaceTracking/ViewController.swift | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/FaceTracking/ViewController.swift b/FaceTracking/ViewController.swift index f739cb7..fe4d300 100644 --- a/FaceTracking/ViewController.swift +++ b/FaceTracking/ViewController.swift @@ -237,18 +237,4 @@ extension ViewController { } } } - - func rotateDetailViewWithDeviceOrientation() { - switch UIDevice.current.orientation { - case .portrait: - detailsView.transform = CGAffineTransform(rotationAngle: 0) - case .landscapeLeft: - detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2) - case .landscapeRight: - detailsView.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2) - case .portraitUpsideDown: - detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi) - default: () - } - } } From 7de87c28177a5744ef478dbf26dcf684fee8595c Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Thu, 8 Feb 2018 16:22:20 -0800 Subject: [PATCH 13/16] turned off automatic code signing trying to pass CI tests --- FaceTracking.xcodeproj/project.pbxproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/FaceTracking.xcodeproj/project.pbxproj b/FaceTracking.xcodeproj/project.pbxproj index dcb480d..12d4fd2 100644 --- a/FaceTracking.xcodeproj/project.pbxproj +++ b/FaceTracking.xcodeproj/project.pbxproj @@ -109,7 +109,7 @@ E5AB7BCD1D9E92DA0079BE5B = { CreatedOnToolsVersion = 8.0; LastSwiftMigration = 0920; - ProvisioningStyle = Automatic; + ProvisioningStyle = Manual; }; }; }; @@ -289,12 +289,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = FaceTracking/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; @@ -304,12 +306,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = FaceTracking/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.droidsonroids.FaceTracking; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; From b709500ed65d177377a2a0018c4adec24d964c4c Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Thu, 8 Feb 2018 16:25:56 -0800 Subject: [PATCH 14/16] turned on auto signing --- FaceTracking.xcodeproj/project.pbxproj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/FaceTracking.xcodeproj/project.pbxproj b/FaceTracking.xcodeproj/project.pbxproj index 12d4fd2..f8bef25 100644 --- a/FaceTracking.xcodeproj/project.pbxproj +++ b/FaceTracking.xcodeproj/project.pbxproj @@ -109,7 +109,7 @@ E5AB7BCD1D9E92DA0079BE5B = { CreatedOnToolsVersion = 8.0; LastSwiftMigration = 0920; - ProvisioningStyle = Manual; + ProvisioningStyle = Automatic; }; }; }; @@ -289,7 +289,8 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_STYLE = Manual; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = FaceTracking/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.2; @@ -306,7 +307,8 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_STYLE = Manual; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = FaceTracking/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 11.2; From f71b176b5b7faf5fb44f2430a28015888b70dddf Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Thu, 8 Feb 2018 16:35:48 -0800 Subject: [PATCH 15/16] set 'Don't Code Sign' in in Code Signing Identities in Build Settings --- FaceTracking.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FaceTracking.xcodeproj/project.pbxproj b/FaceTracking.xcodeproj/project.pbxproj index f8bef25..07a8d1a 100644 --- a/FaceTracking.xcodeproj/project.pbxproj +++ b/FaceTracking.xcodeproj/project.pbxproj @@ -204,7 +204,7 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -262,7 +262,7 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; From 4bfb2ad653642a089ac1b30859dd3da9d5a199fd Mon Sep 17 00:00:00 2001 From: Ryan Rosello Date: Thu, 8 Feb 2018 16:57:56 -0800 Subject: [PATCH 16/16] reset to 'iOS Developer' in in Code Signing Identities in Build Settings --- FaceTracking.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FaceTracking.xcodeproj/project.pbxproj b/FaceTracking.xcodeproj/project.pbxproj index 07a8d1a..f8bef25 100644 --- a/FaceTracking.xcodeproj/project.pbxproj +++ b/FaceTracking.xcodeproj/project.pbxproj @@ -204,7 +204,7 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -262,7 +262,7 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO;