Find points within a cuboid ROI in the organized point cloud data by using the camera projection matrix. Compute the camera projection matrix from sampled point cloud data points and their corresponding image point coordinates.
Load an organized point cloud data into the workspace. The point cloud is generated by using the Kinect depth sensor.
ld = load('object3d.mat');
ptCloud = ld.ptCloud;
Specify the step size for sampling the point cloud data.
stepSize = 100;
Sample the input point cloud and store the sampled 3-D point coordinates as a point cloud object.
indices = 1:stepSize:ptCloud.Count;
tempPtCloud = select(ptCloud,indices);
Remove invalid points from the sampled point cloud.
[tempPtCloud,validIndices] = removeInvalidPoints(tempPtCloud);
Get the 3-D world point coordinates from input point cloud.
worldPoints = tempPtCloud.Location;
Find the 2-D image coordinates corresponding to the 3-D point coordinates of input point cloud.
[Y,X] = ind2sub([size(ptCloud.Location,1),size(ptCloud.Location,2)],indices);
imagePoints = [X(validIndices)' Y(validIndices)'];
Estimate camera projection matrix from the image and the world point coordinates.
camMatrix = estimateCameraMatrix(imagePoints,worldPoints);
Specify a cuboid ROI within the range of the x, y and z coordinates of the input point cloud.
roi = [0.3 0.7 0 0.4 0.1 0.3];
Find the indices of the point cloud data that lie within the cuboid ROI.
indices = findPointsInROI(ptCloud,roi,camMatrix);
Use the point cloud method select to get the point cloud data of points within the ROI.
ptCloudB = select(ptCloud,indices);
Display the input point cloud and the points within the cuboid ROI.
figure
pcshow(ptCloud)
hold on
pcshow(ptCloudB.Location,'r');
legend('Point Cloud','Points within the ROI','Location','southoutside','Color',[1 1 1])
hold off