Skip to content

Commit

Permalink
Merge pull request #218 from googlesamples/feature/refactor_ios_objc
Browse files Browse the repository at this point in the history
Refactored iOS Object Detection
  • Loading branch information
khanhlvg authored Aug 24, 2023
2 parents e4dd265 + e6cf223 commit 2948bbc
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@

/* Begin PBXBuildFile section */
39A04804C8101D2C0D58D927 /* libPods-ObjectDetectorTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BF80BB442A677B6C005E93B1 /* libPods-ObjectDetectorTests.a */; };
7F2ED5E52A97CEFD0044C53E /* coupleanddog.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = BFCF18232A41476D00D64FA6 /* coupleanddog.jpeg */; };
7F7641A62A74803D00DDCE4E /* download_models.sh in Resources */ = {isa = PBXBuildFile; fileRef = 7F7641A52A74803D00DDCE4E /* download_models.sh */; };
9E41A7603AB8BE3B86C06DB9 /* Pods_ObjectDetector.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3FBCABF9DABD56A270978F4 /* Pods_ObjectDetector.framework */; };
AAF981DB2A80D27500C7121A /* CameraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAF981DA2A80D27500C7121A /* CameraViewController.swift */; };
AAF981DD2A80D28B00C7121A /* MediaLibraryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAF981DC2A80D28B00C7121A /* MediaLibraryViewController.swift */; };
AAF981DF2A81330700C7121A /* DetectorMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAF981DE2A81330700C7121A /* DetectorMetadata.swift */; };
AAF981DF2A81330700C7121A /* InferenceConfigManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAF981DE2A81330700C7121A /* InferenceConfigManager.swift */; };
AAF981E52A85156500C7121A /* DefaultConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAF981E42A85156500C7121A /* DefaultConstants.swift */; };
BF2B2D2F2A3C09E200589A11 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D2E2A3C09E200589A11 /* AppDelegate.swift */; };
BF2B2D312A3C09E200589A11 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D302A3C09E200589A11 /* SceneDelegate.swift */; };
BF2B2D332A3C09E200589A11 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D322A3C09E200589A11 /* ViewController.swift */; };
BF2B2D332A3C09E200589A11 /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D322A3C09E200589A11 /* RootViewController.swift */; };
BF2B2D362A3C09E200589A11 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF2B2D342A3C09E200589A11 /* Main.storyboard */; };
BF2B2D382A3C09E300589A11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BF2B2D372A3C09E300589A11 /* Assets.xcassets */; };
BF2B2D3B2A3C09E300589A11 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF2B2D392A3C09E300589A11 /* LaunchScreen.storyboard */; };
BF2B2D462A3C09E300589A11 /* ObjectDetectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D452A3C09E300589A11 /* ObjectDetectorTests.swift */; };
BF2B2D642A3C0C2900589A11 /* CameraFeedService.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D602A3C0C2900589A11 /* CameraFeedService.swift */; };
BF2B2D6B2A3C0C3F00589A11 /* InferenceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D692A3C0C3F00589A11 /* InferenceViewController.swift */; };
BF2B2D6B2A3C0C3F00589A11 /* BottomSheetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D692A3C0C3F00589A11 /* BottomSheetViewController.swift */; };
BF2B2D6D2A3C0EF900589A11 /* ObjectDetectorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2B2D6C2A3C0EF900589A11 /* ObjectDetectorService.swift */; };
BFCF181A2A405D3600D64FA6 /* OverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFCF18192A405D3600D64FA6 /* OverlayView.swift */; };
BFCF18202A405F4300D64FA6 /* efficientdet_lite0.tflite in Resources */ = {isa = PBXBuildFile; fileRef = BFCF181E2A405F4300D64FA6 /* efficientdet_lite0.tflite */; };
BFCF18222A4066C900D64FA6 /* efficientdet_lite2.tflite in Resources */ = {isa = PBXBuildFile; fileRef = BFCF18212A40663700D64FA6 /* efficientdet_lite2.tflite */; };
BFCF18242A41476D00D64FA6 /* coupleanddog.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = BFCF18232A41476D00D64FA6 /* coupleanddog.jpeg */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -47,12 +46,11 @@
7F7641A52A74803D00DDCE4E /* download_models.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = download_models.sh; sourceTree = "<group>"; };
AAF981DA2A80D27500C7121A /* CameraViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraViewController.swift; sourceTree = "<group>"; };
AAF981DC2A80D28B00C7121A /* MediaLibraryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaLibraryViewController.swift; sourceTree = "<group>"; };
AAF981DE2A81330700C7121A /* DetectorMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetectorMetadata.swift; sourceTree = "<group>"; };
AAF981DE2A81330700C7121A /* InferenceConfigManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InferenceConfigManager.swift; sourceTree = "<group>"; };
AAF981E42A85156500C7121A /* DefaultConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultConstants.swift; sourceTree = "<group>"; };
BF2B2D2B2A3C09E200589A11 /* ObjectDetector.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ObjectDetector.app; sourceTree = BUILT_PRODUCTS_DIR; };
BF2B2D2E2A3C09E200589A11 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
BF2B2D302A3C09E200589A11 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
BF2B2D322A3C09E200589A11 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
BF2B2D322A3C09E200589A11 /* RootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewController.swift; sourceTree = "<group>"; };
BF2B2D352A3C09E200589A11 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
BF2B2D372A3C09E300589A11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
BF2B2D3A2A3C09E300589A11 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
Expand All @@ -62,7 +60,7 @@
BF2B2D4F2A3C09E300589A11 /* ObjectDetectorUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectDetectorUITests.swift; sourceTree = "<group>"; };
BF2B2D512A3C09E300589A11 /* ObjectDetectorUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectDetectorUITestsLaunchTests.swift; sourceTree = "<group>"; };
BF2B2D602A3C0C2900589A11 /* CameraFeedService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraFeedService.swift; sourceTree = "<group>"; };
BF2B2D692A3C0C3F00589A11 /* InferenceViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InferenceViewController.swift; sourceTree = "<group>"; };
BF2B2D692A3C0C3F00589A11 /* BottomSheetViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomSheetViewController.swift; sourceTree = "<group>"; };
BF2B2D6C2A3C0EF900589A11 /* ObjectDetectorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectDetectorService.swift; sourceTree = "<group>"; };
BF80BB442A677B6C005E93B1 /* libPods-ObjectDetectorTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = "libPods-ObjectDetectorTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
BF80BB462A677B7B005E93B1 /* MediaPipeTasksCommon.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MediaPipeTasksCommon.xcframework; path = Pods/MediaPipeTasksCommon/frameworks/MediaPipeTasksCommon.xcframework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,20 +140,13 @@
path = Services;
sourceTree = "<group>";
};
AA92E42A2A86A852005A7145 /* Constants */ = {
AA92E42A2A86A852005A7145 /* Configs */ = {
isa = PBXGroup;
children = (
AAF981E42A85156500C7121A /* DefaultConstants.swift */,
AAF981DE2A81330700C7121A /* InferenceConfigManager.swift */,
);
path = Constants;
sourceTree = "<group>";
};
AA92E42B2A86A89A005A7145 /* Metadata */ = {
isa = PBXGroup;
children = (
AAF981DE2A81330700C7121A /* DetectorMetadata.swift */,
);
path = Metadata;
path = Configs;
sourceTree = "<group>";
};
BF2B2D222A3C09E200589A11 = {
Expand All @@ -182,18 +173,15 @@
BF2B2D2D2A3C09E200589A11 /* ObjectDetector */ = {
isa = PBXGroup;
children = (
AA92E42B2A86A89A005A7145 /* Metadata */,
AA92E42A2A86A852005A7145 /* Constants */,
AA92E42A2A86A852005A7145 /* Configs */,
AA92E4292A86A822005A7145 /* Services */,
AA92E4272A86A7F2005A7145 /* Views */,
BF2B2D672A3C0C3F00589A11 /* ViewContollers */,
BF2B2D672A3C0C3F00589A11 /* ViewControllers */,
7F7641A42A74803D00DDCE4E /* RunScripts */,
BF2B2D2E2A3C09E200589A11 /* AppDelegate.swift */,
BF2B2D302A3C09E200589A11 /* SceneDelegate.swift */,
BF2B2D342A3C09E200589A11 /* Main.storyboard */,
BF2B2D372A3C09E300589A11 /* Assets.xcassets */,
BF2B2D392A3C09E300589A11 /* LaunchScreen.storyboard */,
BFCF18232A41476D00D64FA6 /* coupleanddog.jpeg */,
BF2B2D3C2A3C09E300589A11 /* Info.plist */,
BFCF181E2A405F4300D64FA6 /* efficientdet_lite0.tflite */,
BFCF18212A40663700D64FA6 /* efficientdet_lite2.tflite */,
Expand All @@ -204,6 +192,7 @@
BF2B2D442A3C09E300589A11 /* ObjectDetectorTests */ = {
isa = PBXGroup;
children = (
BFCF18232A41476D00D64FA6 /* coupleanddog.jpeg */,
BF2B2D452A3C09E300589A11 /* ObjectDetectorTests.swift */,
);
path = ObjectDetectorTests;
Expand All @@ -218,15 +207,15 @@
path = ObjectDetectorUITests;
sourceTree = "<group>";
};
BF2B2D672A3C0C3F00589A11 /* ViewContollers */ = {
BF2B2D672A3C0C3F00589A11 /* ViewControllers */ = {
isa = PBXGroup;
children = (
BF2B2D322A3C09E200589A11 /* ViewController.swift */,
BF2B2D692A3C0C3F00589A11 /* InferenceViewController.swift */,
BF2B2D322A3C09E200589A11 /* RootViewController.swift */,
BF2B2D692A3C0C3F00589A11 /* BottomSheetViewController.swift */,
AAF981DA2A80D27500C7121A /* CameraViewController.swift */,
AAF981DC2A80D28B00C7121A /* MediaLibraryViewController.swift */,
);
path = ViewContollers;
path = ViewControllers;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -317,7 +306,6 @@
BF2B2D3B2A3C09E300589A11 /* LaunchScreen.storyboard in Resources */,
BF2B2D382A3C09E300589A11 /* Assets.xcassets in Resources */,
BF2B2D362A3C09E200589A11 /* Main.storyboard in Resources */,
BFCF18242A41476D00D64FA6 /* coupleanddog.jpeg in Resources */,
7F7641A62A74803D00DDCE4E /* download_models.sh in Resources */,
BFCF18202A405F4300D64FA6 /* efficientdet_lite0.tflite in Resources */,
);
Expand All @@ -327,6 +315,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7F2ED5E52A97CEFD0044C53E /* coupleanddog.jpeg in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -357,6 +346,7 @@
};
7F7641A12A747F5D00DDCE4E /* Download models */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -403,15 +393,14 @@
buildActionMask = 2147483647;
files = (
BFCF181A2A405D3600D64FA6 /* OverlayView.swift in Sources */,
BF2B2D332A3C09E200589A11 /* ViewController.swift in Sources */,
BF2B2D332A3C09E200589A11 /* RootViewController.swift in Sources */,
AAF981E52A85156500C7121A /* DefaultConstants.swift in Sources */,
BF2B2D6B2A3C0C3F00589A11 /* InferenceViewController.swift in Sources */,
AAF981DF2A81330700C7121A /* DetectorMetadata.swift in Sources */,
BF2B2D6B2A3C0C3F00589A11 /* BottomSheetViewController.swift in Sources */,
AAF981DF2A81330700C7121A /* InferenceConfigManager.swift in Sources */,
BF2B2D642A3C0C2900589A11 /* CameraFeedService.swift in Sources */,
BF2B2D2F2A3C09E200589A11 /* AppDelegate.swift in Sources */,
BF2B2D6D2A3C0EF900589A11 /* ObjectDetectorService.swift in Sources */,
AAF981DD2A80D28B00C7121A /* MediaLibraryViewController.swift in Sources */,
BF2B2D312A3C09E200589A11 /* SceneDelegate.swift in Sources */,
AAF981DB2A80D27500C7121A /* CameraViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="l9g-3L-U89">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="UIMenu" message="Requires Xcode 11 or later." minToolsVersion="11.0" requiredIntegratedClassName="UICommandDiff"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Inference View Controller-->
<!--Bottom Sheet View Controller-->
<scene sceneID="nVP-CX-rj2">
<objects>
<viewController id="zgE-Xo-ZSc" customClass="InferenceViewController" customModule="ObjectDetector" sceneMemberID="viewController">
<viewController id="zgE-Xo-ZSc" customClass="BottomSheetViewController" customModule="ObjectDetector" sceneMemberID="viewController">
<view key="view" clipsSubviews="YES" contentMode="scaleToFill" id="Knd-PN-meG">
<rect key="frame" x="0.0" y="0.0" width="393" height="400"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -188,10 +187,10 @@
</objects>
<point key="canvasLocation" x="638.93129770992368" y="160.56338028169014"/>
</scene>
<!--View Controller-->
<!--Root View Controller-->
<scene sceneID="BN0-Ju-w5Z">
<objects>
<viewController id="l9g-3L-U89" customClass="ViewController" customModule="ObjectDetector" sceneMemberID="viewController">
<viewController id="l9g-3L-U89" customClass="RootViewController" customModule="ObjectDetector" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="914-Wq-nbc">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct DefaultConstants {
}

// MARK: Model
@objc enum Model: Int, CaseIterable {
enum Model: Int, CaseIterable {
case efficientdetLite0
case efficientdetLite2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

/**
* Singleton storing the configs needed to initialize an MediaPipe Tasks object and run inference.
* Controllers can observe the `InferenceConfigManager.notificationName` for any changes made by the user.
*/
class InferenceConfigManager: NSObject {
var model: Model = DefaultConstants.model {
didSet { postConfigChangedNotification() }
}

var maxResults: Int = DefaultConstants.maxResults {
didSet { postConfigChangedNotification() }
}

var scoreThreshold: Float = DefaultConstants.scoreThreshold {
didSet { postConfigChangedNotification() }
}

static let sharedInstance = InferenceConfigManager()

static let notificationName = Notification.Name.init(rawValue: "com.google.mediapipe.inferenceConfigChanged")

private func postConfigChangedNotification() {
NotificationCenter.default
.post(name: InferenceConfigManager.notificationName, object: nil)
}

}

This file was deleted.

Loading

0 comments on commit 2948bbc

Please sign in to comment.