Empty point cloud on rs2::pointcloud::calculate()
I am trying to get the vertices of a point-cloud but no matter what I do, I always get [x=0, y=0, z=0] for all points. I am working on an VMware Ubuntu 18.04.3 virtual machine, I am using real-sense version 2.31.0, and I am using a .bag file hat was recorded with a realsense d435i camera.
My Test-Application:
Application:
#include <librealsense2/rs.hpp>
#include <algorithm>
#include <iostream>
int main(int argc, char *argv[])
{
rs2::pointcloud pc;
rs2::points points;
rs2::pipeline pipe;
rs2::config cfg;
cfg.enable_device_from_file("recording.bag");
pipe.start(cfg);
int frame_off_interest = 100;
while (1)
{
if (frame_off_interest <= 0)
{
auto frames = pipe.wait_for_frames();
auto color = frames.get_color_frame();
auto depth = frames.get_depth_frame();
std::cout << "Measurement at [300, 300] = " << std::to_string(depth.get_distance(300, 300)) << std::endl;
pc.map_to(color);
points = pc.calculate(depth);
auto vertices = points.get_vertices();
std::cout << "Fond " << std::to_string(points.size()) << " Vertices" << std::endl;
int vertex_count = 0;
for (int i = 0; i < points.size(); i++)
{
if (vertices[i].x > 0.0 || vertices[i].y > 0.0 || vertices[i].z > 0.0)
{
vertex_count++;
}
}
std::cout << "Count Vertices that are not (0, 0, 0) = " << std::to_string(vertex_count) << std::endl;
break;
}
frame_off_interest--;
}
return EXIT_SUCCESS;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(LRS_PCL)
#used for intelisense by vscode
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(realsense2 REQUIRED)
include_directories(${realsense2_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
add_executable (LRS_PCL rs-pointcloud.cpp)
target_link_libraries (LRS_PCL ${realsense2_LIBRARY})
When I execute the test application, the depth-map has data, but I always get [x=0, y=0, z=0] for all points. See the output of my Test-Application below:
Measurement at [300, 300] = 2.634000
Fond 921600 Vertices
Count Vertices that are not (0, 0, 0) = 0
I would be great-full for your help.
-
I considered your question very carefully. I believe that you are using the correct approach by accessing the vertices via the point cloud class with points.get_vertices and your code is consistent with Intel's point cloud example program.
https://github.com/IntelRealSense/librealsense/tree/master/examples/pointcloud
Could you try removing the line int vertex_count = 0 please to eliminate the possibility that this line is forcing the output vertex count to constantly = 0?
-
If I replace "int vertex_count = 0;" with "int vertex_count;" like you suggested, I get some random value because "vertex_count" isn't initialized.
Measurement at [300, 300] = 2.634000
Fond 921600 Vertices
Count Vertices that are not (0, 0, 0) = -1025714016But i can print something if a vertex isn’t (0, 0, 0) like in the code below.
if (vertices[i].x > 0.0 || vertices[i].y > 0.0 || vertices[i].z > 0.0)
{
std::cout << "We got a Vertex that isnt (0, 0, 0)" << std::endl;
vertex_count++;
}You can see that nothing gets printed below.
Measurement at [300, 300] = 2.634000
Fond 921600 Vertices
Count Vertices that are not (0, 0, 0) = 0 -
All of the RealSense cases involving extracting vertices from a bag involve using the MATLAB vision software and its robotics toolbox. If you prefer to do it totally within the RealSense SDK then I recommend enquiring at the RealSense GitHub by visiting the link below and clicking on the New Issue button to post a question. They should have the specialist programming knowledge to be able to help you. I do apologize.
Please sign in to leave a comment.
Comments
4 comments