I am trying to create a point cloud using a stereo camera arrangement (calibrated and rectified), a disparity map, and Point Cloud Library. Below is a brief description of my C++ code that is supposed to generate a point cloud using the disparity map.
#include <iostream>
#include <fstream>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/ximgproc.hpp>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
#include <boost/thread/thread.hpp>
#include <pcl/visualization/vtk.h>
using namespace std;
using namespace cv;
using namespace cv::ximgproc;
using namespace pcl;
using namespace pcl::visualization;
boost::shared_ptr<PCLVisualizer> rgbVis (PointCloud<PointXYZRGB>::ConstPtr cloud)
{
boost::shared_ptr<PCLVisualizer> viewer (new PCLVisualizer ("3D Viewer"));
viewer->setBackgroundColor (0, 0, 0);
PointCloudColorHandlerRGBField<PointXYZRGB> rgb(cloud);
viewer->addPointCloud<PointXYZRGB> (cloud, rgb, "sample cloud");
viewer->setPointCloudRenderingProperties (PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud");
return (viewer);
}
/* Some other functions */
int main()
{
.....
.....
int l, r;
cout << "Enter CAM index for Left Camera ";
cin >> l;
cout << endl << "Enter CAM index for Right Camera ";
cin >> r;
VideoCapture leftCam(l);
VideoCapture rightCam(r);
........
........
boost::shared_ptr<PCLVisualizer> viewer;
bool proceed = true;
while(proceed)
{
........
........
PointCloud<PointXYZRGB>::Ptr pointCloud(new PointCloud<PointXYZRGB>());
Mat xyz;
reprojectImageTo3D(disparityMap, xyz, q);
pointCloud->width = static_cast<uint32_t>(disparityMap.cols);
pointCloud->height = static_cast<uint32_t>(disparityMap.rows);
pointCloud->is_dense = false;
PointXYZRGB tempPoint;
for(int i = 0; i < disparityMap.rows; i++)
{
uchar* rgb_ptr = rightUndistorted.ptr<uchar>(i);
uchar* disp_ptr = disparityMap.ptr<uchar>(i);
double* xyz_ptr = xyz.ptr<double>(i);
for(int j = 0; j < disparityMap.cols; j++)
{
uchar d = disp_ptr[j];
if(d == 0)
continue;
Point3f p = xyz.at<Point3f>(i, j);
tempPoint.x = p.x;
tempPoint.y = p.y;
tempPoint.z = p.z;
tempPoint.b = rgb_ptr[3 * j];
tempPoint.g = rgb_ptr[3 * j + 1];
tempPoint.r = rgb_ptr[3 * j + 2];
pointCloud->points.push_back(tempPoint);
}
}
viewer = rgbVis(pointCloud);
if(waitKey(50) == 'q')
proceed = false;
}
destroyAllWindows();
return 0;
}
I run the following terminal command to compile this .cpp file...
g++ -std=c++14 d2pc.cpp -o d2pc `pkg-config --cflags --libs opencv pcl_io-1.11 pcl_visualization-1.11` -lboost_system
This generates the following error message...
/usr/local/include/pcl-1.11/pcl/visualization/point_cloud_geometry_handlers.h:48:10: fatal error: vtkSmartPointer.h: No such file or directory
#include <vtkSmartPointer.h>
^~~~~~~~~~~~~~~~~~~
compilation terminated.
I thought that installing Vtk from here might help solve the issue, but it didn't help.
How to tackle this issue? I am using OpenCV 3.4.10 in Ubuntu 18.04