pcl icon indicating copy to clipboard operation
pcl copied to clipboard

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

Open petrasvestartas opened this issue 4 years ago • 43 comments

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


  1. 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

image


  1. 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 In my case I had some warning messages but it worked: image

  1. Open Visual Studio project and set to project to cloud_viewer. Build it. image

  1. 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

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

image


PCL IS AWESOME

petrasvestartas avatar Oct 22 '20 17:10 petrasvestartas

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.

larshg avatar Oct 23 '20 18:10 larshg

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

kunaltyagi avatar Oct 24 '20 16:10 kunaltyagi

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

CatoFuyu avatar Nov 10 '20 13:11 CatoFuyu

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

rightchose avatar Nov 16 '20 04:11 rightchose

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

eltonhcchan avatar Nov 16 '20 16:11 eltonhcchan

This ended 3 weeks of frustrating fighting vcpkg.

ericwilliamsneu avatar Nov 19 '20 04:11 ericwilliamsneu

Any tutorial to run the qt visualiser example?

eltonhcchan avatar Feb 20 '21 03:02 eltonhcchan

Thank you so much!

pawanpillai avatar Mar 16 '21 19:03 pawanpillai

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.

Chris45215 avatar Mar 25 '21 20:03 Chris45215

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!

deltaprophet avatar Apr 02 '21 07:04 deltaprophet

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

kunaltyagi avatar Apr 05 '21 08:04 kunaltyagi

Thank you

Nerolf05 avatar May 11 '21 08:05 Nerolf05

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

xlulak avatar Aug 21 '21 14:08 xlulak

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

andreas-loeffler avatar Aug 21 '21 16:08 andreas-loeffler

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

AndreAhmed avatar Oct 12 '21 10:10 AndreAhmed

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 avatar Oct 12 '21 10:10 AndreAhmed

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

it works only in release mode.

AndreAhmed avatar Oct 12 '21 10:10 AndreAhmed

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.

kaitou1419 avatar Oct 22 '21 17:10 kaitou1419

Awesome!

guillermoacdc avatar Nov 25 '21 18:11 guillermoacdc

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 ?

1056776 avatar Jan 21 '22 11:01 1056776

@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

CatHas4Paws avatar Apr 20 '22 13:04 CatHas4Paws

@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 :-)

larshg avatar Apr 20 '22 13:04 larshg

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...

nekoshadow1 avatar May 01 '22 05:05 nekoshadow1

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?

HanzDieter avatar May 06 '22 09:05 HanzDieter

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

nekoshadow1 avatar May 06 '22 18:05 nekoshadow1

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?

HanzDieter avatar May 07 '22 11:05 HanzDieter

@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.

CatHas4Paws avatar May 23 '22 15:05 CatHas4Paws

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

Oguzza avatar Dec 07 '22 23:12 Oguzza

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.

CatHas4Paws avatar Dec 08 '22 05:12 CatHas4Paws

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

larshg avatar Dec 08 '22 06:12 larshg