필터 지우기
필터 지우기

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 CenterFile Exchange에서 MATLAB 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