Opencv Motion Target Detection

Source: Internet
Author: User

Common Methods for moving object detection include optical flow, background subtraction, and frame difference ). The Background Subtraction Method and the interframe difference method are suitable for static cameras, while the optical flow method is used for camera motion, but the calculation is relatively large.

The following describes how to use the cvupdatemotionhistory function in opencv to detect motion targets. Cvupdatemotionhistory is used to update motion history images. Its prototype is:

Void cvupdatemotionhistory (
Const cvarr * silhouette,
Cvarr * MHI,
Double timestamp,
Double duration );

The parameters are described as follows,

Silhouette, a motion contour image obtained by difference between frames.

MHI, short for motion histoty image, indicates the motion history image.

Timestamp.

Duration, the maximum time that pixels that have been moved can be maintained.

The relationship between the output motion history image MHI and the input motion contour image silhouette can be expressed as follows:

(1) MHI (x, y) = timestamp if silhouette (x, y )! = 0. That is, when the motion contour image is not zero at the coordinate (x, y), the time mark timestamp of MHI at (x, y.

(2) MHI (x, y) = 0 if silhouette (x, y) = 0 and MHI (x, y) <(timestamp-duration ). because timestamp is constantly increasing over time, the maximum duration of pixels that have been moved is duration. when the duration of MHI (X, Y) is longer than duration, MHI (X, Y) is zero if no new motion occurs at (x, y.

(3) MHI (x, y) = MHI (x, y) otherwise. as long as the duration of the moving pixel does not exceed duration, the MHI (x, y) size is maintained at the time point of the motion.

The following provides the code based on opencv2.0. The code references the routines in the opencv installation directory and makes some changes to facilitate other projects to directly call functions for moving target detection.

# Include <cv. h> # include 

The program runs as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.