Utils.h
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <cstdio>
3 #include <iostream>
4 #include <map>
5 #include <fstream>
6 #include <cmath>
7 
8 #include "opencv2/opencv.hpp"
9 #include <pcl/point_cloud.h>
10 #include <pcl/io/pcd_io.h>
11 
12 #include <pcl_ros/point_cloud.h>
13 #include <boost/foreach.hpp>
15 
16 #include <linux/version.h>
17 
18 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)
19 #include <velodyne_pointcloud/point_types.h>
20 #else
21 
22 #include <velodyne_pcl/point_types.h>
23 
24 #endif
25 
26 #include <pcl/common/eigen.h>
27 #include <pcl/common/transforms.h>
28 #include <pcl/filters/passthrough.h>
29 #include <pcl/sample_consensus/ransac.h>
30 #include <pcl/sample_consensus/sac_model_line.h>
31 #include <pcl/common/intersections.h>
32 
33 cv::Point project(const pcl::PointXYZ &pt, const cv::Mat &projection_matrix) {
34  cv::Mat pt_3D(4, 1, CV_32FC1);
35 
36  pt_3D.at<float>(0) = pt.x;
37  pt_3D.at<float>(1) = pt.y;
38  pt_3D.at<float>(2) = pt.z;
39  pt_3D.at<float>(3) = 1.0f;
40 
41  cv::Mat pt_2D = projection_matrix * pt_3D;
42 
43  float w = pt_2D.at<float>(2);
44  float x = pt_2D.at<float>(0) / w;
45  float y = pt_2D.at<float>(1) / w;
46  return cv::Point(x, y);
47 }
48 
49 cv::Mat project(cv::Mat projection_matrix, cv::Rect frame, pcl::PointCloud <pcl::PointXYZ> point_cloud,
50  pcl::PointCloud <pcl::PointXYZ> *visible_points) {
51  cv::Mat plane = cv::Mat::zeros(frame.size(), CV_32FC1);
52 
53  for (pcl::PointCloud<pcl::PointXYZ>::iterator pt = point_cloud.points.begin();
54  pt < point_cloud.points.end(); pt++) {
55 
56  // behind the camera
57  if (pt->z < 0) {
58  continue;
59  }
60 
61  //float intensity = pt->intensity;
62  cv::Point xy = project(*pt, projection_matrix);
63  if (xy.inside(frame)) {
64  if (visible_points != NULL) {
65  visible_points->push_back(*pt);
66  }
67 
68  plane.at<float>(xy) = 250;
69  }
70  }
71 
72  cv::Mat plane_gray;
73  cv::normalize(plane, plane_gray, 0, 255, cv::NORM_MINMAX, CV_8UC1);
74  cv::dilate(plane_gray, plane_gray, cv::Mat());
75 
76  return plane_gray;
77 }
78 
79 void onMouse(int event, int x, int y, int f, void *g) {
80 
81  cv::Point *P = static_cast<cv::Point *>(g);
82  switch (event) {
83 
84  case cv::EVENT_LBUTTONDOWN :
85  P->x = x;
86  P->y = y;
87  break;
88 
89  case cv::EVENT_LBUTTONUP :
90  P->x = x;
91  P->y = y;
92  break;
93 
94  default :
95  break;
96 
97 
98  }
99 
100 }
void onMouse(int event, int x, int y, int f, void *g)
Definition: Utils.h:79
cv::Point project(const pcl::PointXYZ &pt, const cv::Mat &projection_matrix)
Definition: Utils.h:33
TFSIMD_FORCE_INLINE const tfScalar & y() const
pcl::PointCloud< myPointXYZRID > point_cloud
Mat projection_matrix
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & w() const


lidar_camera_calibration
Author(s):
autogenerated on Sat Feb 6 2021 03:39:37