A beginner guide to motion detection using OpenCV.
For a beginner, which was when I was studying at my university. I studied about OpenCV and its application and decided to work in a computer vision related project.
Motion Detection is magic when used in a way that is required, it can be used in vehicle counting system, anomaly detection during exam hall (which is - I don't recommend, you know what I mean). But on a serious side this sort of libraries can be used in surveillance system which can be utilized more efficiently that your neighbor's eyes.
Video is all about images that are captured continuously, also known as frames. You know FPS - its that images per second that we are talking about here.
Lets have quick look into pseudo code-
- First we initiate our libraries (pandas, numpy, cv2 (computer vision)).
- We declare initial state and motion track list.
- to initialize the camera module its simple than you can ever imagine (cv2.VideoCapture(0)). {bam, pretty cool, right?}
- We use while loop to continuously loop through every images captured.
- We can also use various color conversion in cv2 like, grayscale, gaussian blur etc.
- We now store each frames in initial state to capture initial state of the video captured.
- Now we create threshold frame using absolute difference between initial state and current scaled frame.
- We create a contours using that threshold frame and loop through it to decide a rectangle boundary to any object in motion.
- Jeez, you made it through all these lecture, now lets look at the code.
follow through my github, for the code - github
Happy Coding!
Top comments (0)