matlab - 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] 坐标。
解决方案
推荐阅读
- javascript - 测试失败 - ProductService 不是构造函数
- c++11 - 无论我使用哪种初始化(统一、赋值等),std::string 的初始化似乎都会生成相同的代码
- machine-learning - 如何将 Pytorch 模型参数转换为长数据类型?
- c++ - 如何将两个值相乘并以原子方式存储结果?
- reactjs - react服务和组件之间如何通信?
- react-native - 如何在本机反应中从领域数据库中读取数据?
- java - 数组的 Jackson-CSV 模式
- sql - 更新 XML 列中具有不同值的所有行 [T-SQL]
- actions-on-google - 数字交易问题——启用实时模式
- javascript - 为什么我不能在 return 语句中访问数据,而只能在控制台中访问?