MATLAB: Finding Centroids using text inserter

centroidcomputer visionComputer Vision Toolboxvision.textinserter

Hello everyone, I wanted to ask a question about the vision.TextInserter. The following is some basic codes:
blob = vision.BlobAnalysis('CentroidOutputPort', true, 'AreaOutputPort',...
false,'BoundingBoxOutputPort', false,'MinimumBlobAreaSource', 'Property',...
'MinimumBlobArea', 20000);
textinCentroid = vision.TextInserter('Text', 'X:%4d, Y:%4d', ...
'LocationSource', 'Input port', ...
'Color', [1 0 0], ...
'FontSize', 14);
while ~isDone(videoReader)
frame = step(videoReader);
I = finalimage; %Final result of image after process
centroid = step(blob, I);
result = step(textinCentroid, frame, centroid)
step(videoPlayer, result);
end
So the problem is that I got the following problem:
Error using vision.TextInserter/step
Not enough input arguments; expected 3 (in addition
to the object handle), got 2.
Error in ComputerVision2 (line 64)
result = step(textinCentroid, frame,
centroids);
So can anyone tell me what exactly am I missing here? What do I have to add to make it in such a way that my object detected have a centroid on it? Thank you.

Best Answer

You need the object first. You need the image second. Subtotal 2
You used %-style sequences in your string, so you need a vector of values, one per % in the string. You also need the location for the input port. Subtotal 2.
Total 4.
What I do not see documented is which order to use if you have both loc and vars. Experiment. I'm going to guess loc should be first.