Building a pushup counter with OpenCV and Clojure

Hello folks. I built a pushup counter with OpenCV + Clojure. Here is a video it working (please excuse my poor pushup form).

First the counter takes a raw image and subtracts out the background.

Then it averages the Ycoordinate values of all the white pixels. This average value corresponds to the vertical center of my body. If I plot this Y value across time as I do a pushup, it forms a nice sinusoidal curve

I then compute the slope of that curve by simply subtracting the last point with the new point. When that slope flips sign, I know my body is in the pushup position and the counter adds one.

Here is a video of that underlying process in action:

The display and voice synthesis is relatively easy. There are many libraries and APIs to do GUI and voice synthesis. I used OpenCV’s drawing function for the GUI and I used Mac’s say for the verbal audio count. If I were to do it again, I would get my computer to speak in my own voice using the

Anyway, if you are interested in checking out the source code, you can find it . The pushup counter was part of a larger project I put together a few years ago and it requires a lot of setup to get running. Despite that, my code may help you with some of your own computer vision ideas.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store