├── README.md ├── Text Detection Starter Project.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ ├── SaiKambampati.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ ├── idscomercial.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── simon.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── SaiKambampati.xcuserdatad │ └── xcschemes │ │ └── xcschememanagement.plist │ ├── idscomercial.xcuserdatad │ └── xcschemes │ │ └── xcschememanagement.plist │ └── simon.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── Text Detection Starter Project ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift └── TextDetectionStarter.zip /README.md: -------------------------------------------------------------------------------- 1 | # Vision Framework Demo on Text Detection 2 | 3 | Among many of the powerful frameworks Apple released at this year’s WWDC, the Vision framework was one of them. With the Vision framework, you can easily implement computer vision techniques into your apps with no higher knowledge at all! With Vision, you can have your app perform a number of powerful tasks such as identifying faces and faical features (ex: smile, frown, left eyebrow, etc.), barcode detection, classifying scenes in images, object detection and tracking, and horizon detection. 4 | 5 | In this demo app, we show you how to work the Vision framework in Swift. For the full tutorial, please refer to the link below: 6 | 7 | http://www.appcoda.com/vision-framework-introduction 8 | 9 | -------------------------------------------------------------------------------- /Text Detection Starter Project.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8B0D6AFF1EFA582B00544F3D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B0D6AFE1EFA582B00544F3D /* AppDelegate.swift */; }; 11 | 8B0D6B011EFA582B00544F3D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B0D6B001EFA582B00544F3D /* ViewController.swift */; }; 12 | 8B0D6B041EFA582B00544F3D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8B0D6B021EFA582B00544F3D /* Main.storyboard */; }; 13 | 8B0D6B061EFA582B00544F3D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8B0D6B051EFA582B00544F3D /* Assets.xcassets */; }; 14 | 8B0D6B091EFA582B00544F3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8B0D6B071EFA582B00544F3D /* LaunchScreen.storyboard */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 8B0D6AFB1EFA582B00544F3D /* Text Detection Starter Project.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Text Detection Starter Project.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 8B0D6AFE1EFA582B00544F3D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 20 | 8B0D6B001EFA582B00544F3D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 21 | 8B0D6B031EFA582B00544F3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 22 | 8B0D6B051EFA582B00544F3D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 8B0D6B081EFA582B00544F3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 24 | 8B0D6B0A1EFA582C00544F3D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | 8B0D6AF81EFA582B00544F3D /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | 8B0D6AF21EFA582B00544F3D = { 39 | isa = PBXGroup; 40 | children = ( 41 | 8B0D6AFD1EFA582B00544F3D /* Text Detection Starter Project */, 42 | 8B0D6AFC1EFA582B00544F3D /* Products */, 43 | ); 44 | sourceTree = ""; 45 | }; 46 | 8B0D6AFC1EFA582B00544F3D /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 8B0D6AFB1EFA582B00544F3D /* Text Detection Starter Project.app */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | 8B0D6AFD1EFA582B00544F3D /* Text Detection Starter Project */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 8B0D6AFE1EFA582B00544F3D /* AppDelegate.swift */, 58 | 8B0D6B001EFA582B00544F3D /* ViewController.swift */, 59 | 8B0D6B021EFA582B00544F3D /* Main.storyboard */, 60 | 8B0D6B051EFA582B00544F3D /* Assets.xcassets */, 61 | 8B0D6B071EFA582B00544F3D /* LaunchScreen.storyboard */, 62 | 8B0D6B0A1EFA582C00544F3D /* Info.plist */, 63 | ); 64 | path = "Text Detection Starter Project"; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | 8B0D6AFA1EFA582B00544F3D /* Text Detection Starter Project */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = 8B0D6B0D1EFA582C00544F3D /* Build configuration list for PBXNativeTarget "Text Detection Starter Project" */; 73 | buildPhases = ( 74 | 8B0D6AF71EFA582B00544F3D /* Sources */, 75 | 8B0D6AF81EFA582B00544F3D /* Frameworks */, 76 | 8B0D6AF91EFA582B00544F3D /* Resources */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = "Text Detection Starter Project"; 83 | productName = "Text Detection Starter Project"; 84 | productReference = 8B0D6AFB1EFA582B00544F3D /* Text Detection Starter Project.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | 8B0D6AF31EFA582B00544F3D /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | LastSwiftUpdateCheck = 0900; 94 | LastUpgradeCheck = 0900; 95 | ORGANIZATIONNAME = AppCoda; 96 | TargetAttributes = { 97 | 8B0D6AFA1EFA582B00544F3D = { 98 | CreatedOnToolsVersion = 9.0; 99 | LastSwiftMigration = 1160; 100 | }; 101 | }; 102 | }; 103 | buildConfigurationList = 8B0D6AF61EFA582B00544F3D /* Build configuration list for PBXProject "Text Detection Starter Project" */; 104 | compatibilityVersion = "Xcode 8.0"; 105 | developmentRegion = en; 106 | hasScannedForEncodings = 0; 107 | knownRegions = ( 108 | en, 109 | Base, 110 | ); 111 | mainGroup = 8B0D6AF21EFA582B00544F3D; 112 | productRefGroup = 8B0D6AFC1EFA582B00544F3D /* Products */; 113 | projectDirPath = ""; 114 | projectRoot = ""; 115 | targets = ( 116 | 8B0D6AFA1EFA582B00544F3D /* Text Detection Starter Project */, 117 | ); 118 | }; 119 | /* End PBXProject section */ 120 | 121 | /* Begin PBXResourcesBuildPhase section */ 122 | 8B0D6AF91EFA582B00544F3D /* Resources */ = { 123 | isa = PBXResourcesBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | 8B0D6B091EFA582B00544F3D /* LaunchScreen.storyboard in Resources */, 127 | 8B0D6B061EFA582B00544F3D /* Assets.xcassets in Resources */, 128 | 8B0D6B041EFA582B00544F3D /* Main.storyboard in Resources */, 129 | ); 130 | runOnlyForDeploymentPostprocessing = 0; 131 | }; 132 | /* End PBXResourcesBuildPhase section */ 133 | 134 | /* Begin PBXSourcesBuildPhase section */ 135 | 8B0D6AF71EFA582B00544F3D /* Sources */ = { 136 | isa = PBXSourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 8B0D6B011EFA582B00544F3D /* ViewController.swift in Sources */, 140 | 8B0D6AFF1EFA582B00544F3D /* AppDelegate.swift in Sources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXSourcesBuildPhase section */ 145 | 146 | /* Begin PBXVariantGroup section */ 147 | 8B0D6B021EFA582B00544F3D /* Main.storyboard */ = { 148 | isa = PBXVariantGroup; 149 | children = ( 150 | 8B0D6B031EFA582B00544F3D /* Base */, 151 | ); 152 | name = Main.storyboard; 153 | sourceTree = ""; 154 | }; 155 | 8B0D6B071EFA582B00544F3D /* LaunchScreen.storyboard */ = { 156 | isa = PBXVariantGroup; 157 | children = ( 158 | 8B0D6B081EFA582B00544F3D /* Base */, 159 | ); 160 | name = LaunchScreen.storyboard; 161 | sourceTree = ""; 162 | }; 163 | /* End PBXVariantGroup section */ 164 | 165 | /* Begin XCBuildConfiguration section */ 166 | 8B0D6B0B1EFA582C00544F3D /* Debug */ = { 167 | isa = XCBuildConfiguration; 168 | buildSettings = { 169 | ALWAYS_SEARCH_USER_PATHS = NO; 170 | CLANG_ANALYZER_NONNULL = YES; 171 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 172 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 173 | CLANG_CXX_LIBRARY = "libc++"; 174 | CLANG_ENABLE_MODULES = YES; 175 | CLANG_ENABLE_OBJC_ARC = YES; 176 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 177 | CLANG_WARN_BOOL_CONVERSION = YES; 178 | CLANG_WARN_COMMA = YES; 179 | CLANG_WARN_CONSTANT_CONVERSION = YES; 180 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 181 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 182 | CLANG_WARN_EMPTY_BODY = YES; 183 | CLANG_WARN_ENUM_CONVERSION = YES; 184 | CLANG_WARN_INFINITE_RECURSION = YES; 185 | CLANG_WARN_INT_CONVERSION = YES; 186 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 187 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 188 | CLANG_WARN_STRICT_PROTOTYPES = YES; 189 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 190 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 191 | CLANG_WARN_UNREACHABLE_CODE = YES; 192 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 193 | CODE_SIGN_IDENTITY = "iPhone Developer"; 194 | COPY_PHASE_STRIP = NO; 195 | DEBUG_INFORMATION_FORMAT = dwarf; 196 | ENABLE_STRICT_OBJC_MSGSEND = YES; 197 | ENABLE_TESTABILITY = YES; 198 | GCC_C_LANGUAGE_STANDARD = gnu11; 199 | GCC_DYNAMIC_NO_PIC = NO; 200 | GCC_NO_COMMON_BLOCKS = YES; 201 | GCC_OPTIMIZATION_LEVEL = 0; 202 | GCC_PREPROCESSOR_DEFINITIONS = ( 203 | "DEBUG=1", 204 | "$(inherited)", 205 | ); 206 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 207 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 208 | GCC_WARN_UNDECLARED_SELECTOR = YES; 209 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 210 | GCC_WARN_UNUSED_FUNCTION = YES; 211 | GCC_WARN_UNUSED_VARIABLE = YES; 212 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 213 | MTL_ENABLE_DEBUG_INFO = YES; 214 | ONLY_ACTIVE_ARCH = YES; 215 | SDKROOT = iphoneos; 216 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 217 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 218 | }; 219 | name = Debug; 220 | }; 221 | 8B0D6B0C1EFA582C00544F3D /* Release */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | ALWAYS_SEARCH_USER_PATHS = NO; 225 | CLANG_ANALYZER_NONNULL = YES; 226 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_MODULES = YES; 230 | CLANG_ENABLE_OBJC_ARC = YES; 231 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 232 | CLANG_WARN_BOOL_CONVERSION = YES; 233 | CLANG_WARN_COMMA = YES; 234 | CLANG_WARN_CONSTANT_CONVERSION = YES; 235 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 236 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 237 | CLANG_WARN_EMPTY_BODY = YES; 238 | CLANG_WARN_ENUM_CONVERSION = YES; 239 | CLANG_WARN_INFINITE_RECURSION = YES; 240 | CLANG_WARN_INT_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 243 | CLANG_WARN_STRICT_PROTOTYPES = YES; 244 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 245 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 246 | CLANG_WARN_UNREACHABLE_CODE = YES; 247 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 248 | CODE_SIGN_IDENTITY = "iPhone Developer"; 249 | COPY_PHASE_STRIP = NO; 250 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 251 | ENABLE_NS_ASSERTIONS = NO; 252 | ENABLE_STRICT_OBJC_MSGSEND = YES; 253 | GCC_C_LANGUAGE_STANDARD = gnu11; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 256 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 257 | GCC_WARN_UNDECLARED_SELECTOR = YES; 258 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 259 | GCC_WARN_UNUSED_FUNCTION = YES; 260 | GCC_WARN_UNUSED_VARIABLE = YES; 261 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 262 | MTL_ENABLE_DEBUG_INFO = NO; 263 | SDKROOT = iphoneos; 264 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 265 | VALIDATE_PRODUCT = YES; 266 | }; 267 | name = Release; 268 | }; 269 | 8B0D6B0E1EFA582C00544F3D /* Debug */ = { 270 | isa = XCBuildConfiguration; 271 | buildSettings = { 272 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 273 | DEVELOPMENT_TEAM = 852DX56354; 274 | INFOPLIST_FILE = "Text Detection Starter Project/Info.plist"; 275 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 276 | PRODUCT_BUNDLE_IDENTIFIER = com.josamtz.TextDetection; 277 | PRODUCT_NAME = "$(TARGET_NAME)"; 278 | SWIFT_VERSION = 5.0; 279 | TARGETED_DEVICE_FAMILY = "1,2"; 280 | }; 281 | name = Debug; 282 | }; 283 | 8B0D6B0F1EFA582C00544F3D /* Release */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 287 | DEVELOPMENT_TEAM = 852DX56354; 288 | INFOPLIST_FILE = "Text Detection Starter Project/Info.plist"; 289 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 290 | PRODUCT_BUNDLE_IDENTIFIER = com.josamtz.TextDetection; 291 | PRODUCT_NAME = "$(TARGET_NAME)"; 292 | SWIFT_VERSION = 5.0; 293 | TARGETED_DEVICE_FAMILY = "1,2"; 294 | }; 295 | name = Release; 296 | }; 297 | /* End XCBuildConfiguration section */ 298 | 299 | /* Begin XCConfigurationList section */ 300 | 8B0D6AF61EFA582B00544F3D /* Build configuration list for PBXProject "Text Detection Starter Project" */ = { 301 | isa = XCConfigurationList; 302 | buildConfigurations = ( 303 | 8B0D6B0B1EFA582C00544F3D /* Debug */, 304 | 8B0D6B0C1EFA582C00544F3D /* Release */, 305 | ); 306 | defaultConfigurationIsVisible = 0; 307 | defaultConfigurationName = Release; 308 | }; 309 | 8B0D6B0D1EFA582C00544F3D /* Build configuration list for PBXNativeTarget "Text Detection Starter Project" */ = { 310 | isa = XCConfigurationList; 311 | buildConfigurations = ( 312 | 8B0D6B0E1EFA582C00544F3D /* Debug */, 313 | 8B0D6B0F1EFA582C00544F3D /* Release */, 314 | ); 315 | defaultConfigurationIsVisible = 0; 316 | defaultConfigurationName = Release; 317 | }; 318 | /* End XCConfigurationList section */ 319 | }; 320 | rootObject = 8B0D6AF31EFA582B00544F3D /* Project object */; 321 | } 322 | -------------------------------------------------------------------------------- /Text Detection Starter Project.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Text Detection Starter Project.xcodeproj/project.xcworkspace/xcuserdata/SaiKambampati.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextDetection/3bfac0600d91d5db91436f528c6bebc1c6cd7770/Text Detection Starter Project.xcodeproj/project.xcworkspace/xcuserdata/SaiKambampati.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Text Detection Starter Project.xcodeproj/project.xcworkspace/xcuserdata/idscomercial.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextDetection/3bfac0600d91d5db91436f528c6bebc1c6cd7770/Text Detection Starter Project.xcodeproj/project.xcworkspace/xcuserdata/idscomercial.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Text Detection Starter Project.xcodeproj/project.xcworkspace/xcuserdata/simon.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextDetection/3bfac0600d91d5db91436f528c6bebc1c6cd7770/Text Detection Starter Project.xcodeproj/project.xcworkspace/xcuserdata/simon.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Text Detection Starter Project.xcodeproj/xcuserdata/SaiKambampati.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Text Detection Starter Project.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Text Detection Starter Project.xcodeproj/xcuserdata/idscomercial.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Text Detection Starter Project.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Text Detection Starter Project.xcodeproj/xcuserdata/simon.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Text Detection Starter Project.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Text Detection Starter Project/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Text Detection Starter Project 4 | // 5 | // Created by Sai Kambampati on 6/21/17. 6 | // Copyright © 2017 AppCoda. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // 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. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Text Detection Starter Project/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /Text Detection Starter Project/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Text Detection Starter Project/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Text Detection Starter Project/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSCameraUsageDescription 24 | for text detection 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Text Detection Starter Project/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Text Detection Starter Project 4 | // 5 | // Created by Sai Kambampati on 6/21/17. 6 | // Copyright © 2017 AppCoda. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AVFoundation 11 | import Vision 12 | 13 | class ViewController: UIViewController { 14 | 15 | @IBOutlet weak var imageView: UIImageView! 16 | var session = AVCaptureSession() 17 | var requests = [VNRequest]() 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | 22 | startLiveVideo() 23 | startTextDetection() 24 | } 25 | 26 | override func viewWillAppear(_ animated: Bool) { 27 | 28 | } 29 | 30 | override func didReceiveMemoryWarning() { 31 | super.didReceiveMemoryWarning() 32 | // Dispose of any resources that can be recreated. 33 | } 34 | 35 | func startLiveVideo() { 36 | //1 37 | session.sessionPreset = AVCaptureSession.Preset.photo 38 | let captureDevice = AVCaptureDevice.default(for: AVMediaType.video) 39 | 40 | //2 41 | let deviceInput = try! AVCaptureDeviceInput(device: captureDevice!) 42 | let deviceOutput = AVCaptureVideoDataOutput() 43 | deviceOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)] 44 | deviceOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: DispatchQoS.QoSClass.default)) 45 | session.addInput(deviceInput) 46 | session.addOutput(deviceOutput) 47 | 48 | //3 49 | let imageLayer = AVCaptureVideoPreviewLayer(session: session) 50 | imageLayer.frame = imageView.bounds 51 | imageView.layer.addSublayer(imageLayer) 52 | 53 | session.startRunning() 54 | } 55 | 56 | override func viewDidLayoutSubviews() { 57 | imageView.layer.sublayers?[0].frame = imageView.bounds 58 | } 59 | 60 | func startTextDetection() { 61 | let textRequest = VNDetectTextRectanglesRequest(completionHandler: self.detectTextHandler) 62 | textRequest.reportCharacterBoxes = true 63 | self.requests = [textRequest] 64 | } 65 | 66 | func detectTextHandler(request: VNRequest, error: Error?) { 67 | guard let observations = request.results else { 68 | print("no result") 69 | return 70 | } 71 | 72 | let result = observations.map({$0 as? VNTextObservation}) 73 | 74 | DispatchQueue.main.async() { 75 | self.imageView.layer.sublayers?.removeSubrange(1...) 76 | for region in result { 77 | guard let rg = region else { 78 | continue 79 | } 80 | 81 | self.highlightWord(box: rg) 82 | 83 | if let boxes = region?.characterBoxes { 84 | for characterBox in boxes { 85 | self.highlightLetters(box: characterBox) 86 | } 87 | } 88 | } 89 | } 90 | } 91 | 92 | func highlightWord(box: VNTextObservation) { 93 | guard let boxes = box.characterBoxes else { 94 | return 95 | } 96 | 97 | var maxX: CGFloat = 9999.0 98 | var minX: CGFloat = 0.0 99 | var maxY: CGFloat = 9999.0 100 | var minY: CGFloat = 0.0 101 | 102 | for char in boxes { 103 | if char.bottomLeft.x < maxX { 104 | maxX = char.bottomLeft.x 105 | } 106 | if char.bottomRight.x > minX { 107 | minX = char.bottomRight.x 108 | } 109 | if char.bottomRight.y < maxY { 110 | maxY = char.bottomRight.y 111 | } 112 | if char.topRight.y > minY { 113 | minY = char.topRight.y 114 | } 115 | } 116 | 117 | let xCord = maxX * imageView.frame.size.width 118 | let yCord = (1 - minY) * imageView.frame.size.height 119 | let width = (minX - maxX) * imageView.frame.size.width 120 | let height = (minY - maxY) * imageView.frame.size.height 121 | 122 | let outline = CALayer() 123 | outline.frame = CGRect(x: xCord, y: yCord, width: width, height: height) 124 | outline.borderWidth = 2.0 125 | outline.borderColor = UIColor.red.cgColor 126 | 127 | imageView.layer.addSublayer(outline) 128 | } 129 | 130 | func highlightLetters(box: VNRectangleObservation) { 131 | let xCord = box.topLeft.x * imageView.frame.size.width 132 | let yCord = (1 - box.topLeft.y) * imageView.frame.size.height 133 | let width = (box.topRight.x - box.bottomLeft.x) * imageView.frame.size.width 134 | let height = (box.topLeft.y - box.bottomLeft.y) * imageView.frame.size.height 135 | 136 | let outline = CALayer() 137 | outline.frame = CGRect(x: xCord, y: yCord, width: width, height: height) 138 | outline.borderWidth = 1.0 139 | outline.borderColor = UIColor.blue.cgColor 140 | 141 | imageView.layer.addSublayer(outline) 142 | } 143 | } 144 | 145 | extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { 146 | func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { 147 | guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { 148 | return 149 | } 150 | 151 | var requestOptions:[VNImageOption : Any] = [:] 152 | 153 | if let camData = CMGetAttachment(sampleBuffer, key: kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, attachmentModeOut: nil) { 154 | requestOptions = [.cameraIntrinsics:camData] 155 | } 156 | 157 | let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: CGImagePropertyOrientation(rawValue: 6)!, options: requestOptions) 158 | 159 | do { 160 | try imageRequestHandler.perform(self.requests) 161 | } catch { 162 | print(error) 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /TextDetectionStarter.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextDetection/3bfac0600d91d5db91436f528c6bebc1c6cd7770/TextDetectionStarter.zip --------------------------------------------------------------------------------