How Rep Counting Works: The Algorithm Explained
Updated July 24, 2026
Rep counting turns a stream of pose keypoints into a repetition count by tracking one signal over time — usually a joint angle (three keypoints, like shoulder-elbow-wrist for a curl) or a keypoint position — and detecting when that signal completes a full up-down cycle. Two algorithm families dominate: peak/valley detection on the angle trajectory, and a finite state machine that models each exercise as up/down phases with thresholds. The single most important design choice is how you avoid double-counting jitter near a threshold: a state machine with hysteresis (separate entry thresholds for "up" and "down") is the robust default; pure peak detection is simpler but needs smoothing and a minimum-amplitude gate to behave. Pick the state machine if you want clean, jitter-resistant counting across messy real-world form.
This page explains the algorithm — the concept. To wire it into a real camera feed, see the add rep counting guide for implementation. New to the underlying tech? Start with what pose estimation is.
The signal: from keypoints to one number over time
A pose model gives you a set of keypoints per frame — coordinates, each with a confidence or visibility score. Rep counting does not use all of them at once. Instead you reduce the pose to one scalar that oscillates as the rep happens:
- Joint angle. Take three keypoints that define a joint and compute the angle between the two bones. A bicep curl is the elbow angle (shoulder-elbow-wrist); a squat is the knee or hip angle. The angle swings between a "down" extreme and an "up" extreme once per rep. This is the most common and most robust choice because an angle is invariant to where the person stands in frame and how far they are from the camera.
- Keypoint position. For some movements a single coordinate works — the vertical position of the wrists in a jumping jack, or the hip height in a squat. Positions are simpler but sensitive to camera distance and framing, so they usually need normalization first.
Whichever you pick, the result is a one-dimensional signal that rises and falls once per repetition. Everything after this is signal processing on that curve.
Two ways to count a cycle
Once you have the signal, you need to decide when a rep has happened. There are two established approaches.
| Approach | How it works | Trade-off |
|---|---|---|
| Peak/valley detection | Find local maxima and minima in the angle (or position) trajectory. A peak marks the midpoint of a rep; the valley that follows marks the start/end of the next cycle. Count one rep per completed peak-to-valley cycle. | Simple to implement, but sensitive to noise — messy form can produce multiple small peaks per rep, and jitter near an extreme can register phantom cycles. Needs smoothing plus a minimum-amplitude and minimum-time gate. |
| Finite state machine | Model the exercise as phases (for example down and up). The angle crossing a threshold drives a state transition; completing the full phase cycle increments the counter. | More robust to jitter and partial motion because state only changes on a deliberate threshold crossing. Slightly more logic per exercise, but far fewer false counts. This is the usual default. |
Both operate on the same underlying angle curve. In practice many production counters are state machines because the phase model maps cleanly onto how a rep actually feels — you go down, you come up, that is one.
Walking through the state machine
Here is the logic in prose for a bicep curl, tracking the elbow angle. A straight arm is a large angle (near 180 degrees); a fully curled arm is a small angle.
Start in the down state (arm extended). When the elbow angle drops below a low threshold — say the arm has curled past a certain point — transition to the up state. Then wait: only when the angle climbs back above a high threshold (arm re-extended) do you transition back to down and increment the rep count by one. The rep is counted on the completed cycle, not on either single crossing.
The critical detail is that the two thresholds are different values with a gap between them. That gap is hysteresis. If you used a single threshold, an angle hovering right at that value — which is exactly what noisy keypoints do at the top or bottom of a rep — would flip the state back and forth and count several reps for one. By requiring the signal to travel from a low threshold all the way past a separate high threshold before it can count again, small jitters near either boundary are ignored. The same pattern generalizes to any exercise: pick the joint, pick the two thresholds, define the phase cycle.
Per-exercise logic
Rep logic is exercise-specific. The joint, the angle, and the thresholds all differ by movement:
- Squat — knee and/or hip angle; "down" is deep flexion, "up" is standing.
- Push-up — elbow angle, similar to a curl but body-oriented.
- Bicep curl — elbow angle, arm hanging as the reference.
- Jumping jack — often keypoint positions (wrist height, ankle spread) rather than a single joint angle.
Because each movement needs its own joints and thresholds, a practical counter is built as a library of small, reusable per-exercise definitions rather than one universal detector. Adding a new exercise means specifying which joints to watch and where the phase thresholds sit — real, ongoing engineering work, not a one-time build.
Handling noise and false reps
Raw per-frame keypoints jitter, and that jitter is the enemy of an accurate count. Several layers help:
- Smooth the signal first. Apply a temporal filter to the keypoints or the derived angle before you do any peak or threshold logic. A One Euro filter is a common low-cost choice; the point is that you should never run detection on raw, unsmoothed keypoints. See pose estimation accuracy for why jitter and smoothing matter.
- Use hysteresis, not a single threshold. As above — separate up and down thresholds prevent double-counting when the signal lingers near a boundary.
- Gate on amplitude and time. Require the signal to travel a minimum range (a real rep, not a twitch) and to take a minimum plausible time, so partial motions and jitter spikes do not count.
- Gate on confidence. Pose models emit per-keypoint visibility or confidence. If the joints you depend on are occluded or low-confidence, down-weight or skip those frames rather than compute a garbage angle.
A known failure mode is worth naming: depending on the exercise and the person's form, the angle signal can show multiple peaks per repetition or vary in peak shape and amplitude, which trips up naive peak detection. This is exactly why smoothing plus a state machine (or a gated peak detector) beats reading raw extremes.
Calibration and orientation
Two more real-world factors decide whether your thresholds actually fire correctly:
- Calibration to the user. Range of motion varies by body, mobility, and how deep someone actually goes. Fixed thresholds that work for one person may never trigger for another. A common fix is to capture a reference rep at the start (or use adaptive thresholds that learn each user's range) so "down" and "up" are defined relative to that person rather than an absolute angle.
- Camera orientation and framing. The joints you measure must be in frame and roughly in the camera plane. An angle that projects into depth (the limb moving toward or away from the camera) is the least reliable, because monocular single-camera depth is estimated, not measured. Keep the user side-on or front-on to the movement axis you are counting, with the whole relevant segment visible. Poor lighting, baggy clothing, occlusion, and oblique angles all degrade the keypoints and, downstream, the count.
The honest limits
- A normal RGB phone camera is enough. No depth sensor or LiDAR is needed to count reps — you are tracking 2D angles that stay in the camera plane.
- Miscounts are real. Partial reps, very fast reps, occluded joints, and bad camera angles all cause the signal to miss a threshold or fire a spurious one. Per-exercise threshold tuning is genuine engineering, not a solved default.
- Do not publish an accuracy percentage as fact. Rep-counting accuracy is dataset-, exercise-, and form-dependent; any figure you cite should be attributed to its source and hedged, and re-verified on your own users and hardware (as of 2026, verify).
- Rep counting is not form judgment. A counter tells you that a rep happened, not whether it was done safely. Form scoring is a separate feature — see how form feedback works — and neither is medical or physical-therapy advice.
Before you build
Reduce the pose to one signal (usually a joint angle), smooth it, then drive a per-exercise state machine with hysteresis and amplitude/time gates — that combination is the robust default. Calibrate thresholds to each user, keep the measured joints in frame and in the camera plane, and verify counting accuracy on your own exercises and devices rather than trusting a lab figure. When you are ready to implement it against a live camera feed, follow the add rep counting guide.
Frequently asked questions
- What signal does a rep counter actually track?
- It reduces the pose to one number that oscillates once per rep. Most commonly that is a joint angle from three keypoints (elbow angle for a curl, knee or hip angle for a squat), because an angle is invariant to where the person stands or how far they are from the camera. Some movements use a keypoint position instead (wrist height, hip height), but positions need normalization first. Everything after that is signal processing on that one curve.
- What is hysteresis and why does it stop double-counting?
- Hysteresis means using two different thresholds with a gap between them instead of one. To count a rep you must cross a low threshold into the down phase and then travel all the way past a separate high threshold into the up phase. With a single threshold, noisy keypoints hovering right at that value would flip the state back and forth and count several reps for one. The gap forces the signal to make a full, deliberate swing before it can count again.
- How do you handle noise and false reps?
- Smooth the keypoints or the derived angle before any detection (a One Euro filter is a common low-cost choice), use hysteresis rather than a single threshold, and gate on minimum amplitude and minimum time so twitches and partial motions do not count. Also gate on the model's per-keypoint confidence or visibility and skip frames where the joints you depend on are occluded. Naive peak detection on a raw signal is the main source of miscounts.
- Do I need a depth camera to count reps?
- No. A normal RGB phone camera is enough. Rep counting tracks 2D joint angles that stay in the camera plane, so no depth sensor or LiDAR is required. What matters more is orientation and framing: keep the measured joints in frame and roughly in the camera plane, since an angle projecting toward or away from the camera relies on estimated depth and is the least reliable.
- How accurate is camera-based rep counting?
- It varies by exercise, dataset, and the user's form, so there is no single number to quote. Partial reps, very fast reps, occlusion, and oblique camera angles all cause miscounts, and thresholds often need per-user calibration. Treat any accuracy figure you see as attributed and hedged, and verify it on your own exercises and hardware rather than trusting a lab result. Rep counting also is not form judgment and is not medical advice.
Keep reading
Independent comparison, last reviewed July 24, 2026. Pricing, rate limits, and feature availability change often — confirm current details in each provider’s official documentation before you commit. Product and company names are trademarks of their respective owners; AIFitnessAPI is not affiliated with, endorsed by, or sponsored by any product listed here.
← All ai motion · by AIFitnessAPI