Moving target detection (inter-frame difference method) __ Moving target detection

Source: Internet
Author: User
Tags abs sprintf

Before the computer vision class, the teacher demonstrated a moving target detection program. Feel fun, go back and write a.
Moving target detection based on frame difference method + threshold (thresholds). The median filter was processed before the detection, and the threshold value was set manually. Effect of the general bar.

Clear all;
Close all;
CLC;
Mov=videoreader (' Classroom.avi ');
N=mov. Numberofframes;


For I=2:n
    Frame=read (mov,i);
    Pframe=read (mov,i-1);
    If Ndims (frame) ==3
        X=rgb2gray (frame);
    else
        X=frame;
    End
    If Ndims (pframe) ==3
        Y=rgb2gray (pframe);
    else
        Y=pframe;
    End
    subplot (1,2,1);
    Imshow (pframe,[]);
     Title (sprintf ('%d frame ', i-1))
    % difference Algorithm
    x=medfilt2 (x);
    Y=medfilt2 (y);
    N=im2double (x);
    P=im2double (y);

    C=n-p;
    C=MEDFILT2 (c);
    t=10/256;

    C (ABS (c) >=t) =255;
    C (ABS (c) <t) =0;
    C=logical (c);

    X1=pframe (:,:, 1);
    X1 (c) =0;
    X2=pframe (:,:, 2);
    X2 (c) =255;
    X3=pframe (:,:, 3);
    X3 (c) =0;
    Xc=cat (3,x1,x2,x3);  

    Subplot (1,2,2);
    Imshow (xc,[]);
    Title (sprintf ('%d frame ', i-1)) End

Code and test data downloads

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.