I have been looking at the Motion-Based Multiple Object Tracking and was wondering if there was any way a live webcam feed could be used as the video file?

4 ビュー (過去 30 日間)
I have been working with the object tracking that is an example on the support page and I can get it to work while reading a video file, but since it uses the step() function in places i haven't found any way to use a live feed. Thanks in advance for any help offered.
  1 件のコメント
William Dennehy
William Dennehy 2016 年 12 月 7 日
Hi John, Did you get this working? I've been trying for a while now but the different nested functions keep conflicting with each other. I'm new to Matlab so its trick for me. Thanks.

サインインしてコメントする。

採用された回答

Dima Lisin
Dima Lisin 2016 年 2 月 2 日
編集済み: Dima Lisin 2016 年 2 月 2 日
You can certainly get the video from a webcam instead of a file. Please see the Face Detection and Tracking Using Live Video Acquisition example to learn how to use the Webcam Support Package.
In the Motion-Based Multiple Object Tracking code, you would need to replace vision.VideoFileReader with a webcam object, and the calls to the VideoFileReader's step method with the calls to snapshot .
Alternatively, the Image Acquisition Toolbox has more advanced functionality for configuring cameras and capturing video.
By the way, the step() function you are talking about, is actually a method of the vision.VideoFileReader class. You can find this methods in many classes, and it essentially tells the object to "do its thing", whatever that may be. So to find out what the step method actually does in any particular instance you should check the class of the its first argument, and see its documentation.
  2 件のコメント
John Wallace
John Wallace 2016 年 2 月 2 日
Trial>> multiObjectTracking2 Array formation and parentheses-style indexing with objects of class 'vision.ForegroundDetector' is not allowed. Use objects of class 'vision.ForegroundDetector' only as scalars or use a cell array.
Error in multiObjectTracking2/detectObjects (line 82) mask = obj.detector(frame);
Error in multiObjectTracking2 (line 13) [centroids, bboxes, mask] = detectObjects(frame);
I keep getting that error in this portion of code.
function [centroids, bboxes, mask] = detectObjects(frame)
% Detect foreground.
mask = obj.detector(frame);
% Apply morphological operations to remove noise and fill in holes.
mask = imopen(mask, strel('rectangle', [3,3]));
mask = imclose(mask, strel('rectangle', [15, 15]));
mask = imfill(mask, 'holes');
% Perform blob analysis to find connected components.
[~, centroids, bboxes] = obj.blobAnalyser(mask);
end
Here is the aquire image process.
function obj = setupSystemObjects()
% Initialize Video I/O
% objects in each frame, and playing the video.
cam = webcam();
% Create a video file reader.
obj.reader = snapshot(cam);
% Create two video players, one to display the video,
% and one to display the foreground mask.
obj.videoPlayer = vision.VideoPlayer('Position', [20, 400, 700, 400]);
obj.maskPlayer = vision.VideoPlayer('Position', [740, 400, 700, 400]);
% Create System objects for foreground detection and blob analysis
% The foreground detector is used to segment moving objects from
% the background. It outputs a binary mask, where the pixel value
% of 1 corresponds to the foreground and the value of 0 corresponds
% to the background.
obj.detector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 40, 'MinimumBackgroundRatio', 0.7);
% Connected groups of foreground pixels are likely to correspond to moving
% objects. The blob analysis System object is used to find such groups
% (called 'blobs' or 'connected components'), and compute their
% characteristics, such as area, centroid, and the bounding box.
obj.blobAnalyser = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', true, 'CentroidOutputPort', true, ...
'MinimumBlobArea', 400);
function frame = readFrame()
frame = obj.reader();
end
Thank you for your response and help.
Dima Lisin
Dima Lisin 2016 年 2 月 3 日
In setupSystemObjects replace
cam = webcam();
% Create a video file reader.
obj.reader = snapshot(cam);
with
obj.reader = webcam();
In readFrame replace
frame = obj.reader();
with
frame = snapshot(obj.reader);
webcam() creates the webcam object. snapshot() captures a video frame.

サインインしてコメントする。

その他の回答 (1 件)

chanaka prasad
chanaka prasad 2020 年 3 月 30 日
can i have the full code

Community Treasure Hunt

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

Start Hunting!

Translated by