移動目標檢測(幀間差分法)__移動目標檢測

來源:互聯網
上載者:User

以前上電腦視覺課時,老師示範了一個移動目標檢測的程式。覺得好玩,回去後自己寫了一個。
基於幀間差分法+閾值(門限)的移動目標檢測。檢測前進行了中值濾波處理,手動設定了閾值。效果一般吧。

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幀',i-1))    %差分演算法    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幀',i-1))end

代碼和測試資料下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.