物体检测软件

时间:2014-06-03 07:15:01

标签: matlab computer-vision object-detection matlab-cvst

我想创建一个运动检测软件,通过直播相机获取输入视频。该软件必须执行以下操作:

1-当检测到其移动时,它会在有移动的区域周围绘制一个矩形。 - 为了绘制矩形,我想使用vision.CascadeObjectDetector,因为他们用它来进行人脸识别,但问题是我不知道CascadeObjectDetector是否与我的代码一起工作制作(视频输入)。应该用imaqVideoDevice吗? -

2-注册屏幕在整个恒定时间内移动的次数,并返回一分钟内移动的次数。就像每分钟进行一次运动计数一样。 - 正如你在代码中看到的那样,我使用了tic-toc函数来制作计数器和" cont"变量来计算已注册的动作。我想知道,为了完成反击,我需要做些什么...-

虽然我对Matlab不熟悉,但我知道它的图书馆充满了潜力,我愿意更多地了解它。 这是我的代码。你们可能想忽略评论的部分,因为它是巴西葡萄牙语。

提前致谢。


我管理了重建vision.ForegroundDetector的代码,但现在我遇到了问题...我不知道如何在subplot(1,2,1); imshow(FrameRGB); title('Imagem Recebida')唯一的事情来重现其结果我知道我不会使用imshow ...

%O botão Fechar, deve finalizar o código e parar a câmera
uicontrol('String', 'Fechar',...
          'Callback', 'stop(camera)',...
          'Callback', 'close');
camera = videoinput('winvideo', 1, 'MJPG_320x240');

Detect = vision.ForegroundDetector(...
       'NumTrainingFrames', 100, ... % 5 because of short video
       'InitialVariance', 30*30); % initial standard deviation of 30
hblob = vision.BlobAnalysis(...
       'CentroidOutputPort', false, 'AreaOutputPort', false, ...
       'BoundingBoxOutputPort', true, ...
       'MinimumBlobAreaSource', 'Property', 'MinimumBlobArea', 250);
hsi = vision.ShapeInserter('BorderColor','White');

set(camera,'TriggerRepeat', Inf);
camera.FrameGrabInterval = 1.5;

cont = 0; %cont é a variável que vai armazenar o movimento
A = 0;
timerEnd = 0;

start(camera)
timerStart = tic;
hsnk = vision.VideoPlayer();

while(camera.FramesAcquired>=0)

        FrameRGB = getsnapshot(camera);
        fgMask = step(Detect, FrameRGB);
        bbox   = step(hblob, fgMask);
        out    = step(hsi, FrameRGB, bbox); % draw bounding boxes around cars
        %drawnow;
        subplot(1,2,1); imshow(hsnk); title('Imagem Recebida')
        text(cont, timerEnd,...
        ['Contador:', num2str(cont/timerEnd)],...
        'HorizontalAlignment', 'left');


        IM = getdata(camera,2);
        IMGray = rgb2gray(IM(:,:,1:3));
        IMbw=im2bw(IMGray,0.5);
        IMneg=imadjust(IMGray,[0 1],[1 0]);

        i1=IM(:,:,:,1);
        i2=IM(:,:,:,2);
        i1=rgb2gray(i1(:,:,1:3));
        i2=rgb2gray(i2(:,:,1:3));
        m=abs(double(i1)-double(i2))/256;
        subplot(1,2,2);imshow(m);title('Detecção de Movimentos')



        if sum(sum(m))>700

            cont = cont+1;
            A = mod(cont,0);
        end

        timerEnd = toc(timerStart);
        fprintf('Em %d minutos e %f segundos, obteve-se %14.0f movimentos  \n', floor(timerEnd/60), rem(timerEnd,60), A);

end

stop(camera)

%O botão Fechar, deve finalizar o código e parar a câmera
uicontrol('String', 'Fechar',...
          'Callback', 'stop(camera)',...
          'Callback', 'close');
camera = videoinput('winvideo', 1, 'MJPG_320x240');

Detect = vision.ForegroundDetector(...
       'NumTrainingFrames', 10, ... % 5 because of short video
       'InitialVariance', 4.5*4.5); % initial standard deviation of 30

hblob = vision.BlobAnalysis(...
       'CentroidOutputPort', false, 'AreaOutputPort', false, ...
       'BoundingBoxOutputPort', true, ...
       'MinimumBlobAreaSource', 'Property', 'MinimumBlobArea', 250);
hsi = vision.ShapeInserter('BorderColor','White');

set(camera,'TriggerRepeat', Inf);
camera.FrameGrabInterval = 1.5;

cont = 0; %cont é a variável que vai armazenar o movimento
A = 0;


start(camera)
timerStart = tic;
% hsnk = vision.VideoPlayer();


while(camera.FramesAcquired>=0)

        FrameRGB = getsnapshot(camera);
        fgMask = step(Detect, FrameRGB);
        bbox   = step(hblob, fgMask);
        out    = step(hsi, FrameRGB, bbox); % draw bounding boxes around cars
        subplot(1,2,1);imshow(out);title('Imagem x')


        IM = getdata(camera,2);
        IMGray = rgb2gray(IM(:,:,1:3));
        IMbw=im2bw(IMGray,0.5);
        IMneg=imadjust(IMGray,[0 1],[1 0]);

        i1=IM(:,:,:,1);
        i2=IM(:,:,:,2);
        i1=rgb2gray(i1(:,:,1:3));
        i2=rgb2gray(i2(:,:,1:3));
        m=abs(double(i1)-double(i2))/256;
        subplot(1,2,2);imshow(m);title('Detecção de Movimentos')



        if sum(sum(m))>700

            cont = cont+1;
            A = mod(cont,0); 
        end

         if toc(timerStart) == 15.0000
            plot(A, timerEnd, 'c');
            cont = 0;      
            A = 0;
        end 

        timerEnd = toc(timerStart);
        fprintf('Em %f segundos, obteve-se %14.0f movimentos  \n',rem(timerEnd,60), A);
        %fprintf('Em %d minutos e %f segundos, obteve-se %14.0f movimentos  \n', floor(timerEnd/60), rem(timerEnd,60), A);

end


stop(camera)

唯一的问题是计数器,我试图通过这一行构建:

 if timerEnd == 15.0000
                plot(A, timerEnd, 'c');
                cont = 0;      
                A = 0;
            end 

它有什么问题,或者它只是位于不能使其正常工作的地方? 再次感谢!

1 个答案:

答案 0 :(得分:0)

vision.CascadeObjectDetector用于检测特定的对象类别,例如面部,眼睛,鼻子等。对于运动检测,您应该使用vision.ForegroundDetector,这将为您提供二进制遮罩,将像素标记为背景(固定)或前景(移动)。但是,这仅在您的相机不移动时才有效。

有关详细信息,请参阅此example

请参阅此example了解如何将vision.VideoPlayer放入自定义用户界面。