Automatically Take Perfect Jump Shots




About: I spend my time somewhere between engineering and art.
Ohhh timing. You ruin every jump shot.
You're counting down right before you leap into the air and your friend is crouched on the ground with their finger on the shutter button. Leaping into the air with a glorious jump, you pose for a split second. Confident in your ability, you run to your friend only to find that it is, yet again, another perfectly great jump shot ruined by the lag between pressing the shutter button and the photo actually being taken.

Well, no more! Using Processing, OpenCV, and a high quality web camera, you can take a perfect jump shot (nearly*) everytime!

*has some annoying constraints (see the last step!)

Step 1: How It Works

The key to this project is using OpenCV's face detection capabilities. When a person is looking towards the camera, it will register the face. This is an example already available in the OpenCV library that was modified for this project. The sketch (Processing lingo for the code) is analyzing the basics of a persons movement. If their head goes above a certain location on the frame and there is a change in vertical direction (start falling back down), it will automatically take a image from the web camera. 

Step 2: Get Processing Set Up

Note: Newer versions of Processing are no longer compatible with this library. This OpenCV library works with the later versions of Processing, however, my code is not compatible with it. I'll try and update this Instructable when I get a chance.

First of all, you will need a computer that has Processing installed. Processing is free and open source, so download it and install it on your computer right now! It is a powerful tool and has a very active community of people working with it.

You will also need to install OpenCV and the Simple-OpenCV library for Processing. If you are using a Mac, you can follow this Instructable otherwise you can always follow the directions on this website.

Step 3: Run Code

After you have set up and tested Processing and OpenCV, all you need to do is run the sketch. 

Download and uncompress the sketch.

If you have a USB web camera connected to your computer, the sketch should automatically load that over the onboard web camera. At least that's what happens with me. I hope it does with you.

You will want to check both the wide and high variables in the sketch. This should match the resolution of the web camera that you are using. When you are jumping you'll want to be far enough back that you can get your whole body in the frame. If your face is detected you'll see a red box at the top of the camera feed. Jump up high to get your head in that box.  If it flashes white and you hear a shutter sound, then it took an image and saved it in the folder file that contains the Processing sketch. 

Step 4: Issues and Critiques

There are limitations to this set up. The main one is that the face detection on OpenCV requires that your face is pointed towards the camera. If your head is tilted away from the camera, it isn't going to work. Lighting is also an issue. I found that working in a room with a reasonable amount of natural sunlight seemed work best. Dimly lit rooms produced lower quality images and had a higher chance of not taking an image. Jumping against a bare background also seems to work better with the face detection. OpenCV will occasionally detect random objects in the background as faces. 

The Kinect would probably produce more consistent results and this is how I originally started working on this project. It allows you to have a high amount of control of when it takes an image. For instance, if you wanted to set it up so that it only takes a photo of when you jump into a certain pose, this would be much easier to accomplish with the Kinect's technology and the skeleton feature. However, the resolution of the onboard camera on the Kinect is pretty terrible. So, an additional web camera would probably be required in the setup. 



    • Warm and Fuzzy Contest

      Warm and Fuzzy Contest
    • Toys Contest

      Toys Contest
    • Comfort Food Challenge

      Comfort Food Challenge

    23 Discussions


    4 years ago on Introduction

    Has anyone refactored the code to use Greg Borenstein's newer OpenCV for Processing library?


    5 years ago on Introduction

    You did a really nice work with OpenCV i'm impressed.
    And you could maybe help me in some way.
    I made a program a few ago which dectect my head.
    I used the cvhaardectect and the face.xml
    I'm running this with xcode on my macbook but the program is running really slow.
    I basicly capture a frame, display it on a window and i draw a circle around my face.
    It's not the drawing which slow down but I cannot verify if the display does.
    I'll be very thankful if you could give me some tip or/and tricks to increase the speed of my captures.
    Thanks in advance.
    Again; you did an amazing job.

    1 reply

    Reply 5 years ago on Introduction

    Unfortunately, I don't have experience the with CV programs that you are using. I'd recommend finding an OpenCV forum and posting there.


    5 years ago on Step 4

    This is a lot of fun. From a usability standpoint, though, this doesn't seem any easier than just using the webcam to film and then take a still from the resulting video. If your webcam for some reason takes higher resolution pictures than video, than this project makes a lot of sense. Nice write-up!


    5 years ago on Introduction

    It's a clever funny project. Ditto on what MassimoHackensack said. I do admit that playing and sometimes fighting with OpenCV is a blast.


    5 years ago on Step 4

    I find just making a video and using an editing program that has frame capture to much easier.
    Do all the jumping and dancing you want, face any direction and spin in mid air if you wish and then just capture the frames as jpegs and link them together.


    5 years ago on Introduction

    Reminds me of this.

    I dont get it.. would you not be able to just bring a movie file into PS and render the individual frames and then deleting all but the jumping frames. and same for web.. and bang.. You have jumping in the air gif.?


    5 years ago on Introduction

    Very Nice!
    I like it, and would try connecting it to DSLR to get better photo qualities.

    Camillo Miller

    5 years ago on Step 4

    This is a great project!
    It shouldn't be difficult to connect a DSLR to this setup, maybe through an Arduino, and just shoot a burst (to get the best possibile picture) in the right moment :)

    1 reply

    Actually if you got a PC there (or Mac), would be much easier to use the libs from Canon (maybe Nikon too) to directly control the DSLR. Canon have some SDK I played with and can do any control on the camera connected with USB cable. The SDK requires registration but otherwise free.

    What sort of frame rates are you able to analyze the photo for a face? Could you track the average height of the face and snap the picture at its peak?