![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194296/image.jpeg)
How to publish image to ROS in Simulink
2 ビュー (過去 30 日間)
古いコメントを表示
I use the function writeImage() in matlab function to write a MATLAB image to the ROS image message,but when I run the simulink model, an error appears: Undefined function or variable 'writeImage'. How to solve this problem? How to publish image to ROS in Simulink?
0 件のコメント
回答 (1 件)
JAI PRAKASH
2018 年 11 月 4 日
If your matlab image is 'RGB' matrix, you can use following matlab function block + Bus assignment block as shown in figure.
function [H, W, Enc, EncLength, IsBig, Step, Data, DataLength] = fcn(im)
[H, W, n] = size(im);
H =uint32(H); W =uint32(W);
im = permute(im,[2 1 3]);
Data1 = im(:);
Data2 = reshape(Data1,[H*W,n])';
Data = Data2(:);
Enc = zeros(1,128, 'uint8');
Enc(1:4) = uint8('rgb8'); % uint8('rgb8')
EncLength = uint32(4);
IsBig = uint8(0);
Step = uint32(W*n);
DataLength = uint32(H*W*n);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194296/image.jpeg)
See the attached simulink readymade block also to convert MAT image to ros image message.
3 件のコメント
Syed Adil Ahmed
2020 年 10 月 21 日
For those interested you can fix the non matching size of the Data bus variable by changing array sizes in Simulink for ros. This option is under tools> ROS in simulink.
参考
カテゴリ
Help Center および File Exchange で Specialized Messages についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!