Skip navigation

We have created this unofficial pointcloud example to demonstrate how to view live pointcloud stream in Matlab. It is very basic and does not map color. Mapping of color is still a work in progress. This is provided only to get you started. Matlab and Intel RealSense SDK 2.0 knowledge is required.

 

function pointcloud_example()
    % Make Pipeline object to manage streaming
    pipe = realsense.pipeline();
    
    pointcloud = realsense.pointcloud();


    % Start streaming on an arbitrary camera with default settings
    profile = pipe.start();


    % Get streaming device's name
    dev = profile.get_device();
    name = dev.get_info(realsense.camera_info.name);


    % Get frames. We discard the first couple to allow
    % the camera time to settle
    for i = 1:5
        fs = pipe.wait_for_frames();
    end
        
    figure('visible','on'); 
    %hold on
    for i = 1:1000
        
        fs = pipe.wait_for_frames();
        
        % Select depth frame
        depth = fs.get_depth_frame();
        color = fs.get_color_frame();


        % Produce pointcloud
        if (depth.logical() && color.logical())


            pointcloud.map_to(color);
            points = pointcloud.calculate(depth);
            
            % Adjust frame CS to matlab CS
            vertices = points.get_vertices();
            X = vertices(:,1,1);
            Y = vertices(:,2,1);
            Z = vertices(:,3,1);


            plot3(X,Z,-Y,'.'); %hold on;            


            xlim([-1 1])
            ylim([0.3 2])
            zlim([-1 1])
            xlabel('X axis');
            ylabel('Y axis');
            zlabel('Z');
            pause(0.01);
        end
        % pcshow(vertices); Toolbox required       
    end


            
     % Stop streaming
    pipe.stop();
    
end