Error when using PCA with point clouds
I would like to use PCA on the point clouds to find the lane . So the Principle Component Analysis should work fine for this problem. So Im not sure how to correctly use PCA with Point Clouds and ROS. Here is the code that I create so far
#include <iostream>
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <vector>
#include <sensor_msgs/LaserScan.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/PointCloud.h>
#include <laser_geometry/laser_geometry.h>
#include <tf/transform_listener.h>
#include <Eigen/Core>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include "ros/ros.h"
#include <pcl/common/pca.h>
#include <pcl/io/io.h>
#include <pcl/conversions.h> //I believe you were using pcl/ros/conversion.h
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
//using namespace std;
laser_geometry::LaserProjection projector_;
void getOrientation (const sensor_msgs::LaserScan::ConstPtr& scan)
{
//convert laser scan into point clouds
sensor_msgs::PointCloud cloud;
projector_.projectLaser(*scan, cloud);
//Construct a buffer used by the pca analysis
pcl::PointXYZ projected, reconstructed;
pcl::PCA<pcl::PointXYZ> pca;
for(size_t i = 0; i < cloud.points.size(); i++)
{
pca.project (cloud.points[i], projected(i));
//pca.reconstruct (projected, reconstructed);
}
}
int main(int argc, char **argv)
{
// Initiate a new ROS node named "talker"
ros::init(argc, argv, "lane_detection_pca_node");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("/scan", 1000, getOrientation);
return 0;
ros::spin();
}
So there is a conversion problem but not sure. The error I got is
error: no match for call to ‘(pcl::PointXYZ) (size_t&)’ 45 |
pca.project (cloud.points[i],
So the problem is in pcl::PointXYZ projected, reconstructed; Should be converted to other PCL type??Any help?
Asked by Astronaut on 2023-04-21 00:26:32 UTC
Comments