PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.86k stars 4.61k forks source link

[Proposal] New tutorial for "How to install PCL for windows x64 Visual Studio 2019" #4462

Open petrasvestartas opened 3 years ago

petrasvestartas commented 3 years ago

Hi,

We went through a painful process of PCL installation. In order to save someone else time, I would strongly recommend to include these steps in PCL github ReadMe file.


TRYING TO INSTALL PCL FOR DAYS, WEEKS, MONTHS AND YEARS FOR WINDOWS X64 VISUAL STUDIO 2019? READ CAREFULLY STEPS BELOW:

  1. Download All-in-One Installer https://github.com/PointCloudLibrary/pcl/releases Including OpenNi

We tried VCPKG packages, but it did not work because of Eigen, and the only way was to install via all in one installer.


  1. Set Environmental Variables and restart computer. We tried on two separate laptops and this was the full list needed. Because in one pc some references were ok and the other pc required more references. To find environmental variables in windows bottom left, type Environmental Variables.
    
    name: PCL_ROOT
    value: C:\Program Files\PCL 1.11.1

name:Path C:\Program Files\OpenNI2 C:\Program Files\PCL 1.11.1\bin C:\Program Files\PCL 1.11.1\3rdParty C:\Program Files\PCL 1.11.1\3rdParty\VTK\bin C:\Program Files\OpenNI2\Tools

name: OPENNI2_INCLUDE64 value: C:\Program Files\OpenNI2\Include\

name: OPENNI2_LIB64 value: C:\Program Files\OpenNI2\Lib\

name: OPENNI2_REDIST64 value: C:\Program Files\OpenNI2\Redist\


