Matlab trimesh投影矩阵

时间:2018-11-05 15:51:23

标签: matlab opengl matlab-figure projection

我正在使用使用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映射,否则我无法这样做。如何获得此映射?我使用的代码库未设置任何相机参数,因此所使用的矩阵是Matlab的trimesh固有的。

注意:网格是具有面,顶点和法线列表的数据结构,并使用以下定义的此功能从“ OFF”文件加载: https://github.com/suhangpro/mvcnn/blob/abbebe3278fda70a42f62c2432ba6dd2247f072f/utils/loadMesh.m

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

0 个答案:

没有答案