首页 > 解决方案 > Matlab trimesh投影矩阵

问题描述

我正在使用一个代码库,它使用 Matlab 的trimesh函数将 3D 形状投影到 2D 图像。执行此操作的代码段:

function h = plotMesh(mesh, style, az, el)
h = trimesh(mesh.F', mesh.V(1,:)', mesh.V(2,:)' ,mesh.V(3,:)', 'FaceColor', 'w', 'EdgeColor', 'none', ...
    'AmbientStrength', 0.3, 'DiffuseStrength', 0.6, 'SpecularStrength', 0.0, 'FaceLighting', 'flat');
set(gcf, 'Color', 'w', 'Renderer', 'OpenGL');
set(gca, 'Projection', 'perspective');    
axis equal;
axis off;
view(az,el);
camlight('HEADLIGHT');

上面的代码片段调用如下:

ims = cell(1,length(opts.az));
for i=1:length(opts.az),
    plotMesh(mesh,'solid',opts.az(i),opts.el);
    ims{i} = print('-RGBImage', '-r100');  %in case of an error,you have an old matlab version: comment this line and uncomment the following 2 ones
    %saveas(opts.figHandle, '__temp__.png');
    %ims{i} = imread('__temp__.png');
    if strcmpi(opts.colorMode,'gray'), ims{i} = rgb2gray(ims{i}); end
    ims{i} = resize_im(ims{i}, opts.outputSize, opts.minMargin, opts.maxArea);
end

上面的opts数据结构初始化如下,其中两个参数是方位角和仰角:

opts.az = [0:30:330];
opts.el = 30;
opts.use_dodecahedron_views = false;
opts.colorMode = 'rgb';
opts.outputSize = 224;
opts.minMargin = 0.1;
opts.maxArea = 0.3;
opts.figHandle = [];

但是,我想要[x,y,z][xImage,yImage]的映射或用于执行此投影的实际矩阵trimesh,因此我可以自己计算此映射。我的网格中有其他标签,与每个[x,y,z]相关联,我想将这些标签转移到[xImage,yImage]。除非我知道明确的 3D 到 2D 映射,否则我不能这样做。我如何得到这个映射?我使用的代码库没有设置任何相机参数,所以trimesh我认为使用的矩阵是 Matlab 固有的。

注意:网格是一个包含面、顶点和法线列表的数据结构,并使用此处定义的此函数从“关闭”文件加载: https ://github.com/suhangpro/mvcnn/blob/abbebe3278fda70a42f62c2432ba6dd2247f072f/utils/加载网格.m

TLDR;trimesh使用然后绘图将网格绘制为 2D 投影。对于输入中的每个 [x,y,z] 坐标,我想知道它映射到的输出图像中的 [x,y] 坐标。

标签: matlabopenglmatlab-figureprojection

解决方案


推荐阅读