Niranjan Akella
3 min readOct 23, 2022

Python “Clap Counter” to track Surya Namaskara cycles

Hello readers!!! 👋

This is my 1st note on #SelfHelp series, that I am starting to demonstrate how tech can be used to help ourselves when we cannot find a good product out there or for tech enthusiasts who love to “DIY” their regular stuff.

Background

Recently, I have started my journey into physical yoga. After lots of research into it, I understood that “Surya Namaskara” is the best exercise circuit that impacts all the crucial aspects of the body in one go. One “Surya Namaskara” cycle burns 13.90 calories.

I always wondered why only this? Since sages of ancient times were considered to be highly intellectual people, so why did they choose this over any other?

In this quest of questions, I understood that physical yoga when practiced regularly has the potential to heal every aspect of the human body. It is also observed that it can help you develop bone flexibility and lung capacity. By consistent yoga practice a person can see observe certain changes in themselves, such as:

  1. Increased air retention capacity
  2. Improved physical mobility
  3. Better skin quality
  4. Better overall physique
  5. Reduced stress & laziness
  6. Improved focus
  7. Staying active for longer durations

More info on Surya Namaskara can be found online in Google Scholar…..

Problem

When I started practicing Surya Namaskara, I was frustrated to keep a track of the number of cycles that have completed. And hence I always miscalculated the total number of cycles. Either I would end up performing more cycles or less. Hence I decided to build something for myself which can ease this process and reduce mental strain…. Haha 😄

Solution

I needed something that requires very less effort and should be easy to implement. Thus I decided to build a Python Script that can detect a clap and increment the count, hence helping me keep a track of completed cycles.

But wait….. There is a problem.

My Macbook’s monitor is small and I can’t stop my yoga cycles to come closer to check on the number right? Thus I used the “Computer Vision” library to create a large image window onto which I would display the count.

Numbers keep incrementing on the screen

That’s It!!! This helps me track my cycles with just a Clap 👏.

Implementation

  • The script is very simple, I used an open source package called “pi-clap” that listen’s to the continuous audio stream from my Macbook and executes a method when it detects a clap.
  • Then I have integrated the script with the OpenCV2 package to display the cycle count onto an image window.

Note: The script also contains methods for 2 claps and 3 claps which are used to decrement the cycle count value and to terminate the script. I have set the threshold level to be very high so that I can also make it work by just snapping my fingers which is way more cool than clapping 😁.

After running the below script you will be prompted to confirm/recalibrate/manual/quit, you need to type in ‘c’ to confirm and press “Enter” to start the script.

Install packages

pip install pi-clap
pip install pynput
pip install opencv-python
pip install numpy

Script

I shall be posting more such solution which help make life easier. Please do support me and do suggest me if you have better ways of solving such problems.

Thank you so much!!! See you next time ✌️

Niranjan Akella

A scientist by heart and a passionate researcher in my field of expertise. I love philosophy.