![image](https://user-images.githubusercontent.com/18013985/96911762-9199d480-14a1-11eb-9067-8645247cd807.png)

______________________________________________________________________________________________________________________

3. Create Folder in whatever place (I used C:/lib/PCLTest drive) and add CMakeLists.txt and .cpp file following the online tutorial instructions: https://pcl.readthedocs.io/projects/tutorials/en/latest/cloud_viewer.html#cloud-viewer. 
Add text from this website into **CMakeLists.txt** and then add **cloud_viewer.cpp** with the code inside.

![image](https://user-images.githubusercontent.com/18013985/96912874-4254a380-14a3-11eb-9822-5f4c37182b9f.png)

![image](https://user-images.githubusercontent.com/18013985/96911605-5ac3be80-14a1-11eb-88c5-e9656236419c.png)

______________________________________________________________________________________________________________________

4. In **CMake** (https://cmake.org/download/) reference the folder where those two files are and reference empty build file. 
Press configure and build.
If the cpp file is named main.cpp it wont work because it must be cloud_viewer.cpp .
Also do not forget to add code from the tutorial website (pointclouds.org) else the code wont build.
Press Configure and then Generate. Do not forget to set compiler to x64 bit. Compile will create project file in build directory.
![image](https://user-images.githubusercontent.com/18013985/96912240-52b84e80-14a2-11eb-8c5f-f3bdaf72f8cd.png)
In my case I had some warning messages but it worked:
![image](https://user-images.githubusercontent.com/18013985/96912349-898e6480-14a2-11eb-9768-8860875c0a00.png)

______________________________________________________________________________________________________________________

5. Open Visual Studio project and set to project to cloud_viewer. 
Build it. 
![image](https://user-images.githubusercontent.com/18013985/96912175-374d4380-14a2-11eb-8136-6de0fe9c51c3.png)

______________________________________________________________________________________________________________________

6. Copy PointCloud.pcd file to project main folder, the pcd (pointcloud data sets) are in your program files, use search engine Everything to find these files faster:
C:\DEV\PCL1_11_1_Test03\build
![image](https://user-images.githubusercontent.com/18013985/96911989-ed645d80-14a1-11eb-9837-9ecb86c22e35.png)

______________________________________________________________________________________________________________________

7. Change the name of the .pcd file in the cloud_viewer.cpp file, build it again and run it in debug mode.

![image](https://user-images.githubusercontent.com/18013985/96911428-20f2b800-14a1-11eb-912d-71df5f75b05a.png)

______________________________________________________________________________________________________________________

**PCL IS AWESOME**
larshg commented 3 years ago

Nice summary of how to use the All-In-One-installer - would be nice if you would contribute it as a tutorial perhaps :)

Maybe a bit of rewording here and there.

kunaltyagi commented 3 years ago

I second @larshg here. The tutorials are located in docs/tutorials/content and use RST (how-to-start, primer). You can create a PR and add the images in the subfolder.

Step 3 would be easier since you can simply refer to the source file

CatoFuyu commented 3 years ago

You helped me a lot!!! I really, truly appreciate you!

rightchose commented 3 years ago

Your work has saved me a lot of time!!!

eltonhcchan commented 3 years ago

many thx for your effort and work, you save me a lot of time.

ericwilliamsneu commented 3 years ago

This ended 3 weeks of frustrating fighting vcpkg.

eltonhcchan commented 3 years ago

Any tutorial to run the qt visualiser example?

pawanpillai commented 3 years ago

Thank you so much!

Chris45215 commented 3 years ago

Thank you so much for this! I spent a week struggling to install PCL on Windows 10, resulting in different levels of failure - for example the vcpkg version would install, but lacked the visualization components that are honestly critical to a 3D program. I got to the point of compiling everything myself from scratch, following a mix-and-match of tutorials like the official one and the UnaNancyOwen one, but those ultimately failed too.

Your guide actually worked. And even better, it's really the easiest guide to follow. The only thing I can add is that I had to set the startup project as cloud_viewer rather than ALL_BUILD, and that's a relatively easy step.

Your guide should be the official documentation, and the other documentation should be clearly deprecated and retired.

deltaprophet commented 3 years ago

This should be official guide. I spent several hours to build from source and with vcpkg. none of them actually worked. On top of that, vcpkg takes like 6-7 hours for installation. Thank you so much!

kunaltyagi commented 3 years ago

We have a windows docker image as well: pointcloudlibrary/env:winx86 and pointcloudlibrary/env:winx64 (based on 2019 Server Core image) that come with vcpkg installed (and other dependencies of PCL, but not PCL)

This should be official guide

Adding this as an official tutorial is quite easy (hence the tags). Please feel free to create a PR in the docs module of PCL

Nerolf05 commented 3 years ago

Thank you

xlulak commented 3 years ago

Hi, where can i find those documents from point 3 (CMakeLists.txt and .cpp file)

andreas-loeffler commented 3 years ago

Hi, where can i find those documents from point 3 (CMakeLists.txt and .cpp file)

@xlulak just use the link he provided: https://pcl.readthedocs.io/projects/tutorials/en/latest/cloud_viewer.html#cloud-viewer There you will find the CMake file and the .cpp

AndreAhmed commented 2 years ago

Hello, The all in one installer works only in release mode, debug, release with debug, results in a crash.

AndreAhmed commented 2 years ago
int
main()
{
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));

    pcl::PCLPointCloud2::Ptr cloud(new pcl::PCLPointCloud2);
    pcl::io::loadPCDFile("188261.pcd", *cloud);

    // Convert data to PointCloud<T>
    PointCloud<PointXYZ>::Ptr xyz(new PointCloud<PointXYZ>);
    fromPCLPointCloud2(*cloud, *xyz);

    // Refine the plane indices
    using SampleConsensusModelPlanePtr = SampleConsensusModelPlane<PointXYZ>::Ptr;
    SampleConsensusModelPlanePtr model(new SampleConsensusModelPlane<PointXYZ>(xyz));
    RandomSampleConsensus<PointXYZ> sac(model, 0.05);
    sac.setMaxIterations(1000);
    bool res = sac.computeModel();

    pcl::Indices inliers;
    sac.getInliers(inliers);
    Eigen::VectorXf coefficients;
    sac.getModelCoefficients(coefficients);

    if (!res || inliers.empty())
    {
        PCL_ERROR("No planar model found. Relax thresholds and continue.\n");
        return 0;
    }
    sac.refineModel(2, 50);
    sac.getInliers(inliers);
    sac.getModelCoefficients(coefficients);

    print_info("Model coefficients: [");
    print_value("%g %g %g %g", coefficients[0], coefficients[1], coefficients[2], coefficients[3]); print_info("]\n");

    // Instead of returning the planar model as a set of inliers, return the outliers, but perform a cluster segmentation first

        // Remove the plane indices from the data
    PointIndices::Ptr everything_but_the_plane(new PointIndices);
    std::vector<int> indices_fullset(xyz->size());
    for (int p_it = 0; p_it < static_cast<int> (indices_fullset.size()); ++p_it)
        indices_fullset[p_it] = p_it;

    std::sort(inliers.begin(), inliers.end());
    set_difference(indices_fullset.begin(), indices_fullset.end(),
        inliers.begin(), inliers.end(),
        inserter(everything_but_the_plane->indices, everything_but_the_plane->indices.begin()));

    // Extract largest cluster minus the plane
    std::vector<PointIndices> cluster_indices;
    EuclideanClusterExtraction<PointXYZ> ec;
    ec.setClusterTolerance(0.02); // 2cm
    ec.setMinClusterSize(100);
    ec.setInputCloud(xyz);
    ec.setIndices(everything_but_the_plane);
    ec.extract(cluster_indices);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cluster(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PCLPointCloud2 output;
    // Convert data back
    copyPointCloud(*cloud, cluster_indices[0].indices, output);

    fromPCLPointCloud2(output, *cluster);

    pcl::MomentOfInertiaEstimation <PointXYZ> feature_extractor;
    feature_extractor.setInputCloud(cluster);
    feature_extractor.compute();

    std::vector <float> moment_of_inertia;
    std::vector <float> eccentricity;

    pcl::PointXYZ min_point_AABB;
    pcl::PointXYZ max_point_AABB;
    pcl::PointXYZ min_point_OBB;
    pcl::PointXYZ max_point_OBB;
    pcl::PointXYZ position_OBB;

    Eigen::Matrix3f rotational_matrix_OBB;
    float major_value, middle_value, minor_value;
    Eigen::Vector3f major_vector, middle_vector, minor_vector;
    Eigen::Vector3f mass_center;

    feature_extractor.getMomentOfInertia(moment_of_inertia);
    feature_extractor.getEccentricity(eccentricity);
    feature_extractor.getAABB(min_point_AABB, max_point_AABB);
    feature_extractor.getOBB(min_point_OBB, max_point_OBB, position_OBB, rotational_matrix_OBB);
    feature_extractor.getEigenValues(major_value, middle_value, minor_value);
    feature_extractor.getEigenVectors(major_vector, middle_vector, minor_vector);
    feature_extractor.getMassCenter(mass_center);

    pcl::PointXYZ center(mass_center(0), mass_center(1), mass_center(2));
    pcl::PointXYZ x_axis(major_vector(0) + mass_center(0), major_vector(1) + mass_center(1), major_vector(2) + mass_center(2));
    pcl::PointXYZ y_axis(middle_vector(0) + mass_center(0), middle_vector(1) + mass_center(1), middle_vector(2) + mass_center(2));
    pcl::PointXYZ z_axis(minor_vector(0) + mass_center(0), minor_vector(1) + mass_center(1), minor_vector(2) + mass_center(2));

    viewer->addLine(center, x_axis, 1.0f, 0.0f, 0.0f, "major eigen vector");
    viewer->addLine(center, y_axis, 0.0f, 1.0f, 0.0f, "middle eigen vector");
    viewer->addLine(center, z_axis, 0.0f, 0.0f, 1.0f, "minor eigen vector");
    viewer->addPointCloud<pcl::PointXYZ>(cluster, "Moment Of Inertia (PCA Eigen Vector Axes)");
    pcl::io::savePLYFileBinary("filtered.ply", *cluster);

    while (!viewer->wasStopped())
    {
        viewer->spinOnce(100);
    }
AndreAhmed commented 2 years ago

and here is the sample point cloud https://www.mediafire.com/file/epglzuigetuw0n2/188262.pcd/file

it works only in release mode.

kaitou1419 commented 2 years ago

Can anyone help me, to include PCL lib path when create empty project Visual Studio 2019 (do not use Cmake to complie project) i want to add pcl libraries into a prevous project.

guillermoacdc commented 2 years ago

Awesome!

1056776 commented 2 years ago

I think i'm just to dumb for Point 3. I have no idea on how to find these two documents. Also why do i have 340 .txt documents in the files that i had to download in Point 1 ? https://pcl.readthedocs.io/projects/tutorials/en/latest/cloud_viewer.html#cloud-viewer

Could someone please help me? Maybe with pictures or so ?

CatHas4Paws commented 2 years ago

@petrasvestartas i'm appreciate about the tutorial. I have spend a week to compile it from source and the other tutorials from pcl homepage.

But i have one problem an i hope one of you can help me. I have downloaded the 188262.pcd file from the Link that @AndreAhmed has posted.

I build the project and run it in debug and release mode but i only have the colorful screen below.

For the script i have copied the "more complete sample" from here: https://pcl.readthedocs.io/projects/tutorials/en/latest/cloud_viewer.html#cloud-viewer

InkedScreenshot 2022-04-20 153146 InkedScreenshot 2022-04-20 153242 InkedScreenshot 2022-04-20 153303

larshg commented 2 years ago

@petrasvestartas i'm appreciate about the tutorial. I have spend a week to compile it from source and the other tutorials from pcl homepage.

But i have one problem an i hope one of you can help me. I have downloaded the 188262.pcd file from the Link that @AndreAhmed has posted.

I build the project and run it in debug and release mode but i only have the colorful screen below.

For the script i have copied the "more complete sample" from here: https://pcl.readthedocs.io/projects/tutorials/en/latest/cloud_viewer.html#cloud-viewer

InkedScreenshot 2022-04-20 153146 InkedScreenshot 2022-04-20 153242 InkedScreenshot 2022-04-20 153303

Just press R or scroll with curser on the window. This change the camera view, which only shows the coordinate axises close up :-)

nekoshadow1 commented 2 years ago

Thank you so much! It works for me. Before finding your tutorial, I have spent a whole day installing PCL using vcpkg, which is a nightmare...

HanzDieter commented 2 years ago

Hello, this tutorial is great. But there is one thing not working on my PCL in VS2019. Intellisense ist not working with PCL. Does anybody else has this problem?

nekoshadow1 commented 2 years ago

Have you tried to disable intellisense in VS? Like setting 'Build Only' image

HanzDieter commented 2 years ago

Have you tried to disable intellisense in VS? Like setting 'Build Only' image

Hello, thank you for your answer. i meant that in visual studio the autocorrection or code suggestions from intellisense does not work in a PCL project. Does the autocorrection work for you?

CatHas4Paws commented 2 years ago

@HanzDieter are you work with the PCL-examples or with a new custom project?

In the PCL-examples InteliSense does not work. In a custom projekt it works fine with PCL.

Oguzza commented 1 year ago

resim_2022-12-08_021357075

I can run the code but I am getting this error on the list, what is the problem? C++ command-line error: invalid macro definition: BOOST_ALL_NO_LIB-DBOOST_ALL_NO_LIB

CatHas4Paws commented 1 year ago

Maybe the viewer.h is needed Boost at one point. Can you include a boost library in your Code? Make Sure boost is installed and correctly linked. Maybe its helps if you add boost in the projectsettings as additional include path.

larshg commented 1 year ago

Its a bug with dublicate defines, pleqse search for similiar issue and fix.

Oguzza commented 1 year ago

image

Solved by changing "BOOST_ALL_NO_LIB-DBOOST_ALL_NO_LIB" line to two separate definitions. image

surbhib20 commented 1 year ago

please tell me where can i find CMakeLists.txt and .cpp file (point 3)

CatHas4Paws commented 1 year ago

please tell me where can i find CMakeLists.txt and .cpp file (point 3)

Please look for the tutorial in point 3. You have to copy the code an create the files by yourself.

surbhib20 commented 1 year ago

please tell me where can i find CMakeLists.txt and .cpp file (point 3)

Please look for the tutorial in point 3. You have to copy the code and create the files by yourself.

Okay Thanks, I understood that I have to copy it to the cmakelist.text and cloud_compare.cpp

But where I will find these file

Any help will be appreciated.

CatHas4Paws commented 1 year ago

You should create these files by yourself. You can't find them anywhere.

surbhib20 commented 1 year ago

You should create these files by yourself. You can't find them anywhere.

I am new to this field. Can you give me some idea on how to create it?

Thanks in advance

CatHas4Paws commented 1 year ago

You should create these files by yourself. You can't find them anywhere.

ToDo:

surbhib20 commented 1 year ago

Thanks a lot. It worked.

Would you please explain point 5? What you did in visual studio and how?

thanking you

You should create these files by yourself. You can't find them anywhere.

ToDo:

* Create a empty folder ( e.g. your project name - here cloud_viewer)

* create the file cloud_viewer.cpp in the new folder and copy the cpp-code from the tutorial to this file. (61 lines in this tutorial)

* Create the file CMakeLists.txt in the new folder and copy the Code from the tutorial in this file. (12 lines in this tutorial)

* now you can go to step 4.
  Please be aware with the paths and reference your newly createt project folder.

Thanks a lot. It worked.

Would you please explain point 5? What you did in visual studio and how?

thanking you

CatHas4Paws commented 1 year ago

You haven't looked on the picture on point five?

Open the "solution explorer" Make a right click on the "cloud_viewer" project. Klick in the opened contextmenu on "Set as startup" project.

Sorry, but it's not that difficult. You have worked with visual Studio before?

Shantha-Adi commented 1 year ago

Any tutorial to run the qt visualiser example?

You found any ??

iamjadhav commented 10 months ago

Does this tutorial work for Visual Studio 2022?

FlorianHou commented 10 months ago

Does this tutorial work for Visual Studio 2022?

Yes. I am using VS2022. And It works

ddries commented 1 month ago

Hi,

Thank you very much for this awesome guide. However, following this tutorial when you try to add more source/header files to the project (not only main.cpp or cloudviewer.cpp or whatever), VS2022 creates them in a different directory than the one CMake takes. Thus you have to manually move them which feels weird.

Any idea?