3d Point Cloud forming like a prism
3 views (last 30 days)
Show older comments
Dear All I am trying to plot a point cloud in Matlab 2016. The point cloud is forming something like this instead of a regular point cloud. Can anyone help me with why this is happening?
Thank you
My code
clear all
close all
%%Load the Parameters of the Stereo Camera
% Load the |stereoParameters| object, which is the result of calibrating
% the camera using either the |stereoCameraCalibrator| app or the
% |estimateCameraParameters| function.
% Load the stereoParameters object.
load('webcam.mat');
% Visualize camera extrinsics.
showExtrinsics(stereoParams);
% %%Create Video File Readers and the Video Player
% % Create System Objects for reading and displaying the video
% videoFileLeft = 'second_1.mp4';
% videoFileRight = 'first_1.mp4';
%
% readerLeft = vision.VideoFileReader(videoFileLeft, 'VideoOutputDataType', 'uint8');
% readerRight = vision.VideoFileReader(videoFileRight, 'VideoOutputDataType', 'uint8');
% player = vision.DeployableVideoPlayer('Location', [20, 400]);
%%Read and Rectify Video Frames
% The frames from the left and the right cameras must be rectified in order
% to compute disparity and reconstruct the 3-D scene. Rectified images
% have horizontal epipolar lines, and are row-aligned. This simplifies
% the computation of disparity by reducing the search space for matching
% points to one dimension. Rectified images can also be combined into an
% anaglyph, which can be viewed using the stereo red-cyan glasses to see
% the 3-D effect.
frameLeft = imread('first.jpg');
frameRight = imread('second.jpg');
[frameLeftRect, frameRightRect] = ...
rectifyStereoImages(frameLeft, frameRight, stereoParams);
figure;
imshow(stereoAnaglyph(frameLeftRect, frameRightRect));
title('Rectified Video Frames');
%%Compute Disparity
% In rectified stereo images any pair of corresponding points are located
% on the same pixel row. For each pixel in the left image compute the
% distance to the corresponding pixel in the right image. This distance is
% called the disparity, and it is proportional to the distance of the
% corresponding world point from the camera.
frameLeftGray = rgb2gray(frameLeftRect);
frameRightGray = rgb2gray(frameRightRect);
disparityMap = disparity(frameLeftGray, frameRightGray);
figure;
imshow(disparityMap, [0, 64]);
title('Disparity Map');
colormap jet
colorbar
%%Reconstruct the 3-D Scene
% Reconstruct the 3-D world coordinates of points corresponding to each
% pixel from the disparity map.
points3D = reconstructScene(disparityMap, stereoParams);
% Convert to meters and create a pointCloud object
points3D = points3D ./ 1000;
ptCloud = pointCloud(points3D, 'Color',frameLeftRect);
%
% % Create a streaming point cloud viewer
% player3D = pcplayer([-3, 3], [-3, 3], [0, 8], 'VerticalAxis', 'y', ...
% 'VerticalAxisDir', 'down');
%
% % Visualize the point cloud
% % view(player3D, ptCloud);
% pcshow(ptCloud.Location,ptCloud.Color);
figure
pcshow(ptCloud, 'VerticalAxis', 'y', 'VerticalAxisDir', 'down', ...
'MarkerSize', 45);
% filename='xxx.ply';
% pcwrite(ptCloud,filename,'PLYFormat','binary');
0 Comments
Answers (2)
Qiuheng Zhou
on 8 Feb 2019
Edited: Walter Roberson
on 14 Mar 2020
Hi, i think, i have the same problem as yours. Do you have already solved your problem?
I guess the problem should be hier.
ptCloud = pointCloud(points3D, 'Color',frameLeftRect);
The algorithm of KNN should be changed. I am not sure.
1 Comment
Munin
on 30 Aug 2021
Edited: Munin
on 19 Feb 2022
@Walter Roberson @Qiuheng Zhou @Pooshpanja Roy I've got a bulletproof workaround, and I've contacted the Mathworks team:
Munin
on 28 Mar 2022
Edited: Munin
on 28 Mar 2022
I contacted the MATLAB support team about this issue and told them I wrote a few dozen lines of code to constrain the giant prism point cloud to the world scene at its z-apex:
https://github.com/SNDST00M/stereo2stl/blob/v1.5.0/script.m#L216-L380
They didn't accept the code and suggested a simple > 3m = 0 filter. I.e. it will never be patched. The world scene is the millionth of the point cloud surface that is closest to the origin
0 Comments
See Also
Categories
Find more on Point Cloud Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!