フィルターのクリア

how to use live video from webcam with foregrounddetector

1 回表示 (過去 30 日間)
pratik varma
pratik varma 2014 年 2 月 28 日
回答済み: Dima Lisin 2014 年 7 月 1 日
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

回答 (1 件)

Dima Lisin
Dima Lisin 2014 年 7 月 1 日
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.

カテゴリ

Help Center および File ExchangeMATLAB Support Package for IP Cameras についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by