41 #include <visp3/core/vpConfig.h>
43 #if defined(VISP_HAVE_REALSENSE2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) \
44 && defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
46 #include <visp3/core/vpImage.h>
47 #include <visp3/core/vpImageConvert.h>
48 #include <visp3/core/vpMeterPixelConversion.h>
49 #include <visp3/gui/vpDisplayGDI.h>
50 #include <visp3/gui/vpDisplayX.h>
51 #include <visp3/sensor/vpRealSense2.h>
55 void createDepthHist(std::vector<uint32_t> &histogram2,
const pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud,
58 std::fill(histogram2.begin(), histogram2.end(), 0);
60 for (uint32_t i = 0; i < pointcloud->height; i++) {
61 for (uint32_t j = 0; j < pointcloud->width; j++) {
62 const pcl::PointXYZ &pcl_pt = pointcloud->at(j, i);
63 ++histogram2[
static_cast<uint32_t
>(pcl_pt.z * depth_scale)];
67 for (
int i = 2; i < 0x10000; i++)
68 histogram2[i] += histogram2[i - 1];
72 void createDepthHist(std::vector<uint32_t> &histogram2,
const std::vector<vpColVector> &pointcloud,
double depth_scale)
74 std::fill(histogram2.begin(), histogram2.end(), 0);
76 for (
size_t i = 0; i < pointcloud.size(); i++) {
78 ++histogram2[
static_cast<uint32_t
>(pt[2] * depth_scale)];
81 for (
int i = 2; i < 0x10000; i++)
82 histogram2[i] += histogram2[i - 1];
86 unsigned char getDepthColor(
const std::vector<uint32_t> &histogram2,
double z,
double depth_scale)
89 return static_cast<unsigned char>(histogram2[
static_cast<uint32_t
>(z * depth_scale)] * 255 / histogram2[0xFFFF]);
93 int main(
int argc,
char *argv[])
95 bool align_to_depth =
false;
96 bool color_pointcloud =
false;
97 bool col_vector =
false;
98 bool no_align =
false;
99 for (
int i = 1; i < argc; i++) {
100 if (std::string(argv[i]) ==
"--align_to_depth") {
101 align_to_depth =
true;
103 else if (std::string(argv[i]) ==
"--color") {
104 color_pointcloud =
true;
106 else if (std::string(argv[i]) ==
"--col_vector") {
109 else if (std::string(argv[i]) ==
"--no_align") {
114 std::cout <<
"align_to_depth: " << align_to_depth << std::endl;
115 std::cout <<
"color_pointcloud: " << color_pointcloud << std::endl;
116 std::cout <<
"col_vector: " << col_vector << std::endl;
117 std::cout <<
"no_align: " << no_align << std::endl;
121 const int width = 640, height = 480, fps = 30;
122 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, fps);
123 config.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, fps);
124 config.enable_stream(RS2_STREAM_INFRARED, width, height, RS2_FORMAT_Y8, fps);
128 vpImage<vpRGBa> I_color(height, width), I_depth(height, width), I_pcl(height, width), I_pcl2(height, width);
129 vpImage<vpRGBa> I_display(height * 2, width), I_display2(height * 2, width), I_display3(height * 2, width);
137 d1.
init(I_display, 0, 0,
"Color + depth");
138 d2.
init(I_display2, width, 0,
"Color + ROS pointcloud");
139 d3.
init(I_display3, 2 * width, 0,
"Color + pointcloud");
141 pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud(
new pcl::PointCloud<pcl::PointXYZ>());
142 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud_color(
new pcl::PointCloud<pcl::PointXYZRGB>());
143 std::vector<vpColVector> vp_pointcloud;
144 std::vector<uint32_t> histogram(0x10000), histogram2(0x10000);
146 rs2::align align_to(align_to_depth ? RS2_STREAM_DEPTH : RS2_STREAM_COLOR);
151 if (color_pointcloud) {
152 rs.
acquire(
reinterpret_cast<unsigned char *
>(I_color.bitmap),
153 reinterpret_cast<unsigned char *
>(I_depth_raw.bitmap), &vp_pointcloud, pointcloud_color,
nullptr,
154 no_align ?
nullptr : &align_to);
157 rs.
acquire(
reinterpret_cast<unsigned char *
>(I_color.bitmap),
158 reinterpret_cast<unsigned char *
>(I_depth_raw.bitmap), &vp_pointcloud, pointcloud,
nullptr,
159 no_align ?
nullptr : &align_to);
165 if (color_pointcloud) {
166 for (uint32_t i = 0; i < pointcloud_color->height; i++) {
167 for (uint32_t j = 0; j < pointcloud_color->width; j++) {
168 const pcl::PointXYZRGB &pcl_pt = pointcloud_color->at(j, i);
171 double x = pcl_pt.x / Z;
172 double y = pcl_pt.y / Z;
177 std::min<unsigned int>(
static_cast<unsigned int>(width - 1),
static_cast<unsigned int>(std::max<double>(0.0, imPt.
get_u())));
179 std::min<unsigned int>(
static_cast<unsigned int>(height - 1),
static_cast<unsigned int>(std::max<double>(0.0, imPt.
get_v())));
180 I_pcl[v][u] =
vpRGBa(pcl_pt.r, pcl_pt.g, pcl_pt.b);
186 createDepthHist(histogram, pointcloud, depth_scale);
188 for (uint32_t i = 0; i < pointcloud->height; i++) {
189 for (uint32_t j = 0; j < pointcloud->width; j++) {
190 const pcl::PointXYZ &pcl_pt = pointcloud->at(j, i);
193 double x = pcl_pt.x / Z;
194 double y = pcl_pt.y / Z;
199 std::min<unsigned int>(
static_cast<unsigned int>(width - 1),
static_cast<unsigned int>(std::max<double>(0.0, imPt.
get_u())));
201 std::min<unsigned int>(
static_cast<unsigned int>(height - 1),
static_cast<unsigned int>(std::max<double>(0.0, imPt.
get_v())));
202 unsigned char depth_viz = getDepthColor(histogram, pcl_pt.z, depth_scale);
203 I_pcl[v][u] =
vpRGBa(depth_viz, depth_viz, depth_viz);
210 createDepthHist(histogram2, vp_pointcloud, depth_scale);
211 for (
size_t i = 0; i < vp_pointcloud.size(); i++) {
215 double x = pt[0] / Z;
216 double y = pt[1] / Z;
221 std::min<unsigned int>(
static_cast<unsigned int>(width - 1),
static_cast<unsigned int>(std::max<double>(0.0, imPt.
get_u())));
223 std::min<unsigned int>(
static_cast<unsigned int>(height - 1),
static_cast<unsigned int>(std::max<double>(0.0, imPt.
get_v())));
224 unsigned char depth_viz = getDepthColor(histogram2, Z, depth_scale);
225 I_pcl2[v][u] =
vpRGBa(depth_viz, depth_viz, depth_viz);
230 I_display.insert(I_depth,
vpImagePoint(I_color.getHeight(), 0));
233 I_display2.insert(I_pcl,
vpImagePoint(I_color.getHeight(), 0));
236 I_display3.insert(I_pcl2,
vpImagePoint(I_color.getHeight(), 0));
242 const int nb_lines = 5;
243 for (
int i = 1; i < nb_lines; i++) {
244 const int col_idx = i * (width / nb_lines);
264 int main() {
return EXIT_SUCCESS; }
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") vp_override
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void flush(const vpImage< unsigned char > &I)
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
vpCameraParameters getCameraParameters(const rs2_stream &stream, vpCameraParameters::vpCameraParametersProjType type=vpCameraParameters::perspectiveProjWithDistortion, int index=-1) const
void acquire(vpImage< unsigned char > &grey, double *ts=nullptr)
bool open(const rs2::config &cfg=rs2::config())