Codegen for Bundle Adjustment

I am facing two issues when using codegen on my code. I have attached images of my code for reference.
1) The error report recognises cameraPoses as a struct even though it is a 2x2 table when I run the code. When I take the values in cameraPoses and make camPoses (as shown in the image), that is recognised as a table.
2) Once I use camPoses in Bundle Adjustment, I get a codegen error that says 'This function does not support one-dimensional indexing. I am not sure what that means because my variable dimensions match the documentation. I have also attached images of my variables and their dimensions.

 采纳的回答

Nithin
Nithin 2026-7-16,3:41
编辑:Nithin 2026-7-16,3:43
The issue is not your runtime dimensions. Instead, tt is a codegen representation/type issue.
In MATLAB R2026a, the codegen implementation of imageviewset/poses returns a struct:
struct('ViewId', viewsId, 'AbsolutePose', absPoses)
So the report calling "cameraPoses" a struct is expected, even though normal MATLAB execution shows a 2x2 table.
cameraPoses = poses(vSetKeyFrames);
viewIds = uint32(cameraPoses.ViewId(:));
numViews = numel(viewIds);
absolutePose = cell(numViews, 1);
for k = 1:numViews
absolutePose{k} = cameraPoses.AbsolutePose(k);
end
camPoses = table(viewIds, absolutePose, ...
'VariableNames', {'ViewId', 'AbsolutePose'});
[refinedPoints, refinedAbsPoses] = bundleAdjustment( ...
xyzWorldPoints, tracks, camPoses, intrinsics, ...
'FixedViewIDs', uint32(1), BAParams.full{:});
Additionally, I recommend avoiding "1:height(cameraPoses)" for codegen here. If "cameraPoses" is the codegen struct, "height(cameraPoses)" is not the number of poses. Use "numel(cameraPoses.ViewId)" and preserve the actual ViewId values so they still match "tracks.ViewIds".
“One-dimensional indexing” means codegen is seeing an object array that only supports linear indexing like "pose(k)", but something in the generated validation path is trying table/row-style indexing. Making "AbsolutePose" a cell column avoids that path failing.
Hope this resolves the issue.
Regards,
Matt.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Computer Vision with Simulink 的更多信息

提问:

2026-7-10,14:41

评论:

2026-7-18,6:57

Community Treasure Hunt

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

Start Hunting!

Translated by