I'm following Motion-Based Multiple Object Tracking from mathworks.com/help
Matlab r2013b gives me an error Undefined variable or class "obj.reader.step" when I try to execute main function. I'm using copy-pasted functions and a custom avi file, which seems to be valid.
The code fragment is
function frame = readFrame()
frame = obj.reader.step();
end
Where the obj is being set up like that
obj.reader = vision.VideoFileReader('sample.avi');
obj.videoPlayer = vision.VideoPlayer('Position', [20, 400, 700, 400]);
obj.maskPlayer = vision.VideoPlayer('Position', [740, 400, 700, 400]);
obj.detector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 40, 'MinimumBackgroundRatio', 0.7);
obj.blobAnalyser = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', true, 'CentroidOutputPort', true, ...
'MinimumBlobArea', 400);
Full code is in the link. I believe it is a simple problem, but I didn't use matlab for a long time. May this be the video codec? Thanks in advance for any help
Form the top of the page you linked to:
In other words the
readFramefunction is meant to be a nested function inside of the function where you create yourobj.readerobject. Alternatively, you could pass inobj.readeras an argument. If you look at the code that generated theobj.readerobject (setupSystemObjects), it is also a nested function, but it returnsobjto the outer main function. By the way, if you want to view all of the code together in the Matlab editor, just typeedit multiObjectTrackingin command window.Nested functions have access to all of the variables (workspace) of the outer function. This blog post discusses them in more detail.