11.6: Computer Vision: Motion Detection – Processing Tutorial | Video

In this computer vision tutorial, I show how to analyze the pixels of a video to detect motion. This technique is also known as frame differencing.

Support this channel on Patreon: https://patreon.com/codingtrain

Send me your questions and coding challenges!

READ ALSO:  Ms Excel 2007 Tutorials in Telugu Part - 06 తెలుగులో || Excel Functions in Telugu || LEARN COMPUTER {VIDEO}

Contact: https://twitter.com/shiffman

Links discussed in this video:
Computer Vision for Artists and Designers Essay by Golan Levin: http://www.flong.com/texts/essays/essay_cvad/
Image Processing in Computer Vision: http://openframeworks.cc/ofBook/chapters/image_processing_computer_vision.html

Source Code for the Video Lessons: https://github.com/CodingTrain/Rainbow-Code

READ ALSO:  Devilman Vol.2 OVA - The Demon Bird Review

p5.js: https://p5js.org/
Processing: https://processing.org

For More Computer Vision videos: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6aG2RJHErXKSWFDXU4qo_ro

For More Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH

Help us caption & translate this video!


📄 Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct



  1. As walays, great session. ANy hint on how to process a Youtbe live stream and perform that kind of stuff ? I saw your demo on P5.js, but not for processing. Thank you again.

  2. Just wow, I really didn´t expect the dancing part. Your videos are very helpful, I'm trying to do an Augmented Reality exercise with computer vision and this does helped me a lot!

  3. i try to track white pixel in a image, when the pixel moves,it merge with non moving white pixels.. how can i seperate moving and non moving pixel in a image using opencv c++

  4. Hey at 11.12 sec there you have done betterjob. So I a have an idea about, can you make a program for that exactly 3d virtual frame( fix your face then when you giving input as your face to webcam when it matches to your frame as you did at 11.12, then only it has to take the image ) so can you do that.
    Or tell me where I can get that exactly. Please. Thank you

  5. I thought I would really choke on this one because it seemed hard for me to comprehend but after checking the video twice and really focusing in, I got it. You really did such an amazing job on this one. I really appreciate what you do .Even after 2 years your learning people. Seriously! Best teacher man!!!

  6. Hey man, you ruin my imaginations of adobe programmers skills 😀 It seems to me that adobe master collection should be done in a week !!

  7. MOTION DANCE DETECTOR!!!! mmChuh mmChuh mmChuh mmChuh mmChuh mmChuh mmChuh mmChuh

    –TheMagicPinkDotManipulator circa 2016

  8. Hello to everyone. Dan, your videos are absolutely amazing! Thanks you for all the wonderful things that you teach us!

    I have a question, if someone is so kind to answer it.
    I tried to change the dimension of the window, but it seems to work only with 640×360, even if I changed the dimensions of the PImage too. The strange thing is that I tried to hard code the dimensions to 1280×720 and, even if my webcam can give me those resolutions:

    [0] "name=HP Truevision Full HD,size=640×480,fps=30"
    [1] "name=HP Truevision Full HD,size=176×144,fps=30"
    [2] "name=HP Truevision Full HD,size=320×240,fps=30"
    [3] "name=HP Truevision Full HD,size=352×288,fps=30"
    [4] "name=HP Truevision Full HD,size=640×360,fps=30"
    [5] "name=HP Truevision Full HD,size=1280×720,fps=10"
    [6] "name=HP Truevision Full HD,size=1920×1080,fps=5"
    [7] "name=HP Truevision Full HD,size=640×480,fps=30"
    [8] "name=HP Truevision Full HD,size=176×144,fps=30"
    [9] "name=HP Truevision Full HD,size=320×240,fps=30"
    [10] "name=HP Truevision Full HD,size=352×288,fps=30"
    [11] "name=HP Truevision Full HD,size=640×360,fps=30"
    [12] "name=HP Truevision Full HD,size=1280×720,fps=30"
    [13] "name=HP Truevision Full HD,size=1920×1080,fps=30"

    it works only with [4] and at size(640, 360), not other sizes.

    I think that the problem is in the nested for loop because sometimes it gives me the Array out of bound error.

    Does someone know how to fix this problem?
    If you do, I'd be very pleased to hear your solution.

    Again thank you Dan for your work!

  9. I tried to replicate this in python with OpenCV but the double for loop calculation seemed to be taking way too long and made the stream look like a slide show. Any suggestions?

  10. Hi! I have a problem to solve. I would like that once a pixel become (let's say) black thanks to the motion, it stays black forever.
    The aim is to draw the path of a moving object.

    Any hint?

  11. Okay so…. all is fine and dandy except the rectangle that draws the black and white motion detection is stretched thin across the top of my canvas, and my webcam is a small square underneath – neither of which take up the entire canvas and the ellipse just stays in the center of the webcam drawing…. I assume this is due to the dimensions? Can't find what to change tho? Please help 🙁

  12. As always, thank you so much for creating such helpful content.
    I was trying to find the code from this lesson on GitHub, but didn't see it – does it exist anywhere else?
    Thanks in advance!

  13. can someome help me please?! I need to make a processing file that increases the volume of a track by detecting motion from a webcam, I'm very new to all of this and managed to get the webcam and track working however I have no clue on how to get it to change volume based on motion.

  14. I finally have something of value to comment… yay!!!
    This works better if the loop is placed in the capture/movie event.

    Dan… You are the emperor of teaching. This series in particular has been so helpful to me. I have tried to implement a nearest point algorithm in the past and failed, but I was easily able to fallow along and actually learn and understand well the process. Thanks so so so so so much… again!!!!!!!!!!!

Comments are closed.