Trying to get imageToVehilce to C/C++ code generate in Simulink
1 回表示 (過去 30 日間)
古いコメントを表示
I've been working with the example "TransformAnImageOfARoadToABirdseyeviewImageExample.mlx". I've taken the parts that I would like to use out of it for getting an image pixel to the vehicle location frame. The bird's eye view image is not necessary to output for the application (might be added later for debugging, but currently not necessary).
As I've been trying to compile the project it is saying that the compiler doesn't have enough information to know the size of the cameraIntrinsics or monoCamera. I've set the hardware implementation to be ROS. The xypixels is set to be inherited from the prevoius block (which is a 28x2). I've been trying to get a setting for dynamic memory. Is there a way to initialize the variables? Or set for dynamic memory allocation?
function xyvehicle= image2distance(xypixels)
%#codegen
%Transform Road Image to Bird's-Eye-View Image
%Create a bird's-eye-view image from an image obtained by a front-facing camera mounted on a vehicle. Display points within the bird's-eye view using the vehicle and image coordinate systems.
%Define the camera intrinsics and create an object containing these intrinsics.
focalLength = [309.4362 344.2161];
principalPoint = [318.9034 257.5352];
imageSize = [480 640];
camIntrinsics = cameraIntrinsics(focalLength,principalPoint,imageSize);
%Set the height of the camera to be about 2 meters above the ground. Set the pitch of the camera to 14 degrees toward the ground.
height = 2.1798;
pitch = 14;
%
%Create an object containing the camera configuration.
sensor = monoCamera(camIntrinsics,height,'Pitch',pitch);
%
% %Define the area in front of the camera that you want to transform into a bird's-eye view. Set an area from 3 to 30 meters in front of the camera, with 6 meters to either side of the camera.
distAhead = 30;
spaceToOneSide = 6;
bottomOffset = 3;
outView = [bottomOffset,distAhead,-spaceToOneSide,spaceToOneSide];
%Set the output image width to 250 pixels. Compute the output length automatically from the width by setting the length to NaN.
outImageSize = [1024,250];
%Create an object for performing bird's-eye-view transforms, using the previously defined parameters.
birdsEye = birdsEyeView(sensor,outView,outImageSize);
xyvehicle = imageToVehicle(birdsEye,xypixels);
2 件のコメント
Matthew DiBello
2022 年 5 月 31 日
How are you generating C/C++ code? Based on your description, it seems that this MATLAB function is included in a Simulink model. Is this correct?
I can generate code for this snippet using a simple MATLAB Coder example, so I think there is more context required to see how the problem is occurring. Can you share a simple model that demonstrates this issue?
You also mentioned trying to configure dynamic memory allocation. Are you trying to enable (or disable it)?
Cheers!
Matthew
回答 (1 件)
Ashutosh Thakur
2024 年 1 月 23 日
編集済み: Ashutosh Thakur
2024 年 1 月 23 日
Hi,
I can understand that you want to enable the dynamic memory allocation for the variables which are either part of MATLAB Function or a M-File.
By default there is a limitation in Simulink to support the variables having dynamic size.The variable which needs to have dynamic allocation of memory has to be allocated the maximum size that those variables could achieve in the context of the program. I would like to suggest some approaches to have a dynamic memory allocation for the variables in Simulink for code generation:
- Open the Simulink Model and in the Modelling Tab and click on the Model Explorer button, and a dialog box would get opened.
- In the dialogue box, select those variables which need to be dynamically allocated by clicking on it and select the checkbox of "Variable size" present in the right side of the dialog box.
- You can also use the "coder.varsize" function to explicitly define the variables to have variable-size data.
- Additionally, if you are increasing the size of an array, make sure to do so by using the "end + 1" operation in the MATLAB code.
Kindly refer the following links to have more detailed information in handling dynamic memory allocation in Simulink:
- https://www.mathworks.com/help/simulink/ug/defining-variable-size-data-for-code-generation.html
- https://www.mathworks.com/help/simulink/ug/use-dynamic-memory-allocation-for-variable-size-arrays-in-a-matlab-function-block.html
- https://www.mathworks.com/help/simulink/ug/what-is-variable-size-data.html#bvm9txx-1
- https://www.mathworks.com/help/simulink/slref/coder.varsize.html
I hope the above suggestions help you in resolving issues related to the dynamic memory allocation.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!