<< Chapter < Page | Chapter >> Page > |
The Python OpenCV library exposes an API for the entire Canny edge detection algorithm. The Canny algorithm issimilar to, but more nuanced than, our algorithm, substituting our selective thresholding procedure for hysteresis. However,the end results are very similar. As is evident from Listing 5, the procedure is very straightforward.
Listing 5. python implementation of canny edge detection with opencv
LOW_THRESHOLD = 100
HIGH_THRESHOLD = 200edges = cv2.Canny(img, LOW_THRESHOLD, HIGH_THRESHOLD)
Our motion detection algorithm compares the edges from two frames temporally separated by a small interval of time and attempts to estimate regions of the frame that exhibitmovement or motion. This process is then repeated continuously to provide a real-time visualization of the regions ofmovement in a continuous video stream. The motion detection algorithm we present is composed of the following steps:
F1 and F2 are obtained by sampling frames from a continuous video stream, a task aided by the OpenCV C library.Thus, the time interval Δt will be small enough for a realtime algorithm. The edges E1 and E2 are computed with theedge detection algorithm of Section II. Below, we explore, in greater depth, the procedures for building a thresholdeddiffrence matrix and finally estimating the motion area by analyzing a spatial difference density map.
The preliminary requirement in determining areas of motion from two frames is a systematic method of determining andquantifying the differences between two frames separated by a small Δt. Intuitively, areas of motion within the time intervalΔt should exist at locations at which the difference between the two frames is large. This process is then continuouslyrepeated for every pair of input frames in order to create a realtime motion detector. In our algorithm, we quantify differenceson a binary basis using edge data from our edge detection algorithm, then determine motion locations from a thresholdeddensity map of the difference matrix D. More formally, we begin with a matrix D0 created from asimple comparison of E1 and E2. Then, for each location (i, j) in D0, a thresholded differencematrix D is created by considering a box of constant size b x b around that pixel and suppressing the value of the surroundingpixels to 0 if its value matches that at D0[i,j]. This step isdesigned to reduce false positives of motion detection arising from stray movement of the frame (e.g. camera shake). Thecomputation of D is demonstrated in Algorithm 2. The output matrix is then used as input to building a spatial differencedensity map, from which we estimate motion locations.
Notification Switch
Would you like to follow the 'Elec 301 projects fall 2015' conversation and receive update notifications?