8 #include "opencv2/opencv.hpp" 9 #include <pcl/point_cloud.h> 10 #include <pcl/io/pcd_io.h> 15 #include <boost/foreach.hpp> 18 #include <linux/version.h> 20 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) 21 #include <velodyne_pointcloud/point_types.h> 24 #include <velodyne_pcl/point_types.h> 28 #include <pcl/common/eigen.h> 29 #include <pcl/common/transforms.h> 30 #include <pcl/filters/passthrough.h> 31 #include <pcl/sample_consensus/ransac.h> 32 #include <pcl/sample_consensus/sac_model_line.h> 33 #include <pcl/common/intersections.h> 42 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 (
float, x, x) (
float, y, y) (
float, z, z) (
float,
intensity,
intensity) (uint16_t,
ring,
ring))
56 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59 typedef pcl::PointCloud<::Hesai::PointXYZIT>
PointCloud;
64 (
float, x, x)(
float, y, y)(
float, z, z)
69 struct config_settings {
71 std::vector <std::pair<float, float>> xyz_;
72 float intensity_thresh;
77 std::vector<float> initialRot;
78 std::vector<float> initialTra;
82 std::cout <<
"Size of the frame: " << s.width <<
" x " << s.height <<
"\n";
83 for (
int i = 0; i < 3; i++) {
84 std::cout <<
"Limits: " << xyz_[i].first <<
" to " << xyz_[i].second << std::endl;
86 std::cout <<
"Number of markers: " << num_of_markers << std::endl;
87 std::cout <<
"Intensity threshold (between 0.0 and 1.0): " << intensity_thresh <<
"\nuseCameraInfo: " 88 << useCameraInfo <<
"\n";
89 std::cout <<
"Projection matrix: \n" << P <<
"\n";
90 std::cout <<
"MAX_ITERS: " << MAX_ITERS <<
"\n";
91 std::cout <<
"Lidar_type: " << ((lidar_type == 0) ?
"Velodyne\n" :
"Hesai\n");
93 std::cout <<
"initial rotation: " 94 << initialRot[0] <<
" " 95 << initialRot[1] <<
" " 96 << initialRot[2] <<
"\n";
98 std::cout <<
"initial translation: " 99 << initialTra[0] <<
" " 100 << initialTra[1] <<
" " 101 << initialTra[2] <<
"\n";
108 std::ifstream infile(pkg_loc +
"/conf/config_file.txt");
109 float left_limit = 0.0, right_limit = 0.0;
114 for (
int i = 0; i < 3; i++) {
115 infile >> left_limit >> right_limit;
116 config.xyz_.push_back(std::pair<float, float>(left_limit, right_limit));
121 for (
int i = 0; i < 12; i++) {
124 cv::Mat(3, 4, CV_32FC1, &p).copyTo(
config.P);
126 infile >>
config.MAX_ITERS;
128 for (
int i = 0; i < 3; i++) {
130 config.initialRot.push_back(angle);
133 for (
int i = 0; i < 3; i++) {
135 config.initialTra.push_back(dist);
138 infile >>
config.lidar_type;
145 pcl::PointCloud<myPointXYZRID>::Ptr
toMyPointXYZRID(
const Hesai::PointCloud &point_cloud_ptr) {
146 pcl::PointCloud<myPointXYZRID>::Ptr new_cloud(
new pcl::PointCloud <myPointXYZRID>);
147 for (
auto pt = point_cloud_ptr.points.begin(); pt < point_cloud_ptr.points.end(); pt++) {
153 myPt.
ring = pt->ring;
154 myPt.
range = pt->range;
155 new_cloud->push_back(myPt);
161 pcl::PointCloud <pcl::PointXYZ> *new_cloud =
new pcl::PointCloud<pcl::PointXYZ>();
162 for (pcl::PointCloud<myPointXYZRID>::iterator pt = point_cloud.points.begin();
163 pt < point_cloud.points.end(); pt++) {
164 new_cloud->push_back(pcl::PointXYZ(pt->x, pt->y, pt->z));
170 pcl::PointCloud <myPointXYZRID>
171 transform(pcl::PointCloud <myPointXYZRID> pc,
float x,
float y,
float z,
float rot_x,
float rot_y,
float rot_z) {
172 Eigen::Affine3f transf = pcl::getTransformation(x, y, z, rot_x, rot_y, rot_z);
173 pcl::PointCloud <myPointXYZRID> new_cloud;
174 pcl::transformPointCloud(pc, new_cloud, transf);
180 float min_found = 10e6;
181 float max_found = -10e6;
183 for (pcl::PointCloud<myPointXYZRID>::iterator pt = point_cloud.points.begin();
184 pt < point_cloud.points.end(); pt++) {
185 max_found = MAX(max_found, pt->intensity);
186 min_found = MIN(min_found, pt->intensity);
189 for (pcl::PointCloud<myPointXYZRID>::iterator pt = point_cloud.points.begin();
190 pt < point_cloud.points.end(); pt++) {
191 pt->intensity = (pt->intensity - min_found) / (max_found - min_found) * (max - min) + min;
197 pcl::PointCloud <myPointXYZRID>
200 std::vector <std::vector<myPointXYZRID *>> rings(16);
202 for (pcl::PointCloud<myPointXYZRID>::iterator pt = point_cloud.points.begin();
203 pt < point_cloud.points.end(); pt++) {
204 pt->range = (pt->x * pt->x + pt->y * pt->y + pt->z * pt->z);
205 rings[pt->ring].push_back(&(*pt));
208 for (std::vector < std::vector < myPointXYZRID * >> ::iterator
ring = rings.begin();
ring < rings.end();
217 (*(
ring->end() - 1))->intensity = 0;
218 for (std::vector<myPointXYZRID *>::iterator pt =
ring->begin() + 1; pt <
ring->end() - 1; pt++) {
223 (*pt)->
intensity = MAX(MAX(prev->
range - (*pt)->range, succ->
range - (*pt)->range), 0) * 10;
228 pcl::PointCloud <myPointXYZRID> filtered;
230 for (pcl::PointCloud<myPointXYZRID>::iterator pt = point_cloud.points.begin();
231 pt < point_cloud.points.end(); pt++) {
232 if (pt->intensity > config.intensity_thresh) {
233 if (pt->x >= config.xyz_[0].first && pt->x <= config.xyz_[0].second && pt->y >= config.xyz_[1].first &&
234 pt->y <= config.xyz_[1].second && pt->z >= config.xyz_[2].first && pt->z <= config.xyz_[2].second) {
235 filtered.push_back(*pt);
pcl::PointCloud< myPointXYZRID > intensityByRangeDiff(pcl::PointCloud< myPointXYZRID > point_cloud, config_settings config)
pcl::PointCloud< myPointXYZRID > normalizeIntensity(pcl::PointCloud< myPointXYZRID > point_cloud, float min, float max)
pcl::PointCloud< pcl::PointXYZ > * toPointsXYZ(pcl::PointCloud< myPointXYZRID > point_cloud)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
pcl::PointCloud< myPointXYZRID >::Ptr toMyPointXYZRID(const Hesai::PointCloud &point_cloud_ptr)
pcl::PointCloud< myPointXYZRID > transform(pcl::PointCloud< myPointXYZRID > pc, float x, float y, float z, float rot_x, float rot_y, float rot_z)
pcl::PointCloud< myPointXYZRID > point_cloud
POINT_CLOUD_REGISTER_POINT_STRUCT(myPointXYZRID,(float, x, x)(float, y, y)(float, z, z)(float, intensity, intensity)(uint16_t, ring, ring)) namespace Hesai
ROSLIB_DECL std::string getPath(const std::string &package_name)
uint16_t ring
laser ring number
float intensity
laser intensity reading
void print(cv::Point3f p, string cad)