Install pcl under ubuntu20.04

The pcl point cloud database is used to acquire and process 3D information. Compared with opencv, opencv is used to process two-dimensional information. It is the most complete library for point clouds in academia and industry, and related information on the Internet a lot of. The following are the installation steps of pcl and the problems encountered.

To explain in advance, I am using ubuntu20.04+pcl1.12.0+vtk7.1.1, using source code compilation, and Vtk is used to complete the visualization of point clouds.

I have installed pcl1.12.0+vtk9.1.1 before, and finally pcl installed and visualized flashback, so it is still vtk7.1.1 downloaded by Vtk

It is said on the Internet that pcl1.8.0+vtk7.1.1 is the standard configuration, but there have been errors when installing pcl1.8.1.

     So this article chooses to install pcl1.12.1 + vtk7.1.1 +qt5.12 (no installation instructions here)

ubuntu18.04_pcl installation

1. First install the various dependencies of pcl

sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.9 libflann-dev  # ubuntu20.4对应1.9
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev
sudo apt-get install libqhull* libgtest-dev
sudo apt-get install freeglut3-dev pkg-config
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete
sudo apt-get install libopenni-dev
sudo apt-get install libopenni2-dev


Possible problems:

(1) sudo apt-get install libflann1.9 libflann-dev shows that the package libflann cannot be located,

First check the version corresponding to the system View address: Ubuntu – Package Search Results -- libflann

Search for libflann and select the codename corresponding to ubuntu20.04 : focal:
 Open the terminal and execute the following command:

lsb_release -a

 You can see that ubuntu20.04 corresponds to libflan1.9

 (2) If you encounter a problem that you cannot connect during the installation process, consider replacing the source

Reference article: Ubuntu replaces the software source

2. Install VTK

   Download address: Download | VTK

I download: VTK-7.1.1.zip

 2.1 First install various dependencies of vtk:

# 首先安装VTK的依赖:X11,OpenGL;cmake和cmake-gui在安装pcl依赖的时候安装过了的话可以跳过
# X11
sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
# OpenGL
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
# cmake && cmake-gui
sudo apt-get install cmake cmake-gui

2.2 Install Vtk

2.2.1 Unzip to the prepared installation directory. Create a new build folder in the directory 

Open a terminal and type:  

cmake-gui 

where is the source code: The path is the VTK directory

where to build the binaries: The path is the path to build under the VTK directory

As shown below:

Click: configure, "Configuring done" is displayed.

Then check "VTK-Group-Qt" and click "Configure"; after completion, "Configuring done" is displayed;

Finally click "Generate"; display "Generating done", complete.

2.2.2 In the build directory, open a terminal and enter:

make -j8 # 要是8核处理器还比较着急看结果的话,可以:make -j16    
sudo make install

3. Install pcl

Download address:  Release PCL 1.12.0 · PointCloudLibrary/pcl · GitHub

Open the pcl directory and create a new build folder

In the build file, open a terminal and type:

cmake -DCMAKE_TYPE=None ..    
make -j8    //  选择8个进程同时处理,如果机子比较差,可以选择make -j4 或者 make
sudo make install

At this point, the pcl download is complete, and it will take a long time.

4. pcl test 

The following two pieces of code are used for testing

4.1 File composition

 cmakelist.txt

cmake_minimum_required(VERSION 2.6)
project(pcl_test)

find_package(PCL 1.12 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable(pcl_test pcl_test.cpp)

target_link_libraries (pcl_test ${PCL_LIBRARIES})

install(TARGETS pcl_test RUNTIME DESTINATION bin)

pcl_test.cpp

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int
  main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ> cloud;

  // Fill in the cloud data
  cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);

  for (size_t i = 0; i < cloud.points.size (); ++i)
  {
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }

  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;

  for (size_t i = 0; i < cloud.points.size (); ++i)
    std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;

  return (0);
}

Run: Enter build, open a terminal and enter:

cmake ..
make
./pcl_test.cpp

got the answer:

 4.2 Another test code is

pcl_test.cpp

#include <iostream>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>
 
 
int main(int argc, char **argv) {
    std::cout << "Test PCL !!!" << std::endl;
    
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
    uint8_t r(255), g(15), b(15);
    for (float z(-1.0); z <= 1.0; z += 0.05)
    {
      for (float angle(0.0); angle <= 360.0; angle += 5.0)
      {
	pcl::PointXYZRGB point;
	point.x = 0.5 * cosf (pcl::deg2rad(angle));
	point.y = sinf (pcl::deg2rad(angle));
	point.z = z;
	uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
		static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
	point.rgb = *reinterpret_cast<float*>(&rgb);
	point_cloud_ptr->points.push_back (point);
      }
      if (z < 0.0)
      {
	r -= 12;
	g += 12;
      }
      else
      {
	g -= 12;
	b += 12;
      }
    }
    point_cloud_ptr->width = (int) point_cloud_ptr->points.size ();
    point_cloud_ptr->height = 1;
    
    pcl::visualization::CloudViewer viewer ("test");
    viewer.showCloud(point_cloud_ptr);
    while (!viewer.wasStopped()){ };
    return 0;
}

operation result:

If the above results are ok, pcl is installed successfully.

Guess you like

Origin blog.csdn.net/m0_48919875/article/details/123863892