This python program will allow you to detect any motion that occurs in front of the builtin webcam and also store the time interval of the motions while creating a plot of the time interval using Bokeh Plot.
- Python3
- OpenCV(libraries)
- Pandas(libraries)
Install Requirments: Install Python3, install Pandas and OpenCV libraries.
Videos can be treated as stack of pictures called frames. Here i am comparing different frames(pictures) to the first frame which should be static(No movements initially). We compare two images by comparing the intensity value of each pixels.
After running the code there 4 new window will appear on screen. Output of each frame is added in this repository.
-
Gray Frame: In Gray frame the image is a bit blur and in grayscale we did so because, In gray pictures there is only one intensity value whereas in RGB(Red, Green and Blue) image thre are three intensity values. So it would be easy to calculate the intensity difference in grayscale.
-
Difference Frame: Difference frame shows the difference of intensities of first frame to the current frame.
-
Threshold Frame: If the intensity difference for a particular pixel is more than 30(in my code) then that pixel will be white and if the difference is less than 30 that pixel will be black.
-
Color Frame: In this frame you can see the color images in color frame along with green contour around the moving objects.
The Time_of_movements file will be stored in the folder where your code file is stored. This file will be in csv extension. In this file the start time of motion and the end time of motion will be recorded.
Time Intervals will be plotted using Bokeh Plot. Bokeh is an interactive visualization library that targets modern web browsers for presentation. Here, the time intervals are collected by the csv file and then plotted using Bokeh. The green color shows that an object was under motion, time is displayed in milisecond(ms). a screenshot of output is added in this repository.