├── .gitignore ├── .swift-version ├── .travis.yml ├── Example ├── ImageDetect.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── ImageDetect-Example.xcscheme ├── ImageDetect.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── ImageDetect │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── ImageCollectionViewCell.swift │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift ├── Podfile └── Podfile.lock ├── ImageDetect.podspec ├── ImageDetect └── Classes │ ├── .gitkeep │ └── ImageDetect.swift ├── LICENSE ├── README.md ├── Screenshots ├── 1.PNG └── 2.PNG ├── _Pods.xcodeproj └── _config.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Adapted from https://www.gitignore.io/api/xcode,swift,cocoapods 2 | 3 | # Finder 4 | .DS_Store 5 | 6 | ### CocoaPods ### 7 | ## CocoaPods GitIgnore Template 8 | 9 | # CocoaPods - Only use to conserve bandwidth / Save time on Pushing 10 | # - Also handy if you have a large number of dependant pods 11 | # - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE 12 | Pods/ 13 | 14 | ### Swift ### 15 | # Xcode 16 | # 17 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 18 | 19 | ## Build generated 20 | build/ 21 | DerivedData/ 22 | 23 | ## Various settings 24 | *.pbxuser 25 | !default.pbxuser 26 | *.mode1v3 27 | !default.mode1v3 28 | *.mode2v3 29 | !default.mode2v3 30 | *.perspectivev3 31 | !default.perspectivev3 32 | xcuserdata/ 33 | 34 | ## Other 35 | *.moved-aside 36 | *.xccheckout 37 | *.xcscmblueprint 38 | 39 | ## Obj-C/Swift specific 40 | *.hmap 41 | *.ipa 42 | *.dSYM.zip 43 | *.dSYM 44 | 45 | ## Playgrounds 46 | timeline.xctimeline 47 | playground.xcworkspace 48 | 49 | # Swift Package Manager 50 | # 51 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 52 | # Packages/ 53 | # Package.pins 54 | .build/ 55 | 56 | # CocoaPods - Refactored to standalone file 57 | 58 | # Carthage - Refactored to standalone file 59 | 60 | # fastlane 61 | # 62 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 63 | # screenshots whenever they are needed. 64 | # For more information about the recommended setup visit: 65 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 66 | 67 | fastlane/report.xml 68 | fastlane/Preview.html 69 | fastlane/screenshots 70 | fastlane/test_output 71 | 72 | ### Xcode ### 73 | # Xcode 74 | # 75 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 76 | 77 | ## Build generated 78 | 79 | ## Various settings 80 | 81 | ## Other 82 | 83 | ### Xcode Patch ### 84 | *.xcodeproj/* 85 | !*.xcodeproj/project.pbxproj 86 | !*.xcodeproj/xcshareddata/ 87 | !*.xcworkspace/contents.xcworkspacedata 88 | /*.gcno 89 | 90 | 91 | # End of https://www.gitignore.io/api/xcode,swift,cocoapods -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # references: 2 | # * http://www.objc.io/issue-6/travis-ci.html 3 | # * https://github.com/supermarin/xcpretty#usage 4 | 5 | osx_image: xcode9.4 6 | language: objective-c 7 | # cache: cocoapods 8 | # podfile: Example/Podfile 9 | # before_install: 10 | # - gem install cocoapods # Since Travis is not always on latest version 11 | # - pod install --project-directory=Example 12 | script: 13 | - pod lib lint 14 | -------------------------------------------------------------------------------- /Example/ImageDetect.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 341562F5940490EAE5254961 /* Pods_ImageDetect_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9AC185C22E742B9AFECBE87 /* Pods_ImageDetect_Example.framework */; }; 11 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; 12 | 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; 13 | 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; }; 14 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; 15 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; 16 | DEA87CF8205D545D0013E01E /* ImageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEA87CF7205D545D0013E01E /* ImageCollectionViewCell.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 607FACD01AFB9204008FA782 /* ImageDetect_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ImageDetect_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 22 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 26 | 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 27 | 6607937143B0E566A214F80A /* Pods-ImageDetect_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageDetect_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-ImageDetect_Example/Pods-ImageDetect_Example.release.xcconfig"; sourceTree = ""; }; 28 | 869C7BCB0723285644FD1E43 /* Pods-ImageDetect_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageDetect_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ImageDetect_Example/Pods-ImageDetect_Example.debug.xcconfig"; sourceTree = ""; }; 29 | A4BE9B394385D70E00E89081 /* ImageDetect.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = ImageDetect.podspec; path = ../ImageDetect.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 30 | BC3D6C0D6AB5A344840A2F37 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 31 | D27F8DA16BFB0F3D422390A1 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 32 | D9AC185C22E742B9AFECBE87 /* Pods_ImageDetect_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ImageDetect_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | DEA87CF7205D545D0013E01E /* ImageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewCell.swift; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | 607FACCD1AFB9204008FA782 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | 341562F5940490EAE5254961 /* Pods_ImageDetect_Example.framework in Frameworks */, 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 1DC356EB8C2183EF2DFDA07D /* Frameworks */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | D9AC185C22E742B9AFECBE87 /* Pods_ImageDetect_Example.framework */, 52 | ); 53 | name = Frameworks; 54 | sourceTree = ""; 55 | }; 56 | 607FACC71AFB9204008FA782 = { 57 | isa = PBXGroup; 58 | children = ( 59 | 607FACF51AFB993E008FA782 /* Podspec Metadata */, 60 | 607FACD21AFB9204008FA782 /* Example for ImageDetect */, 61 | 607FACD11AFB9204008FA782 /* Products */, 62 | 99B0D840E7BC3966923036C1 /* Pods */, 63 | 1DC356EB8C2183EF2DFDA07D /* Frameworks */, 64 | ); 65 | sourceTree = ""; 66 | }; 67 | 607FACD11AFB9204008FA782 /* Products */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | 607FACD01AFB9204008FA782 /* ImageDetect_Example.app */, 71 | ); 72 | name = Products; 73 | sourceTree = ""; 74 | }; 75 | 607FACD21AFB9204008FA782 /* Example for ImageDetect */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */, 79 | 607FACD71AFB9204008FA782 /* ViewController.swift */, 80 | DEA87CF7205D545D0013E01E /* ImageCollectionViewCell.swift */, 81 | 607FACD91AFB9204008FA782 /* Main.storyboard */, 82 | 607FACDC1AFB9204008FA782 /* Images.xcassets */, 83 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, 84 | 607FACD31AFB9204008FA782 /* Supporting Files */, 85 | ); 86 | name = "Example for ImageDetect"; 87 | path = ImageDetect; 88 | sourceTree = ""; 89 | }; 90 | 607FACD31AFB9204008FA782 /* Supporting Files */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 607FACD41AFB9204008FA782 /* Info.plist */, 94 | ); 95 | name = "Supporting Files"; 96 | sourceTree = ""; 97 | }; 98 | 607FACF51AFB993E008FA782 /* Podspec Metadata */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | A4BE9B394385D70E00E89081 /* ImageDetect.podspec */, 102 | BC3D6C0D6AB5A344840A2F37 /* README.md */, 103 | D27F8DA16BFB0F3D422390A1 /* LICENSE */, 104 | ); 105 | name = "Podspec Metadata"; 106 | sourceTree = ""; 107 | }; 108 | 99B0D840E7BC3966923036C1 /* Pods */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 869C7BCB0723285644FD1E43 /* Pods-ImageDetect_Example.debug.xcconfig */, 112 | 6607937143B0E566A214F80A /* Pods-ImageDetect_Example.release.xcconfig */, 113 | ); 114 | name = Pods; 115 | sourceTree = ""; 116 | }; 117 | /* End PBXGroup section */ 118 | 119 | /* Begin PBXNativeTarget section */ 120 | 607FACCF1AFB9204008FA782 /* ImageDetect_Example */ = { 121 | isa = PBXNativeTarget; 122 | buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "ImageDetect_Example" */; 123 | buildPhases = ( 124 | E54664A69D6DE6E0037D85DD /* [CP] Check Pods Manifest.lock */, 125 | 607FACCC1AFB9204008FA782 /* Sources */, 126 | 607FACCD1AFB9204008FA782 /* Frameworks */, 127 | 607FACCE1AFB9204008FA782 /* Resources */, 128 | 3A54C5444B5ACDA5B280B61A /* [CP] Embed Pods Frameworks */, 129 | ); 130 | buildRules = ( 131 | ); 132 | dependencies = ( 133 | ); 134 | name = ImageDetect_Example; 135 | productName = ImageDetect; 136 | productReference = 607FACD01AFB9204008FA782 /* ImageDetect_Example.app */; 137 | productType = "com.apple.product-type.application"; 138 | }; 139 | /* End PBXNativeTarget section */ 140 | 141 | /* Begin PBXProject section */ 142 | 607FACC81AFB9204008FA782 /* Project object */ = { 143 | isa = PBXProject; 144 | attributes = { 145 | LastSwiftUpdateCheck = 0830; 146 | LastUpgradeCheck = 1020; 147 | ORGANIZATIONNAME = CocoaPods; 148 | TargetAttributes = { 149 | 607FACCF1AFB9204008FA782 = { 150 | CreatedOnToolsVersion = 6.3.1; 151 | LastSwiftMigration = 1020; 152 | }; 153 | }; 154 | }; 155 | buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "ImageDetect" */; 156 | compatibilityVersion = "Xcode 3.2"; 157 | developmentRegion = en; 158 | hasScannedForEncodings = 0; 159 | knownRegions = ( 160 | en, 161 | Base, 162 | ); 163 | mainGroup = 607FACC71AFB9204008FA782; 164 | productRefGroup = 607FACD11AFB9204008FA782 /* Products */; 165 | projectDirPath = ""; 166 | projectRoot = ""; 167 | targets = ( 168 | 607FACCF1AFB9204008FA782 /* ImageDetect_Example */, 169 | ); 170 | }; 171 | /* End PBXProject section */ 172 | 173 | /* Begin PBXResourcesBuildPhase section */ 174 | 607FACCE1AFB9204008FA782 /* Resources */ = { 175 | isa = PBXResourcesBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, 179 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, 180 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | }; 184 | /* End PBXResourcesBuildPhase section */ 185 | 186 | /* Begin PBXShellScriptBuildPhase section */ 187 | 3A54C5444B5ACDA5B280B61A /* [CP] Embed Pods Frameworks */ = { 188 | isa = PBXShellScriptBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | ); 192 | inputPaths = ( 193 | "${PODS_ROOT}/Target Support Files/Pods-ImageDetect_Example/Pods-ImageDetect_Example-frameworks.sh", 194 | "${BUILT_PRODUCTS_DIR}/ImageDetect/ImageDetect.framework", 195 | ); 196 | name = "[CP] Embed Pods Frameworks"; 197 | outputPaths = ( 198 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ImageDetect.framework", 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | shellPath = /bin/sh; 202 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ImageDetect_Example/Pods-ImageDetect_Example-frameworks.sh\"\n"; 203 | showEnvVarsInLog = 0; 204 | }; 205 | E54664A69D6DE6E0037D85DD /* [CP] Check Pods Manifest.lock */ = { 206 | isa = PBXShellScriptBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | ); 210 | inputPaths = ( 211 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 212 | "${PODS_ROOT}/Manifest.lock", 213 | ); 214 | name = "[CP] Check Pods Manifest.lock"; 215 | outputPaths = ( 216 | "$(DERIVED_FILE_DIR)/Pods-ImageDetect_Example-checkManifestLockResult.txt", 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | shellPath = /bin/sh; 220 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 221 | showEnvVarsInLog = 0; 222 | }; 223 | /* End PBXShellScriptBuildPhase section */ 224 | 225 | /* Begin PBXSourcesBuildPhase section */ 226 | 607FACCC1AFB9204008FA782 /* Sources */ = { 227 | isa = PBXSourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | DEA87CF8205D545D0013E01E /* ImageCollectionViewCell.swift in Sources */, 231 | 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, 232 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | }; 236 | /* End PBXSourcesBuildPhase section */ 237 | 238 | /* Begin PBXVariantGroup section */ 239 | 607FACD91AFB9204008FA782 /* Main.storyboard */ = { 240 | isa = PBXVariantGroup; 241 | children = ( 242 | 607FACDA1AFB9204008FA782 /* Base */, 243 | ); 244 | name = Main.storyboard; 245 | sourceTree = ""; 246 | }; 247 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = { 248 | isa = PBXVariantGroup; 249 | children = ( 250 | 607FACDF1AFB9204008FA782 /* Base */, 251 | ); 252 | name = LaunchScreen.xib; 253 | sourceTree = ""; 254 | }; 255 | /* End PBXVariantGroup section */ 256 | 257 | /* Begin XCBuildConfiguration section */ 258 | 607FACED1AFB9204008FA782 /* Debug */ = { 259 | isa = XCBuildConfiguration; 260 | buildSettings = { 261 | ALWAYS_SEARCH_USER_PATHS = NO; 262 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 264 | CLANG_CXX_LIBRARY = "libc++"; 265 | CLANG_ENABLE_MODULES = YES; 266 | CLANG_ENABLE_OBJC_ARC = YES; 267 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 268 | CLANG_WARN_BOOL_CONVERSION = YES; 269 | CLANG_WARN_COMMA = YES; 270 | CLANG_WARN_CONSTANT_CONVERSION = YES; 271 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 272 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 273 | CLANG_WARN_EMPTY_BODY = YES; 274 | CLANG_WARN_ENUM_CONVERSION = YES; 275 | CLANG_WARN_INFINITE_RECURSION = YES; 276 | CLANG_WARN_INT_CONVERSION = YES; 277 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 279 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 280 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 281 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 282 | CLANG_WARN_STRICT_PROTOTYPES = YES; 283 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 284 | CLANG_WARN_UNREACHABLE_CODE = YES; 285 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 286 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 287 | COPY_PHASE_STRIP = NO; 288 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | ENABLE_TESTABILITY = YES; 291 | GCC_C_LANGUAGE_STANDARD = gnu99; 292 | GCC_DYNAMIC_NO_PIC = NO; 293 | GCC_NO_COMMON_BLOCKS = YES; 294 | GCC_OPTIMIZATION_LEVEL = 0; 295 | GCC_PREPROCESSOR_DEFINITIONS = ( 296 | "DEBUG=1", 297 | "$(inherited)", 298 | ); 299 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 300 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 301 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 302 | GCC_WARN_UNDECLARED_SELECTOR = YES; 303 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 304 | GCC_WARN_UNUSED_FUNCTION = YES; 305 | GCC_WARN_UNUSED_VARIABLE = YES; 306 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 307 | MTL_ENABLE_DEBUG_INFO = YES; 308 | ONLY_ACTIVE_ARCH = YES; 309 | SDKROOT = iphoneos; 310 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 311 | }; 312 | name = Debug; 313 | }; 314 | 607FACEE1AFB9204008FA782 /* Release */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ALWAYS_SEARCH_USER_PATHS = NO; 318 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 319 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 320 | CLANG_CXX_LIBRARY = "libc++"; 321 | CLANG_ENABLE_MODULES = YES; 322 | CLANG_ENABLE_OBJC_ARC = YES; 323 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 324 | CLANG_WARN_BOOL_CONVERSION = YES; 325 | CLANG_WARN_COMMA = YES; 326 | CLANG_WARN_CONSTANT_CONVERSION = YES; 327 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 328 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 329 | CLANG_WARN_EMPTY_BODY = YES; 330 | CLANG_WARN_ENUM_CONVERSION = YES; 331 | CLANG_WARN_INFINITE_RECURSION = YES; 332 | CLANG_WARN_INT_CONVERSION = YES; 333 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 334 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 335 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 336 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 337 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 338 | CLANG_WARN_STRICT_PROTOTYPES = YES; 339 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 340 | CLANG_WARN_UNREACHABLE_CODE = YES; 341 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 342 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 343 | COPY_PHASE_STRIP = NO; 344 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 345 | ENABLE_NS_ASSERTIONS = NO; 346 | ENABLE_STRICT_OBJC_MSGSEND = YES; 347 | GCC_C_LANGUAGE_STANDARD = gnu99; 348 | GCC_NO_COMMON_BLOCKS = YES; 349 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 350 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 351 | GCC_WARN_UNDECLARED_SELECTOR = YES; 352 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 353 | GCC_WARN_UNUSED_FUNCTION = YES; 354 | GCC_WARN_UNUSED_VARIABLE = YES; 355 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 356 | MTL_ENABLE_DEBUG_INFO = NO; 357 | SDKROOT = iphoneos; 358 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 359 | VALIDATE_PRODUCT = YES; 360 | }; 361 | name = Release; 362 | }; 363 | 607FACF01AFB9204008FA782 /* Debug */ = { 364 | isa = XCBuildConfiguration; 365 | baseConfigurationReference = 869C7BCB0723285644FD1E43 /* Pods-ImageDetect_Example.debug.xcconfig */; 366 | buildSettings = { 367 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 368 | DEVELOPMENT_TEAM = ""; 369 | INFOPLIST_FILE = ImageDetect/Info.plist; 370 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 371 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 372 | MODULE_NAME = ExampleApp; 373 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | SWIFT_VERSION = 5.0; 376 | }; 377 | name = Debug; 378 | }; 379 | 607FACF11AFB9204008FA782 /* Release */ = { 380 | isa = XCBuildConfiguration; 381 | baseConfigurationReference = 6607937143B0E566A214F80A /* Pods-ImageDetect_Example.release.xcconfig */; 382 | buildSettings = { 383 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 384 | DEVELOPMENT_TEAM = ""; 385 | INFOPLIST_FILE = ImageDetect/Info.plist; 386 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 387 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 388 | MODULE_NAME = ExampleApp; 389 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 390 | PRODUCT_NAME = "$(TARGET_NAME)"; 391 | SWIFT_VERSION = 5.0; 392 | }; 393 | name = Release; 394 | }; 395 | /* End XCBuildConfiguration section */ 396 | 397 | /* Begin XCConfigurationList section */ 398 | 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "ImageDetect" */ = { 399 | isa = XCConfigurationList; 400 | buildConfigurations = ( 401 | 607FACED1AFB9204008FA782 /* Debug */, 402 | 607FACEE1AFB9204008FA782 /* Release */, 403 | ); 404 | defaultConfigurationIsVisible = 0; 405 | defaultConfigurationName = Release; 406 | }; 407 | 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "ImageDetect_Example" */ = { 408 | isa = XCConfigurationList; 409 | buildConfigurations = ( 410 | 607FACF01AFB9204008FA782 /* Debug */, 411 | 607FACF11AFB9204008FA782 /* Release */, 412 | ); 413 | defaultConfigurationIsVisible = 0; 414 | defaultConfigurationName = Release; 415 | }; 416 | /* End XCConfigurationList section */ 417 | }; 418 | rootObject = 607FACC81AFB9204008FA782 /* Project object */; 419 | } 420 | -------------------------------------------------------------------------------- /Example/ImageDetect.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/ImageDetect.xcodeproj/xcshareddata/xcschemes/ImageDetect-Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 69 | 70 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Example/ImageDetect.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/ImageDetect.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/ImageDetect/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ImageDetect 4 | // 5 | // Created by Arthur Sahakyan on 03/17/2018. 6 | // Copyright (c) 2018 Arthur Sahakyan. 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 throttle down OpenGL ES frame rates. 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 inactive 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 | -------------------------------------------------------------------------------- /Example/ImageDetect/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/ImageDetect/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 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 45 | 46 | 47 | 48 | 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 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /Example/ImageDetect/ImageCollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCollectionViewCell.swift 3 | // ImageDetect_Example 4 | // 5 | // Created by Arthur Sahakyan on 3/17/18. 6 | // Copyright © 2018 Arthur Sahakyan. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ImageCollectionViewCell: UICollectionViewCell { 12 | @IBOutlet weak var imageView: UIImageView! 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Example/ImageDetect/Images.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" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Example/ImageDetect/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSPhotoLibraryUsageDescription 26 | This app requires access to the photo library. 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Example/ImageDetect/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ImageDetect 4 | // 5 | // Created by Arthur Sahakyan on 03/17/2018. 6 | // Copyright (c) 2018 Arthur Sahakyan. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ImageDetect 11 | import Photos 12 | 13 | class ViewController: UIViewController { 14 | @IBOutlet private weak var imageView: UIImageView! 15 | @IBOutlet private weak var collectionView: UICollectionView! 16 | @IBOutlet private weak var activityIndicator: UIActivityIndicatorView! 17 | 18 | var images: [UIImage] = [] 19 | let imagePickerController = UIImagePickerController() 20 | 21 | override func viewDidLoad() { 22 | super.viewDidLoad() 23 | PHPhotoLibrary.requestAuthorization({ (status) in 24 | }) 25 | collectionView.delegate = self 26 | collectionView.dataSource = self 27 | 28 | imagePickerController.sourceType = .photoLibrary 29 | imagePickerController.delegate = self 30 | 31 | activityIndicator.hidesWhenStopped = true 32 | } 33 | 34 | private func cropFaces() { 35 | guard let image = imageView.image else { return } 36 | activityIndicator.startAnimating() 37 | DispatchQueue.global().async { 38 | // `type` in this method can be face, barcode or text 39 | image.detector.crop(type: .face) { result in 40 | DispatchQueue.main.async { [weak self] in 41 | switch result { 42 | case .success(let croppedImages): 43 | // When the `Vision` successfully find type of object you set and successfuly crops it. 44 | self?.images = croppedImages 45 | self?.collectionView.reloadData() 46 | case .notFound: 47 | // When the image doesn't contain any type of object you did set, `result` will be `.notFound`. 48 | print("Not Found") 49 | case .failure(let error): 50 | // When the any error occured, `result` will be `failure`. 51 | print(error.localizedDescription) 52 | } 53 | self?.activityIndicator.stopAnimating() 54 | } 55 | } 56 | } 57 | } 58 | 59 | @IBAction private func changeImageTapped(_ sender: UIButton) { 60 | self.present(imagePickerController, animated: true, completion: nil) 61 | } 62 | } 63 | 64 | extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource { 65 | func numberOfSections(in collectionView: UICollectionView) -> Int { 66 | return 1 67 | } 68 | 69 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 70 | return images.count 71 | } 72 | 73 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 74 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! ImageCollectionViewCell 75 | cell.imageView.image = images[indexPath.row] 76 | return cell 77 | } 78 | } 79 | 80 | extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { 81 | func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { 82 | // Local variable inserted by Swift 4.2 migrator. 83 | let info = convertFromUIImagePickerControllerInfoKeyDictionary(info) 84 | 85 | self.images = [] 86 | self.collectionView.reloadData() 87 | 88 | let chosenImage = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.originalImage)] as! UIImage 89 | imageView.image = chosenImage 90 | picker.dismiss(animated: true, completion: nil) 91 | cropFaces() 92 | } 93 | } 94 | 95 | // Helper function inserted by Swift 4.2 migrator. 96 | fileprivate func convertFromUIImagePickerControllerInfoKeyDictionary(_ input: [UIImagePickerController.InfoKey: Any]) -> [String: Any] { 97 | return Dictionary(uniqueKeysWithValues: input.map {key, value in (key.rawValue, value)}) 98 | } 99 | 100 | // Helper function inserted by Swift 4.2 migrator. 101 | fileprivate func convertFromUIImagePickerControllerInfoKey(_ input: UIImagePickerController.InfoKey) -> String { 102 | return input.rawValue 103 | } 104 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | use_frameworks! 2 | 3 | target 'ImageDetect_Example' do 4 | pod 'ImageDetect', :path => '../' 5 | # pod 'ImageDetect', :git => 'https://github.com/Feghal/ImageDetect.git' 6 | # pod 'ImageDetect' 7 | end 8 | -------------------------------------------------------------------------------- /Example/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - ImageDetect (1.1.4) 3 | 4 | DEPENDENCIES: 5 | - ImageDetect (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | ImageDetect: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | ImageDetect: cff4ef43d8cb22cb5bfdd3134f4224f637c3d372 13 | 14 | PODFILE CHECKSUM: dc7e4c2540a30f5fbd1721d7c39a8dca9da76b86 15 | 16 | COCOAPODS: 1.6.1 17 | -------------------------------------------------------------------------------- /ImageDetect.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint ImageDetect.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'ImageDetect' 11 | s.version = '1.1.4' 12 | s.summary = 'With ImageDetect you can easily detect and crop faces, texts or barcodes in your image.' 13 | 14 | s.description = <<-DESC 15 | ImageDetect is a library developed on Swift. With ImageDetect you can easily detect and crop faces, texts or barcodes in your image with iOS 11 Vision api. 16 | DESC 17 | 18 | s.homepage = 'https://github.com/Feghal/ImageDetect' 19 | s.summary = 'Crop faces, inside of your image, with Vision Api' 20 | s.license = { :type => 'MIT', :file => 'LICENSE' } 21 | s.author = { 'Arthur Sahakyan' => 'feghaldev@gmail.com' } 22 | s.source = { :git => 'https://github.com/Feghal/ImageDetect.git', :tag => s.version.to_s } 23 | 24 | s.source_files = 'ImageDetect/Classes/**/*' 25 | 26 | s.ios.deployment_target = '11.0' 27 | s.frameworks = 'UIKit', 'Vision' 28 | end 29 | -------------------------------------------------------------------------------- /ImageDetect/Classes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Feghal/ImageDetect/69cfb343f072c87b2463466f3e55875820c19bd1/ImageDetect/Classes/.gitkeep -------------------------------------------------------------------------------- /ImageDetect/Classes/ImageDetect.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ImageDetect.swift 3 | // ImageDetect 4 | // 5 | // Created by Arthur Sahakyan on 3/17/18. 6 | // 7 | 8 | import UIKit 9 | import Vision 10 | 11 | extension NSObject: ImageCroppable {} 12 | extension CGImage: ImageCroppable {} 13 | public protocol ImageCroppable {} 14 | 15 | /** 16 | This enumeration is for identification of detection type 17 | 18 | - face: for cropping faces 19 | - barcode: for croping barcodes 20 | - text: for cropping text rectangles 21 | */ 22 | public enum DetectionType { 23 | case face 24 | case barcode 25 | case text 26 | } 27 | 28 | /** 29 | This enumeration is for identification of request type 30 | 31 | - success: successfuly cropted objects 32 | - notFound: not found some object of `DetectionType` in image 33 | - failure: failed with error 34 | */ 35 | public enum ImageDetectResult { 36 | case success([T]) 37 | case notFound 38 | case failure(Error) 39 | } 40 | 41 | public struct ImageDetect { 42 | let detectable: T 43 | init(_ detectable: T) { 44 | self.detectable = detectable 45 | } 46 | } 47 | 48 | public extension ImageCroppable { 49 | var detector: ImageDetect { 50 | return ImageDetect(self) 51 | } 52 | } 53 | 54 | public extension ImageDetect where T: CGImage { 55 | 56 | /** 57 | To crop object in image 58 | - parameter type: type of object that must be croped 59 | - parameter completion: callbeck with `ImageDetectResult` with error or success response 60 | */ 61 | func crop(type: DetectionType, completion: @escaping (ImageDetectResult) -> Void) { 62 | switch type { 63 | case .face: 64 | cropFace(completion) 65 | case .barcode: 66 | cropBarcode(completion) 67 | case .text: 68 | cropText(completion) 69 | break 70 | } 71 | } 72 | 73 | private func cropFace(_ completion: @escaping (ImageDetectResult) -> Void) { 74 | guard #available(iOS 11.0, *) else { 75 | return 76 | } 77 | let req = VNDetectFaceRectanglesRequest { request, error in 78 | guard error == nil else { 79 | completion(.failure(error!)) 80 | return 81 | } 82 | 83 | let faceImages = request.results?.map({ result -> CGImage? in 84 | guard let face = result as? VNFaceObservation else { return nil } 85 | let faceImage = self.cropImage(object: face) 86 | return faceImage 87 | }).compactMap { $0 } 88 | 89 | guard let result = faceImages, result.count > 0 else { 90 | completion(.notFound) 91 | return 92 | } 93 | 94 | completion(.success(result)) 95 | } 96 | 97 | do { 98 | try VNImageRequestHandler(cgImage: self.detectable, options: [:]).perform([req]) 99 | } catch let error { 100 | completion(.failure(error)) 101 | } 102 | } 103 | 104 | private func cropBarcode(_ completion: @escaping (ImageDetectResult) -> Void) { 105 | guard #available(iOS 11.0, *) else { 106 | return 107 | } 108 | 109 | let req = VNDetectBarcodesRequest { request, error in 110 | guard error == nil else { 111 | completion(.failure(error!)) 112 | return 113 | } 114 | 115 | let codeImages = request.results?.map({ result -> CGImage? in 116 | guard let code = result as? VNBarcodeObservation else { return nil } 117 | let codeImage = self.cropImage(object: code) 118 | return codeImage 119 | }).compactMap { $0 } 120 | 121 | guard let result = codeImages, result.count > 0 else { 122 | completion(.notFound) 123 | return 124 | } 125 | 126 | completion(.success(result)) 127 | } 128 | 129 | do { 130 | try VNImageRequestHandler(cgImage: self.detectable, options: [:]).perform([req]) 131 | } catch let error { 132 | completion(.failure(error)) 133 | } 134 | } 135 | 136 | private func cropText(_ completion: @escaping (ImageDetectResult) -> Void) { 137 | guard #available(iOS 11.0, *) else { 138 | return 139 | } 140 | 141 | let req = VNDetectTextRectanglesRequest { request, error in 142 | guard error == nil else { 143 | completion(.failure(error!)) 144 | return 145 | } 146 | 147 | let textImages = request.results?.map({ result -> CGImage? in 148 | guard let text = result as? VNTextObservation else { return nil } 149 | let textImage = self.cropImage(object: text) 150 | return textImage 151 | }).compactMap { $0 } 152 | 153 | guard let result = textImages, result.count > 0 else { 154 | completion(.notFound) 155 | return 156 | } 157 | 158 | completion(.success(result)) 159 | } 160 | 161 | do { 162 | try VNImageRequestHandler(cgImage: self.detectable, options: [:]).perform([req]) 163 | } catch let error { 164 | completion(.failure(error)) 165 | } 166 | } 167 | 168 | private func cropImage(object: VNDetectedObjectObservation) -> CGImage? { 169 | let width = object.boundingBox.width * CGFloat(self.detectable.width) 170 | let height = object.boundingBox.height * CGFloat(self.detectable.height) 171 | let x = object.boundingBox.origin.x * CGFloat(self.detectable.width) 172 | let y = (1 - object.boundingBox.origin.y) * CGFloat(self.detectable.height) - height 173 | 174 | let croppingRect = CGRect(x: x, y: y, width: width, height: height) 175 | let image = self.detectable.cropping(to: croppingRect) 176 | return image 177 | } 178 | } 179 | 180 | public extension ImageDetect where T: UIImage { 181 | 182 | func crop(type: DetectionType, completion: @escaping (ImageDetectResult) -> Void) { 183 | guard #available(iOS 11.0, *) else { 184 | return 185 | } 186 | 187 | self.detectable.cgImage!.detector.crop(type: type) { result in 188 | switch result { 189 | case .success(let cgImages): 190 | let faces = cgImages.map { cgImage -> UIImage in 191 | return UIImage(cgImage: cgImage) 192 | } 193 | completion(.success(faces)) 194 | case .notFound: 195 | completion(.notFound) 196 | case .failure(let error): 197 | completion(.failure(error)) 198 | } 199 | } 200 | 201 | } 202 | 203 | } 204 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Arthur Sahakyan 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ImageDetect 2 | [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 3 | [![Version](https://img.shields.io/cocoapods/v/ImageDetect.svg?style=flat)](http://cocoapods.org/pods/ImageDetect) 4 | [![License](https://img.shields.io/cocoapods/l/ImageDetect.svg?style=flat)](http://cocoapods.org/pods/ImageDetect) 5 | [![Platform](https://img.shields.io/cocoapods/p/ImageDetect.svg?style=flat)](http://cocoapods.org/pods/ImageDetect) 6 | 7 | ImageDetect is a library developed on Swift. With ImageDetect you can easily detect and crop faces, texts or barcodes in your image with iOS 11 Vision api. It will automatically create new images containing each object found within a given image. 8 | 9 | ## Example 10 |
11 | 12 | 13 |
14 | 15 | To run the example project, clone the repo, and run `pod install` from the Example directory first. 16 | 17 | ## Requirements 18 | 1) Xcode 9.0 (beta) or higher. 19 | 2) iOS 11.0 (beta) or higher. 20 | 21 | ## Installation 22 | 23 | ### CocoaPods 24 | 25 | ImageDetect is available through [CocoaPods](http://cocoapods.org). To install 26 | it, simply add the following line to your Podfile: 27 | 28 | ```ruby 29 | pod 'ImageDetect' 30 | ``` 31 | Then, run the following command: 32 | ```ruby 33 | pod install 34 | ``` 35 | ### Manually 36 | 37 | 1. Drag and Drop it into your project 38 | 39 | 2. Import `ImageDetect` 40 | 41 | 3. You are ready to go! 42 | 43 | ## Usage 44 | Crop your (UIImage or CGImage) 45 | ```Swift 46 | 47 | // `type` in this method can be face, barcode or text 48 | image.detector.crop(type: .face) { [weak self] result in 49 | switch result { 50 | case .success(let croppedImages): 51 | // When the `Vision` successfully find type of object you set and successfuly crops it. 52 | print("Found") 53 | case .notFound: 54 | // When the image doesn't contain any type of object you did set, `result` will be `.notFound`. 55 | print("Not Found") 56 | case .failure(let error): 57 | // When the any error occured, `result` will be `failure`. 58 | print(error.localizedDescription) 59 | } 60 | } 61 | ``` 62 | 63 | ## Author 64 | 65 | Arthur Sahakyan, feghaldev@gmail.com 66 | 67 | ## License 68 | 69 | ImageDetect is available under the MIT license. See the LICENSE file for more info. 70 | -------------------------------------------------------------------------------- /Screenshots/1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Feghal/ImageDetect/69cfb343f072c87b2463466f3e55875820c19bd1/Screenshots/1.PNG -------------------------------------------------------------------------------- /Screenshots/2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Feghal/ImageDetect/69cfb343f072c87b2463466f3e55875820c19bd1/Screenshots/2.PNG -------------------------------------------------------------------------------- /_Pods.xcodeproj: -------------------------------------------------------------------------------- 1 | Example/Pods/Pods.xcodeproj -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate --------------------------------------------------------------------------------