Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
st-tuanmai committed Sep 18, 2023
1 parent 681d442 commit ffc46ac
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
390980DAF1C0BF696F2F9034 /* libPods-HandLandmarkerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A5255B9766F2DC5A4177BEC /* libPods-HandLandmarkerTests.a */; };
BE623C897110F7E0442419C4 /* Pods_HandLandmarker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C35377F7CB8DB927779D1AD /* Pods_HandLandmarker.framework */; };
BF5EEC682AB7EBB500189276 /* thumbs-up.png in Resources */ = {isa = PBXBuildFile; fileRef = BF5EEC672AB7EBB500189276 /* thumbs-up.png */; };
BFCDAE252AAEB2A700EC4371 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFCDAE242AAEB2A700EC4371 /* AppDelegate.swift */; };
BFCDAE272AAEB2A700EC4371 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFCDAE262AAEB2A700EC4371 /* SceneDelegate.swift */; };
BFCDAE2C2AAEB2A700EC4371 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BFCDAE2A2AAEB2A700EC4371 /* Main.storyboard */; };
Expand Down Expand Up @@ -43,6 +44,7 @@
5C35377F7CB8DB927779D1AD /* Pods_HandLandmarker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HandLandmarker.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6A5255B9766F2DC5A4177BEC /* libPods-HandLandmarkerTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-HandLandmarkerTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
B19658A239090768FF9A5F9F /* Pods-HandLandmarker.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HandLandmarker.debug.xcconfig"; path = "Target Support Files/Pods-HandLandmarker/Pods-HandLandmarker.debug.xcconfig"; sourceTree = "<group>"; };
BF5EEC672AB7EBB500189276 /* thumbs-up.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "thumbs-up.png"; sourceTree = "<group>"; };
BFCDAE212AAEB2A700EC4371 /* HandLandmarker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HandLandmarker.app; sourceTree = BUILT_PRODUCTS_DIR; };
BFCDAE242AAEB2A700EC4371 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
BFCDAE262AAEB2A700EC4371 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -146,6 +148,7 @@
BFCDAE3A2AAEB2A800EC4371 /* HandLandmarkerTests */ = {
isa = PBXGroup;
children = (
BF5EEC672AB7EBB500189276 /* thumbs-up.png */,
BFCDAE3B2AAEB2A800EC4371 /* HandLandmarkerTests.swift */,
);
path = HandLandmarkerTests;
Expand Down Expand Up @@ -282,6 +285,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BF5EEC682AB7EBB500189276 /* thumbs-up.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -575,6 +579,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 9PLS9MU793;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MARKETING_VERSION = 1.0;
Expand All @@ -595,6 +600,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 9PLS9MU793;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MARKETING_VERSION = 1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stepper opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.20000000000000001" minimumValue="0.10000000000000001" maximumValue="0.80000000000000004" stepValue="0.10000000000000001" translatesAutoresizingMaskIntoConstraints="NO" id="0nH-Zx-p69">
<stepper opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.10000000000000001" minimumValue="0.10000000000000001" maximumValue="0.80000000000000004" stepValue="0.10000000000000001" translatesAutoresizingMaskIntoConstraints="NO" id="0nH-Zx-p69">
<rect key="frame" x="283" y="88.666666666666671" width="94" height="32"/>
<color key="backgroundColor" red="0.0" green="0.49803921569999998" blue="0.5450980392" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<userDefinedRuntimeAttributes>
Expand Down Expand Up @@ -193,7 +193,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stepper opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.20000000000000001" minimumValue="0.10000000000000001" maximumValue="0.80000000000000004" stepValue="0.10000000000000001" translatesAutoresizingMaskIntoConstraints="NO" id="1fr-hY-4II">
<stepper opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.10000000000000001" minimumValue="0.10000000000000001" maximumValue="0.80000000000000004" stepValue="0.10000000000000001" translatesAutoresizingMaskIntoConstraints="NO" id="1fr-hY-4II">
<rect key="frame" x="283" y="132.66666666666666" width="94" height="32"/>
<color key="backgroundColor" red="0.0" green="0.49803921569999998" blue="0.5450980392" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -218,7 +218,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stepper opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.20000000000000001" minimumValue="0.10000000000000001" maximumValue="0.80000000000000004" stepValue="0.10000000000000001" translatesAutoresizingMaskIntoConstraints="NO" id="DDi-33-JAf">
<stepper opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.10000000000000001" minimumValue="0.10000000000000001" maximumValue="0.80000000000000004" stepValue="0.10000000000000001" translatesAutoresizingMaskIntoConstraints="NO" id="DDi-33-JAf">
<rect key="frame" x="283" y="176.66666666666666" width="94" height="32"/>
<color key="backgroundColor" red="0.0" green="0.49803921569999998" blue="0.5450980392" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -243,6 +243,9 @@
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="layer.cornerRadius" value="8"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="numHandsStepperValueChanged:" destination="zgE-Xo-ZSc" eventType="valueChanged" id="ti0-YY-lAk"/>
</connections>
</stepper>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Num Hands" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jCg-YX-6ga">
<rect key="frame" x="16" y="228" width="76" height="17"/>
Expand Down Expand Up @@ -357,7 +360,7 @@
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="m4r-LP-sGS" customClass="OverlayView" customModule="FaceDetector">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="m4r-LP-sGS" customClass="OverlayView" customModule="HandLandmarker">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
Expand Down Expand Up @@ -409,7 +412,7 @@
<rect key="frame" x="0.0" y="59" width="393" height="759"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Sfh-5s-l7y" customClass="OverlayView" customModule="FaceDetector">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Sfh-5s-l7y" customClass="OverlayView" customModule="HandLandmarker">
<rect key="frame" x="0.0" y="59" width="393" height="759"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ import UIKit

// MARK: Define default constants
struct DefaultConstants {

static let lineWidth: CGFloat = 2
static let pointRadius: CGFloat = 5
static let pointColor = UIColor.yellow
static let pointFillColor = UIColor.red
static let lineColor = UIColor(red: 0, green: 127/255.0, blue: 139/255.0, alpha: 1)

static var numHands: Int = 1
static var minHandDetectionConfidence: Float = 0.3
static var minHandPresenceConfidence: Float = 0.3
static var minTrackingConfidence: Float = 0.3
static var minHandDetectionConfidence: Float = 0.5
static var minHandPresenceConfidence: Float = 0.5
static var minTrackingConfidence: Float = 0.5
static let modelPath: String? = Bundle.main.path(forResource: "hand_landmarker", ofType: "task")
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class HandLandmarkerService: NSObject {
private func createHandLandmarker() {
let handLandmarkerOptions = HandLandmarkerOptions()
handLandmarkerOptions.runningMode = runningMode
// handLandmarkerOptions.numHands = numHands
// handLandmarkerOptions.minHandDetectionConfidence = minHandDetectionConfidence
// handLandmarkerOptions.minHandPresenceConfidence = minHandPresenceConfidence
// handLandmarkerOptions.minTrackingConfidence = minTrackingConfidence
handLandmarkerOptions.numHands = numHands
handLandmarkerOptions.minHandDetectionConfidence = minHandDetectionConfidence
handLandmarkerOptions.minHandPresenceConfidence = minHandPresenceConfidence
handLandmarkerOptions.minTrackingConfidence = minTrackingConfidence
handLandmarkerOptions.baseOptions.modelAssetPath = modelPath
if runningMode == .liveStream {
handLandmarkerOptions.handLandmarkerLiveStreamDelegate = self
Expand Down Expand Up @@ -256,7 +256,13 @@ extension HandLandmarkerService: HandLandmarkerLiveStreamDelegate {
didFinishDetection result: HandLandmarkerResult?,
timestampInMilliseconds: Int,
error: Error?) {

let resultBundle = ResultBundle(
inferenceTime: Date().timeIntervalSince1970 * 1000 - Double(timestampInMilliseconds),
handLandmarkerResults: [result])
liveStreamDelegate?.handLandmarkerService(
self,
didFinishDetection: resultBundle,
error: error)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,15 @@ extension CameraViewController: HandLandmarkerServiceLiveStreamDelegate {
didFinishDetection result: ResultBundle?,
error: Error?) {
DispatchQueue.main.async { [weak self] in
guard let weakSelf = self else {
return
}
guard let weakSelf = self else { return }
weakSelf.inferenceResultDeliveryDelegate?.didPerformInference(result: result)
guard let handLandmarkerResult =
result?.handLandmarkerResults.first as? HandLandmarkerResult else {
return
}
guard let handLandmarkerResult = result?.handLandmarkerResults.first as? HandLandmarkerResult else { return }
let imageSize = weakSelf.cameraFeedService.videoResolution
let objectOverlays = OverlayView.objectOverlays(
fromLandmarks: handLandmarkerResult.landmarks,
inferredOnImageOfSize: imageSize,
ovelayViewSize: weakSelf.overlayView.bounds.size,
imageContentMode: weakSelf.overlayView.imageContentMode,
andOrientation: UIImage.Orientation.from(
deviceOrientation: UIDevice.current.orientation))
weakSelf.overlayView.draw(objectOverlays: objectOverlays,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ extension MediaLibraryViewController: UIImagePickerControllerDelegate, UINavigat
DispatchQueue.main.async {
weakSelf.hideProgressView()
weakSelf.inferenceResultDeliveryDelegate?.didPerformInference(result: resultBundle)
let imageSize = image.size
let objectOverlays = OverlayView.objectOverlays(
fromLandmarks: handLandmarkerResult.landmarks,
inferredOnImageOfSize: imageSize,
ovelayViewSize: weakSelf.overlayView.bounds.size,
imageContentMode: weakSelf.overlayView.imageContentMode,
andOrientation: image.imageOrientation)
weakSelf.overlayView.draw(objectOverlays: objectOverlays,
inBoundsOfContentImageOfSize: imageSize,
imageContentMode: .scaleAspectFit)
}
}
default:
Expand Down Expand Up @@ -321,6 +331,17 @@ extension MediaLibraryViewController: UIImagePickerControllerDelegate, UINavigat
let handLandmarkerResult = resultBundle.handLandmarkerResults[index] else {
return
}
weakSelf.inferenceResultDeliveryDelegate?.didPerformInference(result: resultBundle)
let imageSize = resultBundle.size
let objectOverlays = OverlayView.objectOverlays(
fromLandmarks: handLandmarkerResult.landmarks,
inferredOnImageOfSize: imageSize,
ovelayViewSize: weakSelf.overlayView.bounds.size,
imageContentMode: weakSelf.overlayView.imageContentMode,
andOrientation: .up)
weakSelf.overlayView.draw(objectOverlays: objectOverlays,
inBoundsOfContentImageOfSize: imageSize,
imageContentMode: .scaleAspectFit)

// Enable clicks on inferenceVC if playback has ended.
if (floor(CMTimeGetSeconds(time) +
Expand Down
Loading

0 comments on commit ffc46ac

Please sign in to comment.