Finding Centroids using text inserter?
2 views (last 30 days)
Show older comments
Akira Chan
on 28 Jul 2015
Commented: Akira Chan
on 28 Jul 2015
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.
0 Comments
Accepted Answer
Walter Roberson
on 28 Jul 2015
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.
3 Comments
Walter Roberson
on 28 Jul 2015
Setting CentroidOutputPort for the blobanalysis means that when you step() the blob analysis class object, the output of step() will be the centroid.
Setting 'LocationSource' to 'Input Port' for the TextInserter class object means that you will pass the location in as a parameter to step() instead of the class object retrieving the location from the Location property of the class object.
With those and with a String that did not include % codes, your existing code would be fine,
centroid = step(blob, I);
result = step(textinCentroid, frame, centroid);
that is you would return the value from the step() of the blob analysis class object, and you would pass that value in to the text inserter class object.
This would be the syntax for specifying where the text is to be placed.
When you use % strings for string in the text inserter, you need to pass the step() call to the inserter class object a vector containing the values to be substituted in at the point of the %. You do not use Input Port for this, that is not what it is for. Input Port is for the position.
If you want position the given text at the centroid, and you want the values of the text to be the locations of the centroid, then pass the centroid twice to the step() of the inserter class object:
result = step(textinCentroid, frame, centroid, centroid);
It turns out, by the way, that the parameters for the % format should go before the location for Input Port. See the example http://www.mathworks.com/help/vision/ref/vision.textinserter-class.html#btk0zqa-1 which uses both % and the Input Port.
More Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!