Matlab coder with system objects - size of expression error

5 visualizzazioni (ultimi 30 giorni)
Hello,
I am trying to generate C code (static library) from a computer vision system toolbox object called vision.BoundaryTracer. I can generate the code just fine with variable-sizing (dynamic memory allocation etc) ticked in the coder options but I want to generate more compact cleaner code so I don't want variable-sizing, however if I un-tick this option, I then get an error: Could not determine the size of the expression..
Here is the code:
function [boundary_xy_vec] = label_trace(grey_thres_erode) %#codegen
maximum_pixel_count = 5000;
y = 200;
x = 200;
boundary_xy = zeros(5000,2,'double');
persistent hboundtrace;
if isempty(hboundtrace)
hboundtrace = vision.BoundaryTracer ('MaximumPixelCount', maximum_pixel_count, 'NoBoundaryAction', 'Fill with last point found');
boundary_xy = step(hboundtrace, grey_thres_erode, [x(1) y(1)]);
end
boundary_xy_vec = boundary_xy(:);
Now, it is having trouble allocating memory for boundary_xy the output of the step function (if you follow the error it is with the step function). This is understandable to a degree as boundary_xy could be ?*2 in size, however I set the maximum boundary size to 5000, and I setup the output variable beforehand to be 5000*2, so I'm expecting the code generation to accept that I want a 5000*2 out i.e. a static array. I have also set the necessary properties to deal with the extra values. Am I missing something here do I need to do something else to force to system preallocate the output at a certain size. For example do I have to allocate a pointer for the output..?
Any help in this matter would be greatly appreciated.
Cheers,
Gary

Risposte (2)

Wayne King
Wayne King il 7 Feb 2013
Have you tried using the following codegen command on your M-file
codegen label_trace -args {logical(zeros(500,2))} -o label_trace
  1 Commento
Gary
Gary il 16 Feb 2013
Modificato: Gary il 16 Feb 2013
Apologies about the delay in getting back to you. Thanks for you reply, however what you suggested does not work I'm afraid. I'm not sure if I follow why it would have worked though, as it appears the code only specifies the type and size of the input variable and that is not the problem.
Whether I go through codegen (with first setting the config options programmatically) or through the coder gui, I get the same error but if I set EnableVariableSizing to true then it will work. Maybe this is specific to the computer vision system toolbox code generation, is there any other way to specify an output variable of a the toolbox's step function to be static/fixed size?
Cheers,
Gary

Accedi per commentare.


Mohammad Khan
Mohammad Khan il 25 Feb 2013
The output size of this System Object (vision.BoundaryTracer) is determined at run-time and so the output buffer size is variable-sized in nature. That's why this object does not work when 'EnableVariableSizing' is disabled. To generate code from this object, it must be used with VariableSizing feature turned on.
Thanks, Mohammad

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by