diff --git a/Logo.png b/Logo.png new file mode 100644 index 0000000..204009c Binary files /dev/null and b/Logo.png differ diff --git a/Logo.psd b/Logo.psd new file mode 100644 index 0000000..17dd7ca Binary files /dev/null and b/Logo.psd differ diff --git a/iOSApp/.DS_Store b/iOSApp/.DS_Store new file mode 100644 index 0000000..14765bb Binary files /dev/null and b/iOSApp/.DS_Store differ diff --git a/iOSApp/AutoSafe.xcodeproj/project.pbxproj b/iOSApp/AutoSafe.xcodeproj/project.pbxproj new file mode 100644 index 0000000..45de948 --- /dev/null +++ b/iOSApp/AutoSafe.xcodeproj/project.pbxproj @@ -0,0 +1,355 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 3E359493229A91790052C95A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E359492229A91790052C95A /* AppDelegate.swift */; }; + 3E359497229A91790052C95A /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E359496229A91790052C95A /* SecondViewController.swift */; }; + 3E35949A229A91790052C95A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E359498229A91790052C95A /* Main.storyboard */; }; + 3E35949C229A917A0052C95A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3E35949B229A917A0052C95A /* Assets.xcassets */; }; + 3E35949F229A917A0052C95A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E35949D229A917A0052C95A /* LaunchScreen.storyboard */; }; + 3E3594A9229A964F0052C95A /* FatigueViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3594A8229A964F0052C95A /* FatigueViewController.swift */; }; + 3E3594AB229A982A0052C95A /* FaceLandmarksDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3594AA229A982A0052C95A /* FaceLandmarksDetector.swift */; }; + 3E3594AD229A98670052C95A /* UIImage+Scale.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3594AC229A98670052C95A /* UIImage+Scale.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 3E35948F229A91790052C95A /* AutoSafe.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AutoSafe.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 3E359492229A91790052C95A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 3E359496229A91790052C95A /* SecondViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = ""; }; + 3E359499229A91790052C95A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 3E35949B229A917A0052C95A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 3E35949E229A917A0052C95A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 3E3594A0229A917A0052C95A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 3E3594A8229A964F0052C95A /* FatigueViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FatigueViewController.swift; sourceTree = ""; }; + 3E3594AA229A982A0052C95A /* FaceLandmarksDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaceLandmarksDetector.swift; sourceTree = ""; }; + 3E3594AC229A98670052C95A /* UIImage+Scale.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Scale.swift"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 3E35948C229A91790052C95A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 3E359486229A91790052C95A = { + isa = PBXGroup; + children = ( + 3E359491229A91790052C95A /* AutoSafe */, + 3E359490229A91790052C95A /* Products */, + ); + sourceTree = ""; + }; + 3E359490229A91790052C95A /* Products */ = { + isa = PBXGroup; + children = ( + 3E35948F229A91790052C95A /* AutoSafe.app */, + ); + name = Products; + sourceTree = ""; + }; + 3E359491229A91790052C95A /* AutoSafe */ = { + isa = PBXGroup; + children = ( + 3E3594A8229A964F0052C95A /* FatigueViewController.swift */, + 3E359492229A91790052C95A /* AppDelegate.swift */, + 3E359496229A91790052C95A /* SecondViewController.swift */, + 3E359498229A91790052C95A /* Main.storyboard */, + 3E35949B229A917A0052C95A /* Assets.xcassets */, + 3E35949D229A917A0052C95A /* LaunchScreen.storyboard */, + 3E3594A0229A917A0052C95A /* Info.plist */, + 3E3594AA229A982A0052C95A /* FaceLandmarksDetector.swift */, + 3E3594AC229A98670052C95A /* UIImage+Scale.swift */, + ); + path = AutoSafe; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 3E35948E229A91790052C95A /* AutoSafe */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3E3594A3229A917A0052C95A /* Build configuration list for PBXNativeTarget "AutoSafe" */; + buildPhases = ( + 3E35948B229A91790052C95A /* Sources */, + 3E35948C229A91790052C95A /* Frameworks */, + 3E35948D229A91790052C95A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = AutoSafe; + productName = AutoSafe; + productReference = 3E35948F229A91790052C95A /* AutoSafe.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 3E359487229A91790052C95A /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1020; + LastUpgradeCheck = 1020; + ORGANIZATIONNAME = "Navan Chauhan"; + TargetAttributes = { + 3E35948E229A91790052C95A = { + CreatedOnToolsVersion = 10.2.1; + }; + }; + }; + buildConfigurationList = 3E35948A229A91790052C95A /* Build configuration list for PBXProject "AutoSafe" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 3E359486229A91790052C95A; + productRefGroup = 3E359490229A91790052C95A /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 3E35948E229A91790052C95A /* AutoSafe */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 3E35948D229A91790052C95A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3E35949F229A917A0052C95A /* LaunchScreen.storyboard in Resources */, + 3E35949C229A917A0052C95A /* Assets.xcassets in Resources */, + 3E35949A229A91790052C95A /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 3E35948B229A91790052C95A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3E359497229A91790052C95A /* SecondViewController.swift in Sources */, + 3E359493229A91790052C95A /* AppDelegate.swift in Sources */, + 3E3594A9229A964F0052C95A /* FatigueViewController.swift in Sources */, + 3E3594AB229A982A0052C95A /* FaceLandmarksDetector.swift in Sources */, + 3E3594AD229A98670052C95A /* UIImage+Scale.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 3E359498229A91790052C95A /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 3E359499229A91790052C95A /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 3E35949D229A917A0052C95A /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 3E35949E229A917A0052C95A /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 3E3594A1229A917A0052C95A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + 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_IMPLICIT_RETAIN_SELF = 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_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.2; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 3E3594A2229A917A0052C95A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + 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_IMPLICIT_RETAIN_SELF = 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_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.2; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 3E3594A4229A917A0052C95A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 6BS49F3GLW; + INFOPLIST_FILE = AutoSafe/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.navanchauhan.autosafemobile; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 3E3594A5229A917A0052C95A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 6BS49F3GLW; + INFOPLIST_FILE = AutoSafe/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.navanchauhan.autosafemobile; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 3E35948A229A91790052C95A /* Build configuration list for PBXProject "AutoSafe" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3E3594A1229A917A0052C95A /* Debug */, + 3E3594A2229A917A0052C95A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 3E3594A3229A917A0052C95A /* Build configuration list for PBXNativeTarget "AutoSafe" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3E3594A4229A917A0052C95A /* Debug */, + 3E3594A5229A917A0052C95A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 3E359487229A91790052C95A /* Project object */; +} diff --git a/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..54086ce --- /dev/null +++ b/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/xcuserdata/navanchauhan.xcuserdatad/UserInterfaceState.xcuserstate b/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/xcuserdata/navanchauhan.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..ed57292 Binary files /dev/null and b/iOSApp/AutoSafe.xcodeproj/project.xcworkspace/xcuserdata/navanchauhan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iOSApp/AutoSafe.xcodeproj/xcuserdata/navanchauhan.xcuserdatad/xcschemes/xcschememanagement.plist b/iOSApp/AutoSafe.xcodeproj/xcuserdata/navanchauhan.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..1e4a5b8 --- /dev/null +++ b/iOSApp/AutoSafe.xcodeproj/xcuserdata/navanchauhan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + AutoSafe.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/iOSApp/AutoSafe/.DS_Store b/iOSApp/AutoSafe/.DS_Store new file mode 100644 index 0000000..4c76d10 Binary files /dev/null and b/iOSApp/AutoSafe/.DS_Store differ diff --git a/iOSApp/AutoSafe/AppDelegate.swift b/iOSApp/AutoSafe/AppDelegate.swift new file mode 100644 index 0000000..3b11ca5 --- /dev/null +++ b/iOSApp/AutoSafe/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// AutoSafe +// +// Created by Navan Chauhan on 26/05/19. +// Copyright © 2019 Navan Chauhan. 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 + } + + func applicationWillResignActive(_ application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(_ application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Contents.json b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..8d8f4bb --- /dev/null +++ b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,122 @@ +{ + "images" : [ + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@3x.png", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@1x.png", + "scale" : "1x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "1024x1024", + "idiom" : "ios-marketing", + "filename" : "ItunesArtwork@2x.png", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png new file mode 100644 index 0000000..1023684 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png new file mode 100644 index 0000000..d8bfff4 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png new file mode 100644 index 0000000..1ab5526 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png new file mode 100644 index 0000000..7722deb Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png new file mode 100644 index 0000000..57af5b9 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png new file mode 100644 index 0000000..17b8445 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png new file mode 100644 index 0000000..d8bfff4 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png new file mode 100644 index 0000000..e492161 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png new file mode 100644 index 0000000..89280f5 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png new file mode 100644 index 0000000..89280f5 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png new file mode 100644 index 0000000..cf9857f Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png new file mode 100644 index 0000000..9017311 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png new file mode 100644 index 0000000..f01965c Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png new file mode 100644 index 0000000..31ae078 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png new file mode 100644 index 0000000..77224d2 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/Contents.json b/iOSApp/AutoSafe/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/iOSApp/AutoSafe/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/iOSApp/AutoSafe/Assets.xcassets/first.imageset/Contents.json b/iOSApp/AutoSafe/Assets.xcassets/first.imageset/Contents.json new file mode 100644 index 0000000..33a7451 --- /dev/null +++ b/iOSApp/AutoSafe/Assets.xcassets/first.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "first.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/iOSApp/AutoSafe/Assets.xcassets/first.imageset/first.pdf b/iOSApp/AutoSafe/Assets.xcassets/first.imageset/first.pdf new file mode 100644 index 0000000..47d911d Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/first.imageset/first.pdf differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/Contents.json b/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/Contents.json new file mode 100644 index 0000000..43003d0 --- /dev/null +++ b/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "iTunesArtwork@1x.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "iTunesArtwork@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "iTunesArtwork@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@1x.png b/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@1x.png new file mode 100644 index 0000000..e780f81 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@1x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@2x.png b/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@2x.png new file mode 100644 index 0000000..77224d2 Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@2x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@3x.png b/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@3x.png new file mode 100644 index 0000000..799d91a Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/iTunesArtwork.imageset/iTunesArtwork@3x.png differ diff --git a/iOSApp/AutoSafe/Assets.xcassets/second.imageset/Contents.json b/iOSApp/AutoSafe/Assets.xcassets/second.imageset/Contents.json new file mode 100644 index 0000000..03bd9c9 --- /dev/null +++ b/iOSApp/AutoSafe/Assets.xcassets/second.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "second.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/iOSApp/AutoSafe/Assets.xcassets/second.imageset/second.pdf b/iOSApp/AutoSafe/Assets.xcassets/second.imageset/second.pdf new file mode 100644 index 0000000..401614e Binary files /dev/null and b/iOSApp/AutoSafe/Assets.xcassets/second.imageset/second.pdf differ diff --git a/iOSApp/AutoSafe/Base.lproj/LaunchScreen.storyboard b/iOSApp/AutoSafe/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..6b735c8 --- /dev/null +++ b/iOSApp/AutoSafe/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSApp/AutoSafe/Base.lproj/Main.storyboard b/iOSApp/AutoSafe/Base.lproj/Main.storyboard new file mode 100644 index 0000000..5c5e033 --- /dev/null +++ b/iOSApp/AutoSafe/Base.lproj/Main.storyboard @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSApp/AutoSafe/FaceLandmarksDetector.swift b/iOSApp/AutoSafe/FaceLandmarksDetector.swift new file mode 100644 index 0000000..6aeac33 --- /dev/null +++ b/iOSApp/AutoSafe/FaceLandmarksDetector.swift @@ -0,0 +1,196 @@ +// +// FaceLandmarksDetector.swift +// AutoSafe +// +// Created by Navan Chauhan on 26/05/19. +// Copyright © 2019 Navan Chauhan. All rights reserved. +// + +import AVFoundation +import UIKit +import Vision + +class FaceLandmarksDetector { + var counter = 0 + open func highlightFaces(for source: UIImage, complete: @escaping (UIImage) -> Void) { + var resultImage = source + let detectFaceRequest = VNDetectFaceLandmarksRequest { (request, error) in + if error == nil { + if let results = request.results as? [VNFaceObservation] { + for faceObservation in results { + guard let landmarks = faceObservation.landmarks else { + continue + } + let boundingRect = faceObservation.boundingBox + + resultImage = self.drawOnImage(source: resultImage, boundingRect: boundingRect, faceLandmarks: landmarks) + } + } + } else { + print(error!.localizedDescription) + } + complete(resultImage) + } + + let vnImage = VNImageRequestHandler(cgImage: source.cgImage!, options: [:]) + try? vnImage.perform([detectFaceRequest]) + } + + private func drawOnImage(source: UIImage, boundingRect: CGRect, faceLandmarks: VNFaceLandmarks2D) -> UIImage { + UIGraphicsBeginImageContextWithOptions(source.size, false, 1) + let context = UIGraphicsGetCurrentContext()! + context.translateBy(x: 0.0, y: source.size.height) + context.scaleBy(x: 1.0, y: -1.0) + //context.setBlendMode(CGBlendMode.colorBurn) + context.setLineJoin(.round) + context.setLineCap(.round) + context.setShouldAntialias(true) + context.setAllowsAntialiasing(true) + + let rectWidth = source.size.width * boundingRect.size.width + let rectHeight = source.size.height * boundingRect.size.height + + //draw image + let rect = CGRect(x: 0, y:0, width: source.size.width, height: source.size.height) + context.draw(source.cgImage!, in: rect) + + + //draw bound rect + context.setStrokeColor(UIColor.green.cgColor) + context.addRect(CGRect(x: boundingRect.origin.x * source.size.width, y:boundingRect.origin.y * source.size.height, width: rectWidth, height: rectHeight)) + context.drawPath(using: CGPathDrawingMode.stroke) + + //draw overlay + context.setLineWidth(1.0) + + func drawFeature(_ feature: VNFaceLandmarkRegion2D, color: CGColor, close: Bool = false) { + context.setStrokeColor(color) + context.setFillColor(color) + for point in feature.normalizedPoints { + // Draw DEBUG numbers + let textFontAttributes = [ + NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), + NSAttributedString.Key.foregroundColor: UIColor.white + ] + context.saveGState() + // rotate to draw numbers + context.translateBy(x: 0.0, y: source.size.height) + context.scaleBy(x: 1.0, y: -1.0) + let mp = CGPoint(x: boundingRect.origin.x * source.size.width + point.x * rectWidth, y: source.size.height - (boundingRect.origin.y * source.size.height + point.y * rectHeight)) + context.fillEllipse(in: CGRect(origin: CGPoint(x: mp.x-2.0, y: mp.y-2), size: CGSize(width: 4.0, height: 4.0))) + if let index = feature.normalizedPoints.firstIndex(of: point) { + NSString(format: "%d", index).draw(at: mp, withAttributes: textFontAttributes); + //print(mp, index); + } + context.restoreGState() + } + let mappedPoints = feature.normalizedPoints.map { CGPoint(x: boundingRect.origin.x * source.size.width + $0.x * rectWidth, y: boundingRect.origin.y * source.size.height + $0.y * rectHeight) } + context.addLines(between: mappedPoints) + if close, let first = mappedPoints.first, let lats = mappedPoints.last { + context.addLines(between: [lats, first]) + } + context.strokePath() + } + + + if let leftEye = faceLandmarks.leftEye { + drawFeature(leftEye, color: UIColor.cyan.cgColor, close: true) + /* + for point in leftEye.normalizedPoints { + let mp = CGPoint(x: boundingRect.origin.x * source.size.width + point.x * rectWidth, y: source.size.height - (boundingRect.origin.y * source.size.height + point.y * rectHeight)) + /* + if let index = leftEye.normalizedPoints.index(of: point) { + print(mp, index); + if(index==4){ + print("fuck me, this works!!!") + point4.append(mp[0]) + } */ + + } + + //for i in leftEye.normalizedPoints{ + // print("HEHE:") + // print(i) + //} + */ + //let p1.x = leftEye.normalizedPoints[0].x; + + + } + if let rightEye = faceLandmarks.rightEye { + drawFeature(rightEye, color: UIColor.cyan.cgColor, close: true) + + } + if let leftPupil = faceLandmarks.leftPupil { + drawFeature(leftPupil, color: UIColor.cyan.cgColor, close: true) + } + if let rightPupil = faceLandmarks.rightPupil { + drawFeature(rightPupil, color: UIColor.cyan.cgColor, close: true) + } + + + + if let leftEye = faceLandmarks.leftEye, let rightEye = faceLandmarks.rightEye { + print("WORKS?") + + let p1l = leftEye.normalizedPoints[1] + let p2l = leftEye.normalizedPoints[7] + + let p3l = leftEye.normalizedPoints[3] + let p4l = leftEye.normalizedPoints[5] + + let p5l = leftEye.normalizedPoints[0] + let p6l = leftEye.normalizedPoints[4] + + let Al = hypotf(Float(p1l.x - p2l.x), Float(p1l.y - p2l.y)); + let Bl = hypotf(Float(p3l.x - p4l.x), Float(p3l.y - p4l.y)); + let Cl = hypotf(Float(p5l.x - p6l.x), Float(p5l.y - p6l.y)); + + let leftEAR = (Al + Bl) / (2.0 * Cl) + + print("Left EAR", leftEAR); + + let p1r = rightEye.normalizedPoints[1] + let p2r = rightEye.normalizedPoints[7] + + let p3r = rightEye.normalizedPoints[3] + let p4r = rightEye.normalizedPoints[5] + + let p5r = rightEye.normalizedPoints[0] + let p6r = rightEye.normalizedPoints[4] + + let Ar = hypotf(Float(p1r.x - p2r.x), Float(p1r.y - p2r.y)); + let Br = hypotf(Float(p3r.x - p4r.x), Float(p3r.y - p4r.y)); + let Cr = hypotf(Float(p5r.x - p6r.x), Float(p5r.y - p6r.y)); + + let rightEAR = (Ar + Br) / (2.0 * Cr) + + print("Right EAR", rightEAR); + + let EAR = (Float(leftEAR) + Float(rightEAR)) / 2.0 + print("EAR:", EAR) + + let threshold = Float(0.25) + let noOfFrames = 2 + + if EAR < threshold { + counter += 1; + } + if EAR > threshold { + counter -= 1; + } + if counter > noOfFrames { + print("Wake up Sid!") + AudioServicesPlayAlertSound(SystemSoundID(1005)) + counter = 0 + + } + } + let coloredImg : UIImage = UIGraphicsGetImageFromCurrentImageContext()! + UIGraphicsEndImageContext() + return coloredImg + } +} + + + diff --git a/iOSApp/AutoSafe/FatigueViewController.swift b/iOSApp/AutoSafe/FatigueViewController.swift new file mode 100644 index 0000000..1e9f98f --- /dev/null +++ b/iOSApp/AutoSafe/FatigueViewController.swift @@ -0,0 +1,83 @@ +// +// FatigueDetection.swift +// AutoSafe +// +// Created by Navan Chauhan on 26/05/19. +// Copyright © 2019 Navan Chauhan. All rights reserved. +// + +import UIKit +import AVFoundation +import Vision + +class FatigueViewController: UIViewController { + + let faceDetector = FaceLandmarksDetector() + let captureSession = AVCaptureSession() + @IBOutlet weak var imageView: UIImageView! + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view, typically from a nib. + configureDevice() + } + + private func getDevice() -> AVCaptureDevice? { + let discoverSession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera, .builtInTelephotoCamera, .builtInWideAngleCamera], mediaType: .video, position: .front) + return discoverSession.devices.first + } + + private func configureDevice() { + if let device = getDevice() { + do { + try device.lockForConfiguration() + if device.isFocusModeSupported(.continuousAutoFocus) { + device.focusMode = .continuousAutoFocus + } + device.unlockForConfiguration() + } catch { print("failed to lock config") } + + do { + let input = try AVCaptureDeviceInput(device: device) + captureSession.addInput(input) + } catch { print("failed to create AVCaptureDeviceInput") } + + captureSession.startRunning() + + let videoOutput = AVCaptureVideoDataOutput() + videoOutput.videoSettings = [String(kCVPixelBufferPixelFormatTypeKey): Int(kCVPixelFormatType_32BGRA)] + videoOutput.alwaysDiscardsLateVideoFrames = true + videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: .utility)) + + if captureSession.canAddOutput(videoOutput) { + captureSession.addOutput(videoOutput) + } + } + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + +} + +extension FatigueViewController: AVCaptureVideoDataOutputSampleBufferDelegate { + + func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { + + // Scale image to process it faster + let maxSize = CGSize(width: 1024, height: 1024) + + if let image = UIImage(sampleBuffer: sampleBuffer)?.flipped()?.imageWithAspectFit(size: maxSize) { + faceDetector.highlightFaces(for: image) { (resultImage) in + DispatchQueue.main.async { + self.imageView?.image = resultImage + } + } + } + } +} + + diff --git a/iOSApp/AutoSafe/Info.plist b/iOSApp/AutoSafe/Info.plist new file mode 100644 index 0000000..cfce526 --- /dev/null +++ b/iOSApp/AutoSafe/Info.plist @@ -0,0 +1,57 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + NSCameraUsageDescription + For Fatigue Detection + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarTintParameters + + UINavigationBar + + Style + UIBarStyleDefault + Translucent + + + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/iOSApp/AutoSafe/SecondViewController.swift b/iOSApp/AutoSafe/SecondViewController.swift new file mode 100644 index 0000000..addbd61 --- /dev/null +++ b/iOSApp/AutoSafe/SecondViewController.swift @@ -0,0 +1,20 @@ +// +// SecondViewController.swift +// AutoSafe +// +// Created by Navan Chauhan on 26/05/19. +// Copyright © 2019 Navan Chauhan. All rights reserved. +// + +import UIKit + +class SecondViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + } + + +} + diff --git a/iOSApp/AutoSafe/UIImage+Scale.swift b/iOSApp/AutoSafe/UIImage+Scale.swift new file mode 100644 index 0000000..118eac2 --- /dev/null +++ b/iOSApp/AutoSafe/UIImage+Scale.swift @@ -0,0 +1,86 @@ +// +// UIImage+Scale.swift +// AutoSafe +// +// Created by Navan Chauhan on 26/05/19. +// Copyright © 2019 Navan Chauhan. All rights reserved. +// + +import UIKit +import CoreMedia + +extension UIImage { + + convenience init?(sampleBuffer: CMSampleBuffer) { + + guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return nil } + CVPixelBufferLockBaseAddress(imageBuffer, CVPixelBufferLockFlags.readOnly) + + let baseAddress = CVPixelBufferGetBaseAddress(imageBuffer) + let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer) + let width = CVPixelBufferGetWidth(imageBuffer) + let height = CVPixelBufferGetHeight(imageBuffer) + let colorSpace = CGColorSpaceCreateDeviceRGB() + + let bitmapInfo: UInt32 = CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue & CGBitmapInfo.alphaInfoMask.rawValue + guard let context = CGContext(data: baseAddress, width: width, height: height, bitsPerComponent: 8, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo) else { return nil } + let quartzImage = context.makeImage() + CVPixelBufferUnlockBaseAddress(imageBuffer, CVPixelBufferLockFlags.readOnly) + + if let quartz = quartzImage { + self.init(cgImage: quartz, scale: 1.0, orientation: .right) + //self.init(cgImage: quartz) + } else { + return nil + } + } + + func hasAlpha() -> Bool { + if let cgImage = self.cgImage { + let alpha = cgImage.alphaInfo + return alpha == .first || alpha == .last || alpha == .premultipliedFirst || alpha == .premultipliedLast + } + return false + } + + func flipped() -> UIImage? { + UIGraphicsBeginImageContextWithOptions(self.size, !self.hasAlpha(), self.scale) + let context = UIGraphicsGetCurrentContext()! + context.translateBy(x: self.size.width, y: 0.0) + context.scaleBy(x: -1.0, y: 1.0) + let rect = CGRect(origin: .zero, size: self.size) + self.draw(in: rect) + let retVal = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + return retVal + } + + func imageWithAspectFit(size:CGSize) -> UIImage? { + let aspectFitSize = self.getAspectFitSize(destination: size) + let resizedImage = self.resize(size: aspectFitSize) + return resizedImage + } + + private func getAspectFitSize(destination dst:CGSize) -> CGSize { + var result = CGSize.zero + var scaleRatio = CGPoint() + + if (dst.width != 0) {scaleRatio.x = self.size.width / dst.width} + if (dst.height != 0) {scaleRatio.y = self.size.height / dst.height} + let scaleFactor = max(scaleRatio.x, scaleRatio.y) + + result.width = scaleRatio.x * dst.width / scaleFactor + result.height = scaleRatio.y * dst.height / scaleFactor + return result + } + + func resize(size:CGSize) -> UIImage? { + let imageRect = CGRect(origin: .zero, size: size); + + UIGraphicsBeginImageContextWithOptions(size, false, 1.0); + self.draw(in: imageRect) + let scaled = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return scaled + } +}