OpenCV: Implementing Motion Detection using Motion Templates

OpenCV: Implementing Motion Detection using Motion Templates


According to Wikipedia, 'Motion Detection is actually a process of confirming the position of an object relative to its surroundings'. of which post discusses the concepts involved as well as the implementation of Motion Detection in a video using Open CV as well as C++, as implemented from the sample code in OpenCV samples folder, "motempl.c" .

There are several ways of implementing motion detection using Open CV. One of the most effective methods is actually by using 'Motion Templates'. of which method was invented from the MIT Media Lab by Bobick as well as Davis. of which method is actually very useful in detection motion in a video. The important feature of of which technique is actually of which motion can be detected even in little regions of a frame.

Silhouette:
Silhouettes are the basic requirements for motion detection using Motion Templates. One of the easiest ways of finding object silhouettes is actually by taking the absolute difference from the frames of 2 images. The function which does of which is actually cvAbsDiff. of which function takes 2 images by the buffer as input, as well as gives the silhouette of cvArray type as the output. Then, thresholding is actually carried out using the cvThreshold function, which converts the image to a binary image. of which gives us an object silhouette which is actually from the binary form.
Motion History Image:
The concept of Motion History Image (MHI) forms the basis of Motion Detection using Motion Templates. Let us assume of which an object silhouette is actually created which is actually most recent. A 'timestamp' is actually used to identify if the image is actually recent or not, which is actually basically the current system time, measured upto milliseconds. The various other older silhouettes are necessary to be compared with of which silhouette in order to achieve motion detection. Hence, older silhouettes are also saved from the image, with an older timestamp.
We can say of which the sequence of these silhouettes along with the timestamp, which record the previous motion is actually referred to as the "Motion History Image". Hence, the Motion Templates have to be constructed, taking the silhouettes as well as the timestamp. The OpenCV function which does of which is actually cvUpdateMotionHistory. of which function takes the silhouettes as well as the timestamp, along with the duration upto which the motion history has to be recorded, as the input. The output of of which function is actually the 'Motion History Image' of simply mhi.
Calculation of Motion Gradient:
today, of which we have a mhi, which has the collection of object silhouettes along with their timestamp, we can detect overall motion by taking the gradient of the mhi image. however then, some gradients are very high, when the older inactive parts are set to 0. of which produces large gradients over the edges. Since we know the duration upto which the mhi records the silhouettes, we can find out how large the gradients are, as well as hence can set an upper as well as lower limit to the gradient. Hence, large gradients are eliminated. Then, we can calculate the overall motion by taking the gradient.
The OpenCV function which does of which, is actually the cvCalcMotionGradient. of which function takes the mhi image, delta1 & delta2 (the maximum as well as minimum gradient values) as well as the variable aperture size according to the size of the gradient operator(depending on gradient functions like Scharr as well as Sobel filers) as the input. The output of the function is actually the mask which has the allowed gradients, the ones which are valid. Also generated is actually the orientation, which has the output gradient's direction angle.
Global Orientation:
The global orientation can be calculated by the output of the cvCalcMotionGradient function. The OpenCV function used to calculate Global Orientation is actually cvCalcGlobalOrientation. of which function take the orientation, mask along with the timestamp as well as duration used to create a MHI template, as well as resulting mhi as the input. The returned output is actually the vector-sum global orientation.
Detecting Local motion using Segmentation:
Most of the times, we will also need to calculate local motion within the regions. Hence to do of which, first, the mhi is actually scanned for current silhouette regions (the ones with most recent timestamp). When the region with most current timestamp is actually found, the perimeter is actually searched for most recent motion. When the idea is actually found, floodfill is actually done to isolate the region of motion found. Once  found, we can compute the local motion gradient direction from the spill-off region, remove the region as well as repeat till all the regions are found. of which method is actually like segmenting the image which a motion is actually found in a particular location from the mhi.
The OpenCV function which does of which is actually the cvSegmentMotion. of which function takes the mhi image, the timestamp, the segmentation threshold (maximum downward step by previos motion - used to avoid overlap of motion detected regions), as well as a storage object as the input. the idea returns a cvSeq* of the cvConnectedComp structures, one for each motion. the idea also returns a segmask, one for each region where motion is actually found.
After we obtain the cvConnectedComp structures, we have a 'for' loop, which iterates through these structures one by one extracting bounding rectangles for each motion. For each local segments, motion is actually calculated using cvCalcGlobalOrientation. Instead of using the specific masks, of which restricts motion only to specific regions of interest(ROI) of which binds the local motions. then the idea calculates where valid motion within ROI's was actually found. The regions where the motion is actually too little, are rejected. Finally, motion is actually drawn on the image.
of which code can be found from the .../OpenCV/samples/c/.. folder in your OpenCV installation directory. The program is actually named as 'motempl.c' .
Note: of which is actually summary of the explanation of which has been mentioned from the Learning OpenCV book by O' Reilly Media Inc. For detailed explanation with diagrams, please refer the book.

Sign up here with your email address to receive updates from this blog in your inbox.

0 Response to "OpenCV: Implementing Motion Detection using Motion Templates"

Posting Komentar