vision.blobanalysis used in ROS code generation does not support dynamicMemoryAllocation for AllVariableSizeArrays, but needed for ROS code gen
1 view (last 30 days)
I want to use vision.blobanalysis in a matlab script to do some image processing on some images recived from ROS. I want use matlab coder to generate ROS code for deployment.
However when complieing it, it throws an error regarding the binary image input into the vision.blobanalysis object.:
??? This System object method does not support input of unbounded size.
Configure 'DynamicMemoryAllocation' to a mode other than 'AllVariableSizeArrays' to allow automatic size propagation.
The relevant part of the code is as follows:
BlobAnalysis = vision.BlobAnalysis('ExtentOutputPort',1,'OrientationOutputPort',1,'Connectivity',4,'MaximumCount', 3,'MaximumBlobArea', 12000000,'MinimumBlobArea', 10000);
[~,centroid,bbox,~,extent] = step(BlobAnalysis,BW);% error thrown for this line
I think the problem is that for ROS code gen, it requires dynamicMemoryAllocation enabled for AllVariableSizeArrays. So am unable to change this mode. However this seems to have caused the binary image input in to this function to be of an unbounded size, which seems to not be accepted by this function for code gen.
I know that the size of the binary image is fixed as a 360x640 logical, and so i have tried to fix the size using
Or using the other method using assert
assert(size(BW,1) <= 2000 & size(BW,2) <= 2000)
using both after BW's first delceration.
However neither work and still give me the same compile error.
So my question is does anyone know a way around this, or perhaps i am simply unable to use vision.BlobAnalysis, and might need to find an alternative.
Thanks so much for any help anyone can give me.
Josh Chen on 9 Feb 2022
Since the "step" function does not want "unbounded" input, one idea that worth trying is to create an empty fixed size image, filling this image by the values in "BW", and then always pass the fixed size image into the "step" function. This way the size is always "bounded". The code would be something similar to:
% Create default empty image
defaultImage = zeros([360,640]);
% Fill the default image with values from BW
minRow = min(size(defaultImage,1), size(BW,1));
minCol = min(size(defaultImage,2), size(BW,2));
defaultImage(1:minRow,1:minCol) = BW(1:minRow, 1:minCol);
% Pass to "step" function
[~,centroid,bbox,~,extent] = step(BlobAnalysis,defaultImage);
Hope this helps,