如何使用matlab vision.ForegroundDetector用网络摄像头代替输入视频文件。
hsrc = vision.VideoFileReader('viptraffic.avi','ImageColorSpace','Intensity','VideoOutputDataType','uint8');
hfg = vision.ForegroundDetector(...
'NumTrainingFrames', 5, ... % 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');
hsnk = vision.VideoPlayer();
while ~isDone(hsrc)
frame = step(hsrc);
fgMask = step(hfg, frame);
bbox = step(hblob, fgMask);
out = step(hsi, frame, bbox); % draw bounding boxes around cars
step(hsnk, out); % view results in the video player
end
release(hsnk);
release(hsrc);
答案 0 :(得分:3)
如果您有权访问图像采集工具箱,则可以将第一行替换为:
hsrc = imaq.VideoDevice('winvideo', 1, 'MJPG_640x480', ...
'ReturnedColorSpace','grayscale', 'ReturnedDataType','uint8');
您需要根据网络摄像头支持的格式调整参数。只需查阅imaq.VideoDevice
函数的文档。
同样只用while true
替换循环测试,因为视频Feed始终没有完成:)