Matlab解析Json文件绘图应用

项目中的相机参数以json文件的格式给出。
为了形象化看观察每个相机的位置,将其用matlab解析并绘制成球。

相机模型

FacebookX24

Matlab程序

% facebookX24.m
clc;
addpath('C:\Program Files\MATLAB\R2015b\toolbox\jsonlab-1.5');

% read .json
json2data=loadjson('E:\JZChen\X24\museum_metadata.json');

Cameras_number = json2data.Informative.Cameras_number;
% fprintf('%d',Cameras_number);

% draw the camera and it's index
for index = 1:Cameras_number
    %fprintf('%d\n',index);
    name = json2data.cameras{1,index}.Name;    
    Position = json2data.cameras{1,index}.Position;
    %fprintf('%s,%d\n',name,Position);
    tmp_x = Position(1);
    tmp_z = Position(2);
    tmp_y = Position(3);
    plot3(tmp_z,tmp_x,tmp_y,'rx');
    text(tmp_z,tmp_x,tmp_y,name,'FontSize',12);
    hold on;
end
r=sqrt(0.0955); % radius
x0=0;y0=1.65;z0=0; % sphere center

[z,x,y]=sphere(); % generate sphere
surf(r*z+z0,r*x+x0,r*y+y0); % draw sphere

axis on;
axis equal;
xlabel('z');
ylabel('x');
zlabel('y');

% color
%colormap('white');
%colormap('gray');
colormap('default');
alpha(0.5);

绘制效果

这里写图片描述

json配置文件如下:

{
    "Content_name": "TechnicolorMuseum", 
    "BoundingBox_center": [0.0,0.0,1.65], 
    "Fps": 30,
    "Frames_number": 300,
    "Informative":
    {     
        "Cameras_number": 24,
        "RigRadius": 0.30
    },
    "cameras":
    [
        {
            "Name":"camE0",
            "Position": [  0.0777,   -0.1429, 1.3872], 
            "Rotation": [  -61.4676,   40.3759, 0.0000],  
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE1",
            "Position": [  0.1429,   0.2628, 1.7277], 
            "Rotation": [  61.4676,   -14.1095, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE2",
            "Position": [  0.2628,   0.0777, 1.7929], 
            "Rotation": [  16.4676,   -24.8121, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE3",
            "Position": [  0.1429,   -0.2628, 1.5723], 
            "Rotation": [  -61.4676,   14.1095, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE4",
            "Position": [  0.0777,   0.1429, 1.9128], 
            "Rotation": [  61.4676,   -40.3759, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE5",
            "Position": [  0.2628,   -0.0777, 1.5071], 
            "Rotation": [  -16.4676,   24.8121, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE6",
            "Position": [  0.1429,   0.0777, 1.3872], 
            "Rotation": [  28.5324,   40.3759, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE7",
            "Position": [  0.0777,   0.2628, 1.5071], 
            "Rotation": [  73.5324,  24.8121, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE8",
            "Position": [  0.2628,   0.1429, 1.5723], 
            "Rotation": [  28.5324,   14.1095, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE9",
            "Position": [  0.1429,   -0.0777, 1.9128], 
            "Rotation": [  -28.5324,   -40.3759, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE10",
            "Position": [  0.0777,   -0.2628, 1.7929], 
            "Rotation": [  -73.5324,   -24.8121, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE11",
            "Position": [  0.2628,   -0.1429, 1.7277], 
            "Rotation": [  -28.5324,   -14.1095, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE12",
            "Position": [  -0.2628,   -0.0777, 1.7929], 
            "Rotation": [  -163.5324,   -24.8121, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE13",
            "Position": [  -0.0777,   -0.1429, 1.9128], 
            "Rotation": [  -118.5324,   -40.3759, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE14",
            "Position": [  -0.1429,   -0.2628, 1.7277], 
            "Rotation": [  -118.5324,   -14.1095, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE15",
            "Position": [  -0.0777,   0.1429, 1.3872], 
            "Rotation": [  118.5324,   40.3759, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE16",
            "Position": [  -0.2628,   0.0777, 1.5071], 
            "Rotation": [  163.5324,   24.8121, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE17",
            "Position": [  -0.1429,   0.2628, 1.5723], 
            "Rotation": [  118.5324,   14.1095, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE18",
            "Position": [  -0.0777,   0.2628, 1.7929], 
            "Rotation": [  106.4676,   -24.8121, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE19",
            "Position": [  -0.2628,   -0.1429, 1.5723], 
            "Rotation": [  -151.4676,   14.1095, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE20",
            "Position": [  -0.1429,   -0.0777, 1.3872], 
            "Rotation": [  -151.4676,   40.3759, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE21",
            "Position": [  -0.2628,   0.1429, 1.7277], 
            "Rotation": [  151.4676,   -14.1095, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE22",
            "Position": [  -0.1429,   0.0777, 1.9128], 
            "Rotation": [  151.4676,   -40.3759, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        },
        {
            "Name":"camE23",
            "Position": [  -0.0777,   -0.2628, 1.5071], 
            "Rotation": [  -106.4676,   24.8121, 0.0000], 
            "Depthmap": 1,
            "Background": 1,
            "Rmin":   0.50,
            "Rmax":  25.00,
            "Resolution": [2048,2048],
            "Hor_range": [ -90.0, +90.0 ],
            "Ver_range": [ -90.0, +90.0 ]
        }
    ]
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值