How do I modify object arrays to support C/C++ code generation?

조회 수: 4 (최근 30일)
cui,xingxing
cui,xingxing 2022년 10월 26일
댓글: cui,xingxing 2022년 10월 26일
I want to remove some indexed subscript elements in object arrays, where the element type in arrays is matlab built-in ORBPoints type, it is very easy to delete these indexed elements in MATLAB environment, and then when I am ready to generate C code, I found that object arrays is not supported to generate.
I checked the relevant documentation in detail and tried hard to convert object arrays to cell arrays, but it was not easy to convert each ORBPoints to cell arrays.
Any help would be greatly appreciate!
Pseudocode:
Image = imread('someImg.jpg');
myClassArray = detectORBFeatures(Image); % myClassArray is ORBPoints arrays
if coder.target("MATLAB") % MATLAB environment is easy to remove some elements
myClassArray(removeIdxs) = [];
else % Code generation does not support object arrays, so convert to cell arrays
n = numel(myClassArray);
points1Cell = cell(1,n);
for i = 1:n
points1Cell{i} = ORBPoints(...) ? % Constructing ORBPoints using the constructor is not easy, the object has many more properties that also have to be copied all according to the same properties as the elements in myClass! It's a pain!
end
end
Most of the official documentation examples are numeric type to cell arrays conversions, which are relatively simple and easy to follow, but when it comes to types that are not easy to construct, it can be tricky. I have also tried the mat2cell function, but unfortunately this built-in function does not support C/C++ code generation!
  댓글 수: 1
cui,xingxing
cui,xingxing 2022년 10월 26일
This problem can be solved and may not be an optimal solution is write a function in terms of object arrays, NOT USING CELL ARRAYS THAT REFER TO DOCUMENTION.
function dstORBPoints = getSubInds(srcORBPoints,validIdxs)
%#codegen
Location = srcORBPoints.Location(validIdxs,:);
Metric = srcORBPoints.Metric(validIdxs);
Scale = srcORBPoints.Scale(validIdxs);
Orientation = srcORBPoints.Orientation(validIdxs);
dstORBPoints = ORBPoints(Location,"Metric",Metric,"Orientation",Orientation,"Scale",Scale);
end

댓글을 달려면 로그인하십시오.

답변 (0개)

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by