how to use live video from webcam with foregrounddetector

1 Ansicht (letzte 30 Tage)
pratik varma
pratik varma am 28 Feb. 2014
Beantwortet: Dima Lisin am 1 Jul. 2014
i have to tack using live live video from webcam and track an object using foregrounddetector, my code is
vision.ForegroundDetector
clc;
close all;
imtool close all;
clear;
workspace;
fontSize = 8;
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3,'MinimumBackgroundRatio',0.9, ... 'NumTrainingFrames', 700); blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ... 'AreaOutputPort', false, 'CentroidOutputPort', false, ... 'MinimumBlobArea', 250);
vid = videoinput('winvideo', 1, 'YUY2_320x240'); %select input device hvpc = vision.VideoPlayer; %create video player object src = getselectedsource(vid); vid.FramesPerTrigger =1; vid.TriggerRepeat = Inf; vid.ReturnedColorspace = 'rgb'; src.FrameRate = '30'; start(vid)
i=0;
while (i<=20)
data = getsnapshot(vid); subplot(2,2,1); imshow(data); foreground = step(foregroundDetector, data); subplot(2,2,2); imshow(foreground); se = strel('square', 3); filteredForeground = imopen(foreground, se);
% u = 0.9; % if i == 0 % bg = zeros(size(data)); % else % bg = (1-u)*double(data) + u*bg; % end % dif = abs(data-uint8(bg) ); % % grayImage = rgb2gray(dif);% Convert to gray level % level = 0.1; % bw = im2bw( dif, level); % BW5 = imfill(bw,'holes'); % bw6 = bwlabel(BW5, 8);
bbox = step(blobAnalysis,filteredForeground); result = insertShape(data, 'Rectangle', bbox, 'Color', 'green'); % subplot(1,1,1); % imshow(result); step(hvpc, result); stop(vid) flushdata(vid); i=i+1; end

Antworten (1)

Dima Lisin
Dima Lisin am 1 Jul. 2014
You would either need to have the Image Acquisition Toolbox, or MATLAB version R2014a, which includes support for getting video from a webcam in base MATLAB.

Kategorien

Mehr zu MATLAB Support Package for IP Cameras finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by