# 【Matlab Computer Vision System ToolBox】学习笔记-2-3D立体图创建 | 视差图 | 3D点云图

【Matlab Computer Vision System ToolBox】学习笔记-1-点云配准流程 | 特征匹配

【Matlab Computer Vision System ToolBox】学习笔记-2-3D立体图创建 | 视差图 | 3D点云图

【Matlab Computer Vision System ToolBox】学习笔记-3 -点云配准 | 噪音去除 | 降采样

【Matlab Computer Vision System ToolBox】学习笔记-4 -点云文件PLY格式

# 1. Create 3-D Stereo Display -创建3D立体图

>> load('webcamsSceneReconstruction.mat');             //导入双目标定的结果文件
>> [J1,J2]=rectifyStereoImages(I1,I2,stereoParams);    //立体矫正
>> A=stereoAnaglyph(J1,J2);                            //创建立体图
>> figure;
>> imshow(A);

# 2. Reconstruct 3-D Scene from Disparity Map -从视差图中重建3D场景

>> load('webcamsSceneReconstruction.mat');
>> [J1,J2]=rectifyStereoImages(I1,I2,stereoParams);
>> figure;
>> imshow(cat(3,J1(:,:,1),J2(:,:,2:3)),'InitialMagnification',50);     //合并矩阵并显示，效果同上stereoAnaglyph

>> disparityMap=disparity(rgb2gray(J1),rgb2gray(J2));        //计算视差
>> figure
>> imshow(disparityMap,[0,64],'InitialMagnification',50);     //adjust the display range [0,64]

>> xyzPoints=reconstructScene(disparityMap,stereoParams);
>> Z=xyzPoints(:,:,3);
>> imshow(J1,'InitialMagnification',50);

# 3. Read Point Cloud from a PLY File -读入点云数据

>> ptCloud=pcread('teapot.ply');
>> pcshow(ptCloud);

pcwrite(ptCloud,'teapotOut','PLYFormat','binary');

# 4. Visualize the Difference Between Two Point Clouds -可视化观察两个点云的区别

>> load('livingRoom');                      //88个点云数组集
>> pc1=livingRoomData{1};
>> pc2=livingRoomData{2};                   // 取前2组点云
>> figure;
>> pcshowpair(pc1,pc2,'VerticalAxis','Y','VerticalAxisDir','Down');      //显示点云
>> title('Difference Between Tow Point Clouds')
>> xlabel('X(m)');
>> ylabel('Y(m)');
>> zlabel('Z(m)');

# 5. View Rotating 3-D Point Cloud

>> pcCloud=pcread('teapot.ply');
>> x=pi/180;
>> R=[cos(x) sin(x) 0 0;-sin(x) cos(x) 0 0;0 0 1 0;0 0 0 1];
>> tform=affine3d(R);                                             //定义旋转矩阵和3D平移
>> lower=min([pcCloud.XLimits pcCloud.YLimits]);
>> upper=max([pcCloud.XLimits pcCloud.YLimits]);
>> xlimits=[lower upper];
>> ylimits=[lower upper];
>> zlimits=pcCloud.ZLimits;                                      //找出xy的最小最大值，防止不被显示
>> player=pcplayer(xlimits,ylimits,zlimits);
>> xlabel(player.Axes,'X(m)');
>> ylabel(player.Axes,'Y(m)');
>> zlabel(player.Axes,'Z(m)');
>> for i=1:360                                                   //以Z轴旋转
ptCloud=pctransform(pcCloud,tform);
view(player,pcCloud);
end

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客