diff --git a/mediapipe/MediaPipe.tulsiproj/Configs/MediaPipe.tulsigen b/mediapipe/MediaPipe.tulsiproj/Configs/MediaPipe.tulsigen index 69b95f381..41eee5741 100644 --- a/mediapipe/MediaPipe.tulsiproj/Configs/MediaPipe.tulsigen +++ b/mediapipe/MediaPipe.tulsiproj/Configs/MediaPipe.tulsigen @@ -23,8 +23,7 @@ "mediapipe/objc/testing/app/BUILD" ], "buildTargets" : [ - "//mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera:posetracking-lindera", - "//mediapipe/swift/solutions/lindera:lindera" + "//mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera:posetracking-lindera" ], "optionSet" : { "BazelBuildOptionsDebug" : { diff --git a/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/BUILD.bazel b/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/BUILD.bazel index 6ba6af02e..592435d03 100644 --- a/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/BUILD.bazel +++ b/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/BUILD.bazel @@ -12,7 +12,7 @@ MIN_IOS_VERSION = "14.0" swift_library( name = "lindera_app_lib", srcs = glob(["**/*.swift"]), - data =[ + data = [ "Base.lproj/LaunchScreen.storyboard", "Base.lproj/Main.storyboard", ], @@ -62,7 +62,7 @@ ios_application( "ipad", ], infoplists = [ - "Info.plist", + "Infobazel.plist", "//mediapipe/examples/ios/common:Info.plist", ], linkopts = [ diff --git a/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/Base.lproj/Main.storyboard b/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/Base.lproj/Main.storyboard index 2ca04eade..d65b7611f 100644 --- a/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/Base.lproj/Main.storyboard +++ b/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/Base.lproj/Main.storyboard @@ -56,6 +56,38 @@ + + + + + + + + + + @@ -63,8 +95,10 @@ + + diff --git a/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/Infobazel.plist b/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/Infobazel.plist new file mode 100644 index 000000000..108826e3b --- /dev/null +++ b/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/Infobazel.plist @@ -0,0 +1,34 @@ + + + + + + UIApplicationSceneManifest + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSupportsMultipleScenes + + MainViewController + ViewController + UILaunchStoryboardName + LaunchScreen + + + diff --git a/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/ViewController.swift b/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/ViewController.swift index b9b449643..3cc30c86f 100644 --- a/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/ViewController.swift +++ b/mediapipe/examples/ios/posetracking-lindera/PoseTrackingLindera/ViewController.swift @@ -7,9 +7,34 @@ import UIKit import LinderaDetection //import LinderaDetection +import PhotosUI +class ViewController: UIViewController, PHPickerViewControllerDelegate { + + // Video Picker + func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { + + for result in results { + result.itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.movie.identifier){url,err in + if let url = url { + DispatchQueue.main.async { + [weak self] in -class ViewController: UIViewController { + picker.dismiss(animated: true) + self?.inputSourceView.isHidden = true + + } + let asset = AVAsset(url: url) + self.lindera.startVideo(asset: asset) + + } + } + } + +// + + } + //MARK: - UI Elements @@ -17,11 +42,30 @@ class ViewController: UIViewController { @IBOutlet var liveView : UIView! @IBOutlet var showLandmarksButton: UIButton! @IBOutlet var chooseModelButton: UIButton! + @IBOutlet var startCameraButton: UIButton! @IBOutlet var titleview: UIView! @IBOutlet var fpsLabel: UILabel! - + @IBOutlet var inputSourceView: UIView! //MARK: - UI Actions + @IBAction func startCamera(){ + lindera.startCamera() + inputSourceView.isHidden = true + + + + } + + @IBAction func pickVideo(){ + var configuration = PHPickerConfiguration(photoLibrary: .shared()) + let filter = PHPickerFilter.any(of: [ .videos]) + configuration.filter = filter + configuration.selectionLimit = 1 + let picker = PHPickerViewController(configuration: configuration) + picker.delegate = self + present(picker, animated: true) + + } @IBAction func setModelComplexity(){ let alert = UIAlertController( @@ -150,12 +194,16 @@ class ViewController: UIViewController { // Otherwise they are hidden self.liveView.bringSubviewToFront(titleview) self.liveView.bringSubviewToFront(fpsLabel) - + self.liveView.bringSubviewToFront(inputSourceView) // Make the Landmarks and Model button text reflect the state in lindera object updateLandmarksButtonText() updateModelButtonText() - lindera.startCamera() + + + + + } diff --git a/mediapipe/swift/solutions/lindera/Lindera.swift b/mediapipe/swift/solutions/lindera/Lindera.swift index 3a380c923..5f756daee 100644 --- a/mediapipe/swift/solutions/lindera/Lindera.swift +++ b/mediapipe/swift/solutions/lindera/Lindera.swift @@ -2,6 +2,12 @@ import UIKit #if arch(arm64) import MPPoseTracking +import AVFoundation + +public enum InputSource { + case CAMERA,VIDEO +} + /// A helper class to run the Pose Tracking API @@ -20,7 +26,45 @@ public final class Lindera{ public func setFpsDelegate(fpsDelegate: @escaping (_ fps:Double)->Void){ fpsHelper.onFpsUpdate = fpsDelegate; } + + public func startVideo(asset:AVAsset){ + self.videoSource = MPPPlayerInputSource(avAsset: asset) + self.videoSource.setDelegate(self.poseTracking, queue: self.poseTracking.videoQueue) + DispatchQueue.main.async { [weak self] in + + if let self = self { + // set our rendering layer frame according to cameraView boundry + self.poseTracking.renderer.layer.frame = self.cameraView.layer.bounds + // attach render CALayer on cameraView to render output to + self.cameraView.layer.addSublayer(self.poseTracking.renderer.layer) + } + } + + self.poseTracking.videoQueue.async(execute:{ [weak self] in + self?.videoSource.start() + + + }) + + } + + public func setInputSource(inputSource:InputSource){ + if (self.inputSource==inputSource) {return} + switch(inputSource){ + + case .CAMERA: + self.cameraSource.setDelegate(self.poseTracking, queue: self.poseTracking.videoQueue) + break + + case .VIDEO: + break + } + + + self.inputSource = inputSource + + } // Get the camera UI View that may contain landmarks drawing public var cameraView: UIView { return self.linderaExerciseSession @@ -57,6 +101,7 @@ public final class Lindera{ startPoseTracking() } + public func startCamera(_ completion: ((Result) -> Void)? = nil) { // set our rendering layer frame according to cameraView boundry @@ -182,8 +227,9 @@ public final class Lindera{ // attach Mediapipe camera helper to our class let cameraSource = MPPCameraInputSource() + var videoSource = MPPPlayerInputSource() - + var inputSource:InputSource = InputSource.CAMERA }