Question

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

Was it helpful?

Solution

Form the top of the page you linked to:

This example is a function with the main body at the top and helper routines in the form of nested functions below.

In other words the readFrame function is meant to be a nested function inside of the function where you create your obj.reader object. Alternatively, you could pass in obj.reader as an argument. If you look at the code that generated the obj.reader object (setupSystemObjects), it is also a nested function, but it returns obj to the outer main function. By the way, if you want to view all of the code together in the Matlab editor, just type edit multiObjectTracking in command window.

Nested functions have access to all of the variables (workspace) of the outer function. This blog post discusses them in more detail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top