├── .gitignore ├── DetectorAppSwiftUI.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── David.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── DetectorAppSwiftUI ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── Detector.swift ├── ObjectDetectorSwiftUIApp.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json ├── ViewController.swift └── YOLOv3TinyInt8LUT.mlmodel ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | 52 | .DS_Store 53 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6302C29C289FBCAC00D61B61 /* ObjectDetectorSwiftUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6302C29B289FBCAC00D61B61 /* ObjectDetectorSwiftUIApp.swift */; }; 11 | 6302C29E289FBCAC00D61B61 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6302C29D289FBCAC00D61B61 /* ContentView.swift */; }; 12 | 6302C2A0289FBCAD00D61B61 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6302C29F289FBCAD00D61B61 /* Assets.xcassets */; }; 13 | 6302C2A3289FBCAD00D61B61 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6302C2A2289FBCAD00D61B61 /* Preview Assets.xcassets */; }; 14 | 6302C2AA289FBF5F00D61B61 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6302C2A9289FBF5F00D61B61 /* ViewController.swift */; }; 15 | 63E9CD6728AACF1D00FD0BAA /* Detector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E9CD6628AACF1D00FD0BAA /* Detector.swift */; }; 16 | 63E9CD6928AACFB000FD0BAA /* YOLOv3TinyInt8LUT.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = 63E9CD6828AACFB000FD0BAA /* YOLOv3TinyInt8LUT.mlmodel */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 6302C298289FBCAC00D61B61 /* DetectorAppSwiftUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DetectorAppSwiftUI.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 6302C29B289FBCAC00D61B61 /* ObjectDetectorSwiftUIApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectDetectorSwiftUIApp.swift; sourceTree = ""; }; 22 | 6302C29D289FBCAC00D61B61 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 23 | 6302C29F289FBCAD00D61B61 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 6302C2A2289FBCAD00D61B61 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 25 | 6302C2A9289FBF5F00D61B61 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 26 | 63E9CD6628AACF1D00FD0BAA /* Detector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Detector.swift; sourceTree = ""; }; 27 | 63E9CD6828AACFB000FD0BAA /* YOLOv3TinyInt8LUT.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = YOLOv3TinyInt8LUT.mlmodel; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | 6302C295289FBCAC00D61B61 /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | 6302C28F289FBCAC00D61B61 = { 42 | isa = PBXGroup; 43 | children = ( 44 | 6302C29A289FBCAC00D61B61 /* DetectorAppSwiftUI */, 45 | 6302C299289FBCAC00D61B61 /* Products */, 46 | ); 47 | sourceTree = ""; 48 | }; 49 | 6302C299289FBCAC00D61B61 /* Products */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | 6302C298289FBCAC00D61B61 /* DetectorAppSwiftUI.app */, 53 | ); 54 | name = Products; 55 | sourceTree = ""; 56 | }; 57 | 6302C29A289FBCAC00D61B61 /* DetectorAppSwiftUI */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 6302C29B289FBCAC00D61B61 /* ObjectDetectorSwiftUIApp.swift */, 61 | 6302C29D289FBCAC00D61B61 /* ContentView.swift */, 62 | 6302C2A9289FBF5F00D61B61 /* ViewController.swift */, 63 | 63E9CD6628AACF1D00FD0BAA /* Detector.swift */, 64 | 63E9CD6828AACFB000FD0BAA /* YOLOv3TinyInt8LUT.mlmodel */, 65 | 6302C29F289FBCAD00D61B61 /* Assets.xcassets */, 66 | 6302C2A1289FBCAD00D61B61 /* Preview Content */, 67 | ); 68 | path = DetectorAppSwiftUI; 69 | sourceTree = ""; 70 | }; 71 | 6302C2A1289FBCAD00D61B61 /* Preview Content */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 6302C2A2289FBCAD00D61B61 /* Preview Assets.xcassets */, 75 | ); 76 | path = "Preview Content"; 77 | sourceTree = ""; 78 | }; 79 | /* End PBXGroup section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | 6302C297289FBCAC00D61B61 /* DetectorAppSwiftUI */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = 6302C2A6289FBCAD00D61B61 /* Build configuration list for PBXNativeTarget "DetectorAppSwiftUI" */; 85 | buildPhases = ( 86 | 6302C294289FBCAC00D61B61 /* Sources */, 87 | 6302C295289FBCAC00D61B61 /* Frameworks */, 88 | 6302C296289FBCAC00D61B61 /* Resources */, 89 | ); 90 | buildRules = ( 91 | ); 92 | dependencies = ( 93 | ); 94 | name = DetectorAppSwiftUI; 95 | productName = ObjectDetectorSwiftUI; 96 | productReference = 6302C298289FBCAC00D61B61 /* DetectorAppSwiftUI.app */; 97 | productType = "com.apple.product-type.application"; 98 | }; 99 | /* End PBXNativeTarget section */ 100 | 101 | /* Begin PBXProject section */ 102 | 6302C290289FBCAC00D61B61 /* Project object */ = { 103 | isa = PBXProject; 104 | attributes = { 105 | BuildIndependentTargetsInParallel = 1; 106 | LastSwiftUpdateCheck = 1340; 107 | LastUpgradeCheck = 1340; 108 | TargetAttributes = { 109 | 6302C297289FBCAC00D61B61 = { 110 | CreatedOnToolsVersion = 13.4.1; 111 | }; 112 | }; 113 | }; 114 | buildConfigurationList = 6302C293289FBCAC00D61B61 /* Build configuration list for PBXProject "DetectorAppSwiftUI" */; 115 | compatibilityVersion = "Xcode 13.0"; 116 | developmentRegion = en; 117 | hasScannedForEncodings = 0; 118 | knownRegions = ( 119 | en, 120 | Base, 121 | ); 122 | mainGroup = 6302C28F289FBCAC00D61B61; 123 | productRefGroup = 6302C299289FBCAC00D61B61 /* Products */; 124 | projectDirPath = ""; 125 | projectRoot = ""; 126 | targets = ( 127 | 6302C297289FBCAC00D61B61 /* DetectorAppSwiftUI */, 128 | ); 129 | }; 130 | /* End PBXProject section */ 131 | 132 | /* Begin PBXResourcesBuildPhase section */ 133 | 6302C296289FBCAC00D61B61 /* Resources */ = { 134 | isa = PBXResourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | 6302C2A3289FBCAD00D61B61 /* Preview Assets.xcassets in Resources */, 138 | 6302C2A0289FBCAD00D61B61 /* Assets.xcassets in Resources */, 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXResourcesBuildPhase section */ 143 | 144 | /* Begin PBXSourcesBuildPhase section */ 145 | 6302C294289FBCAC00D61B61 /* Sources */ = { 146 | isa = PBXSourcesBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | 6302C2AA289FBF5F00D61B61 /* ViewController.swift in Sources */, 150 | 63E9CD6928AACFB000FD0BAA /* YOLOv3TinyInt8LUT.mlmodel in Sources */, 151 | 6302C29E289FBCAC00D61B61 /* ContentView.swift in Sources */, 152 | 6302C29C289FBCAC00D61B61 /* ObjectDetectorSwiftUIApp.swift in Sources */, 153 | 63E9CD6728AACF1D00FD0BAA /* Detector.swift in Sources */, 154 | ); 155 | runOnlyForDeploymentPostprocessing = 0; 156 | }; 157 | /* End PBXSourcesBuildPhase section */ 158 | 159 | /* Begin XCBuildConfiguration section */ 160 | 6302C2A4289FBCAD00D61B61 /* Debug */ = { 161 | isa = XCBuildConfiguration; 162 | buildSettings = { 163 | ALWAYS_SEARCH_USER_PATHS = NO; 164 | CLANG_ANALYZER_NONNULL = YES; 165 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 166 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 167 | CLANG_ENABLE_MODULES = YES; 168 | CLANG_ENABLE_OBJC_ARC = YES; 169 | CLANG_ENABLE_OBJC_WEAK = YES; 170 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 171 | CLANG_WARN_BOOL_CONVERSION = YES; 172 | CLANG_WARN_COMMA = YES; 173 | CLANG_WARN_CONSTANT_CONVERSION = YES; 174 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 175 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 176 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 177 | CLANG_WARN_EMPTY_BODY = YES; 178 | CLANG_WARN_ENUM_CONVERSION = YES; 179 | CLANG_WARN_INFINITE_RECURSION = YES; 180 | CLANG_WARN_INT_CONVERSION = YES; 181 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 182 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 183 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 184 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 185 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 186 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 187 | CLANG_WARN_STRICT_PROTOTYPES = YES; 188 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 189 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 190 | CLANG_WARN_UNREACHABLE_CODE = YES; 191 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 192 | COPY_PHASE_STRIP = NO; 193 | DEBUG_INFORMATION_FORMAT = dwarf; 194 | ENABLE_STRICT_OBJC_MSGSEND = YES; 195 | ENABLE_TESTABILITY = YES; 196 | GCC_C_LANGUAGE_STANDARD = gnu11; 197 | GCC_DYNAMIC_NO_PIC = NO; 198 | GCC_NO_COMMON_BLOCKS = YES; 199 | GCC_OPTIMIZATION_LEVEL = 0; 200 | GCC_PREPROCESSOR_DEFINITIONS = ( 201 | "DEBUG=1", 202 | "$(inherited)", 203 | ); 204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 205 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 206 | GCC_WARN_UNDECLARED_SELECTOR = YES; 207 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 208 | GCC_WARN_UNUSED_FUNCTION = YES; 209 | GCC_WARN_UNUSED_VARIABLE = YES; 210 | IPHONEOS_DEPLOYMENT_TARGET = 15.5; 211 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 212 | MTL_FAST_MATH = YES; 213 | ONLY_ACTIVE_ARCH = YES; 214 | SDKROOT = iphoneos; 215 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 216 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 217 | }; 218 | name = Debug; 219 | }; 220 | 6302C2A5289FBCAD00D61B61 /* Release */ = { 221 | isa = XCBuildConfiguration; 222 | buildSettings = { 223 | ALWAYS_SEARCH_USER_PATHS = NO; 224 | CLANG_ANALYZER_NONNULL = YES; 225 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 226 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 227 | CLANG_ENABLE_MODULES = YES; 228 | CLANG_ENABLE_OBJC_ARC = YES; 229 | CLANG_ENABLE_OBJC_WEAK = YES; 230 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 231 | CLANG_WARN_BOOL_CONVERSION = YES; 232 | CLANG_WARN_COMMA = YES; 233 | CLANG_WARN_CONSTANT_CONVERSION = YES; 234 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_NON_LITERAL_NULL_CONVERSION = YES; 242 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 243 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 244 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 245 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 246 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 247 | CLANG_WARN_STRICT_PROTOTYPES = YES; 248 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 249 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 250 | CLANG_WARN_UNREACHABLE_CODE = YES; 251 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 252 | COPY_PHASE_STRIP = NO; 253 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 254 | ENABLE_NS_ASSERTIONS = NO; 255 | ENABLE_STRICT_OBJC_MSGSEND = YES; 256 | GCC_C_LANGUAGE_STANDARD = gnu11; 257 | GCC_NO_COMMON_BLOCKS = YES; 258 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 259 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 260 | GCC_WARN_UNDECLARED_SELECTOR = YES; 261 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 262 | GCC_WARN_UNUSED_FUNCTION = YES; 263 | GCC_WARN_UNUSED_VARIABLE = YES; 264 | IPHONEOS_DEPLOYMENT_TARGET = 15.5; 265 | MTL_ENABLE_DEBUG_INFO = NO; 266 | MTL_FAST_MATH = YES; 267 | SDKROOT = iphoneos; 268 | SWIFT_COMPILATION_MODE = wholemodule; 269 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 270 | VALIDATE_PRODUCT = YES; 271 | }; 272 | name = Release; 273 | }; 274 | 6302C2A7289FBCAD00D61B61 /* Debug */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 278 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 279 | CODE_SIGN_STYLE = Automatic; 280 | CURRENT_PROJECT_VERSION = 1; 281 | DEVELOPMENT_ASSET_PATHS = "\"DetectorAppSwiftUI/Preview Content\""; 282 | DEVELOPMENT_TEAM = ""; 283 | ENABLE_PREVIEWS = YES; 284 | GENERATE_INFOPLIST_FILE = YES; 285 | INFOPLIST_KEY_NSCameraUsageDescription = "App uses camera to detect objects."; 286 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 287 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 288 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 289 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 290 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 291 | LD_RUNPATH_SEARCH_PATHS = ( 292 | "$(inherited)", 293 | "@executable_path/Frameworks", 294 | ); 295 | MARKETING_VERSION = 1.0; 296 | PRODUCT_NAME = DetectorAppSwiftUI; 297 | SWIFT_EMIT_LOC_STRINGS = YES; 298 | SWIFT_VERSION = 5.0; 299 | TARGETED_DEVICE_FAMILY = "1,2"; 300 | }; 301 | name = Debug; 302 | }; 303 | 6302C2A8289FBCAD00D61B61 /* Release */ = { 304 | isa = XCBuildConfiguration; 305 | buildSettings = { 306 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 307 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 308 | CODE_SIGN_STYLE = Automatic; 309 | CURRENT_PROJECT_VERSION = 1; 310 | DEVELOPMENT_ASSET_PATHS = "\"DetectorAppSwiftUI/Preview Content\""; 311 | DEVELOPMENT_TEAM = ""; 312 | ENABLE_PREVIEWS = YES; 313 | GENERATE_INFOPLIST_FILE = YES; 314 | INFOPLIST_KEY_NSCameraUsageDescription = "App uses camera to detect objects."; 315 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 316 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 317 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 318 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 319 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 320 | LD_RUNPATH_SEARCH_PATHS = ( 321 | "$(inherited)", 322 | "@executable_path/Frameworks", 323 | ); 324 | MARKETING_VERSION = 1.0; 325 | PRODUCT_NAME = DetectorAppSwiftUI; 326 | SWIFT_EMIT_LOC_STRINGS = YES; 327 | SWIFT_VERSION = 5.0; 328 | TARGETED_DEVICE_FAMILY = "1,2"; 329 | }; 330 | name = Release; 331 | }; 332 | /* End XCBuildConfiguration section */ 333 | 334 | /* Begin XCConfigurationList section */ 335 | 6302C293289FBCAC00D61B61 /* Build configuration list for PBXProject "DetectorAppSwiftUI" */ = { 336 | isa = XCConfigurationList; 337 | buildConfigurations = ( 338 | 6302C2A4289FBCAD00D61B61 /* Debug */, 339 | 6302C2A5289FBCAD00D61B61 /* Release */, 340 | ); 341 | defaultConfigurationIsVisible = 0; 342 | defaultConfigurationName = Release; 343 | }; 344 | 6302C2A6289FBCAD00D61B61 /* Build configuration list for PBXNativeTarget "DetectorAppSwiftUI" */ = { 345 | isa = XCConfigurationList; 346 | buildConfigurations = ( 347 | 6302C2A7289FBCAD00D61B61 /* Debug */, 348 | 6302C2A8289FBCAD00D61B61 /* Release */, 349 | ); 350 | defaultConfigurationIsVisible = 0; 351 | defaultConfigurationName = Release; 352 | }; 353 | /* End XCConfigurationList section */ 354 | }; 355 | rootObject = 6302C290289FBCAC00D61B61 /* Project object */; 356 | } 357 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI.xcodeproj/xcuserdata/David.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DetectorAppSwiftUI.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | ObjectDetectorSwiftUI.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "2x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "83.5x83.5" 82 | }, 83 | { 84 | "idiom" : "ios-marketing", 85 | "scale" : "1x", 86 | "size" : "1024x1024" 87 | } 88 | ], 89 | "info" : { 90 | "author" : "xcode", 91 | "version" : 1 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/ContentView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct ContentView: View { 4 | var body: some View { 5 | HostedViewController() 6 | .ignoresSafeArea() 7 | } 8 | } 9 | 10 | struct ContentView_Previews: PreviewProvider { 11 | static var previews: some View { 12 | ContentView() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/Detector.swift: -------------------------------------------------------------------------------- 1 | import Vision 2 | import AVFoundation 3 | import UIKit 4 | 5 | extension ViewController { 6 | 7 | func setupDetector() { 8 | let modelURL = Bundle.main.url(forResource: "YOLOv3TinyInt8LUT", withExtension: "mlmodelc") 9 | 10 | do { 11 | let visionModel = try VNCoreMLModel(for: MLModel(contentsOf: modelURL!)) 12 | let recognitions = VNCoreMLRequest(model: visionModel, completionHandler: detectionDidComplete) 13 | self.requests = [recognitions] 14 | } catch let error { 15 | print(error) 16 | } 17 | } 18 | 19 | func detectionDidComplete(request: VNRequest, error: Error?) { 20 | DispatchQueue.main.async(execute: { 21 | if let results = request.results { 22 | self.extractDetections(results) 23 | } 24 | }) 25 | } 26 | 27 | func extractDetections(_ results: [VNObservation]) { 28 | detectionLayer.sublayers = nil 29 | 30 | for observation in results where observation is VNRecognizedObjectObservation { 31 | guard let objectObservation = observation as? VNRecognizedObjectObservation else { continue } 32 | 33 | // Transformations 34 | let objectBounds = VNImageRectForNormalizedRect(objectObservation.boundingBox, Int(screenRect.size.width), Int(screenRect.size.height)) 35 | let transformedBounds = CGRect(x: objectBounds.minX, y: screenRect.size.height - objectBounds.maxY, width: objectBounds.maxX - objectBounds.minX, height: objectBounds.maxY - objectBounds.minY) 36 | 37 | let boxLayer = self.drawBoundingBox(transformedBounds) 38 | 39 | detectionLayer.addSublayer(boxLayer) 40 | } 41 | } 42 | 43 | func setupLayers() { 44 | detectionLayer = CALayer() 45 | detectionLayer.frame = CGRect(x: 0, y: 0, width: screenRect.size.width, height: screenRect.size.height) 46 | DispatchQueue.main.async { [weak self] in 47 | self!.view.layer.addSublayer(self!.detectionLayer) 48 | } 49 | } 50 | 51 | func updateLayers() { 52 | detectionLayer?.frame = CGRect(x: 0, y: 0, width: screenRect.size.width, height: screenRect.size.height) 53 | } 54 | 55 | func drawBoundingBox(_ bounds: CGRect) -> CALayer { 56 | let boxLayer = CALayer() 57 | boxLayer.frame = bounds 58 | boxLayer.borderWidth = 3.0 59 | boxLayer.borderColor = CGColor.init(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0) 60 | boxLayer.cornerRadius = 4 61 | return boxLayer 62 | } 63 | 64 | func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { 65 | guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } 66 | let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: .up, options: [:]) // Create handler to perform request on the buffer 67 | 68 | do { 69 | try imageRequestHandler.perform(self.requests) // Schedules vision requests to be performed 70 | } catch { 71 | print(error) 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/ObjectDetectorSwiftUIApp.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @main 4 | struct ObjectDetectorSwiftUIApp: App { 5 | var body: some Scene { 6 | WindowGroup { 7 | ContentView() 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/ViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import SwiftUI 3 | import AVFoundation 4 | import Vision 5 | 6 | 7 | class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate { 8 | private var permissionGranted = false // Flag for permission 9 | private let captureSession = AVCaptureSession() 10 | private let sessionQueue = DispatchQueue(label: "sessionQueue") 11 | private var previewLayer = AVCaptureVideoPreviewLayer() 12 | var screenRect: CGRect! = nil // For view dimensions 13 | 14 | // Detector 15 | private var videoOutput = AVCaptureVideoDataOutput() 16 | var requests = [VNRequest]() 17 | var detectionLayer: CALayer! = nil 18 | 19 | 20 | override func viewDidLoad() { 21 | checkPermission() 22 | 23 | sessionQueue.async { [unowned self] in 24 | guard permissionGranted else { return } 25 | self.setupCaptureSession() 26 | 27 | self.setupLayers() 28 | self.setupDetector() 29 | 30 | self.captureSession.startRunning() 31 | } 32 | } 33 | 34 | override func viewDidAppear(_ animated: Bool) { 35 | // Reset layers when view reappears 36 | self.setupLayers() 37 | } 38 | 39 | override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { 40 | screenRect = UIScreen.main.bounds 41 | self.previewLayer.frame = CGRect(x: 0, y: 0, width: screenRect.size.width, height: screenRect.size.height) 42 | 43 | switch UIDevice.current.orientation { 44 | // Home button on top 45 | case UIDeviceOrientation.portraitUpsideDown: 46 | self.previewLayer.connection?.videoOrientation = .portraitUpsideDown 47 | 48 | // Home button on right 49 | case UIDeviceOrientation.landscapeLeft: 50 | self.previewLayer.connection?.videoOrientation = .landscapeRight 51 | 52 | // Home button on left 53 | case UIDeviceOrientation.landscapeRight: 54 | self.previewLayer.connection?.videoOrientation = .landscapeLeft 55 | 56 | // Home button at bottom 57 | case UIDeviceOrientation.portrait: 58 | self.previewLayer.connection?.videoOrientation = .portrait 59 | 60 | default: 61 | break 62 | } 63 | 64 | // Detector 65 | updateLayers() 66 | } 67 | 68 | func checkPermission() { 69 | switch AVCaptureDevice.authorizationStatus(for: .video) { 70 | // Permission has been granted before 71 | case .authorized: 72 | permissionGranted = true 73 | 74 | // Permission has not been requested yet 75 | case .notDetermined: 76 | requestPermission() 77 | 78 | default: 79 | permissionGranted = false 80 | } 81 | } 82 | 83 | func requestPermission() { 84 | sessionQueue.suspend() 85 | AVCaptureDevice.requestAccess(for: .video) { [unowned self] granted in 86 | self.permissionGranted = granted 87 | self.sessionQueue.resume() 88 | } 89 | } 90 | 91 | func setupCaptureSession() { 92 | // Camera input 93 | guard let videoDevice = AVCaptureDevice.default(.builtInDualWideCamera,for: .video, position: .back) else { return } 94 | guard let videoDeviceInput = try? AVCaptureDeviceInput(device: videoDevice) else { return } 95 | 96 | guard captureSession.canAddInput(videoDeviceInput) else { return } 97 | captureSession.addInput(videoDeviceInput) 98 | 99 | // Preview layer 100 | screenRect = UIScreen.main.bounds 101 | 102 | previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) 103 | previewLayer.frame = CGRect(x: 0, y: 0, width: screenRect.size.width, height: screenRect.size.height) 104 | previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill // Fill screen 105 | previewLayer.connection?.videoOrientation = .portrait 106 | 107 | // Detector 108 | videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "sampleBufferQueue")) 109 | captureSession.addOutput(videoOutput) 110 | 111 | videoOutput.connection(with: .video)?.videoOrientation = .portrait 112 | 113 | // Updates to UI must be on main queue 114 | DispatchQueue.main.async { [weak self] in 115 | self!.view.layer.addSublayer(self!.previewLayer) 116 | } 117 | } 118 | } 119 | 120 | struct HostedViewController: UIViewControllerRepresentable { 121 | func makeUIViewController(context: Context) -> UIViewController { 122 | return ViewController() 123 | } 124 | 125 | func updateUIViewController(_ uiViewController: UIViewController, context: Context) { 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /DetectorAppSwiftUI/YOLOv3TinyInt8LUT.mlmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daved01/DetectorAppSwiftUI/00cdf4540f644332d4a687ce3e94c37c4ce30f55/DetectorAppSwiftUI/YOLOv3TinyInt8LUT.mlmodel -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 David Kirchhoff 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DetectorAppSwiftUI 2 | **Please note:** This repo is no longer actively maintained. 3 | 4 | Code for the two tutorials on how to make an object detection app with a SwiftUI-based interface. 5 | Both tutorials exist as posts and videos. 6 | 7 | ## Part 1 8 | PreviewLayer which presents a live camera feed. [Post](https://www.neuralception.com/detection-app-tutorial-camera-feed/) | [video](https://www.youtube.com/watch?v=R2STbo53_vc). 9 | The code is in the tag `previewLayer`. 10 | 11 | ## Part 2 12 | Adding an object detection model. [Post](https://www.neuralception.com/detection-app-tutorial-detector/) | [video](). 13 | The code is in the tag `detector`. 14 | 15 | # Accessing tags 16 | Since the code for the detector in part 2 is based on the one for the previewLayer in part 1, you can access part 1 and 2 with tags. 17 | If you are not familiar with tags here's how to do it. 18 | 19 | In Github click on the branches tab and then select `Tags`. 20 | 21 | In git, first make sure you have all tags locally after you cloned this repository: 22 | 23 | ``` 24 | git fetch --all 25 | ``` 26 | 27 | Then, use 28 | 29 | ``` 30 | git checkout previewLayer 31 | ``` 32 | 33 | to see the code for part 1 for example. 34 | --------------------------------------------------------------------------------