How to Build an Automatic Plank Timer using AI Pose Estimation

Kevin K DeRoo
QuickPose
Published in
3 min readJun 13, 2023

QuickPose’s iOS SDK is makes it easier than ever to integrate MediaPipe into iOS, with a plethora of fitness exercises you can easily add into your app.

AI is really changing the way we interact with machines — with ChatGPT tapped into the real-time internet, we’re seeing swathes of changes in our daily lives.

Exercise is no exception, and if you’re already somewhat tapped into the latest tech news, no doubt you’ll be aware of Pose Estimation. And now, even if you’re a developer who does more copy-pasting than typing code (ahem…everyone?), you can get your nifty developer fingers on this tasty tech and paste it right into your projects.

Step 1: Add the QuickPose iOS SDK repo from Github to your app

https://github.com/quickpose/quickpose-ios-sdk

Step 2: Register for a Free SDK Key

https://dev.quickpose.ai/auth/signup

Step 3: Add your Bundle ID

Unique bundle ID for each app.

Step 4: Incorporate into SwiftUI

Proceed to integrate QuickPose with your SwiftUI views. This step includes the setup of camera permissions and linking the QuickPose SDK to your SwiftUI views.

import SwiftUI
import QuickPoseCore
import QuickPoseSwiftUI

struct QuickPoseBasicView: View {
private var quickPose = QuickPose(sdkKey: "YOUR SDK KEY HERE") // register for your free key at dev.quickpose.ai
@State private var overlayImage: UIImage?
var body: some View {
GeometryReader { geometry in
ZStack(alignment: .top) {
QuickPoseCameraView(useFrontCamera: true, delegate: quickPose)
QuickPoseOverlayView(overlayImage: $overlayImage)
}
.frame(width: geometry.safeAreaInsets.leading + geometry.size.width + geometry.safeAreaInsets.trailing)
.edgesIgnoringSafeArea(.all)
.onAppear {
quickPose.start(features: [.showPoints()], onFrame: { status, image, features, feedback, landmarks in
if case .success(_,_) = status {
overlayImage = image
} else {
overlayImage = nil
}
})
}.onDisappear {
quickPose.stop()
}
}
}
}

Step 5: Adding “Plank ”

You can add the Plank Timer with the following lines of code:

To time the Plank declare a configurable threshold timer, which can be used to turn lots of our features into timers. For Plank, we suggest modifying the default threshold, taking account of expected camera positioning and tilt.

@State private var timer = QuickPoseThresholdTimer(threshold: 0.2)

Then pass the result’s raw value to the timer, and display in the feedback text declared above.

quickPose.start(features: [.fitness(.plank)], onFrame: { status, image, features, feedback, landmarks in
switch status {
case .success:
overlayImage = image
if let result = features.values.first {
let timerState = timer.time(result.value)
feedbackText = String(format: "%.1f", timerState.time) + "secs"
} else {
feedbackText = nil
}

case .noPersonFound:
feedbackText = "Stand in view";
case .sdkValidationError:
feedbackText = "Be back soon";
}
})

Check our docs for a deeper dive of features you can add.

Step 6: Develop Customised Feedback:

Enhance the user experience by developing custom feedback prompts.

You can also edit the styling and annotations to suit the UI of your own app.

That’s it! In only a few steps, you have integrated an AI push up counter into your app. Now you’ve seen how simple it is, we encourage you to test out our other exercises. We’ll leave it up to you to create incredible user experiences, develop gamification elements, and create an app your users will remember.

If you’re thinking of developing something and want to bounce around some ideas, we’re all ears! Drop us an email if you would like to get in touch: info@quickpose.ai

--

--