8 #include "opencv2/opencv.hpp" 9 #include <pcl/point_cloud.h> 10 #include <pcl/io/pcd_io.h> 13 #include <boost/foreach.hpp> 16 #include <linux/version.h> 18 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) 19 #include <velodyne_pointcloud/point_types.h> 22 #include <velodyne_pcl/point_types.h> 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> 34 cv::Mat pt_3D(4, 1, CV_32FC1);
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;
41 cv::Mat pt_2D = projection_matrix * pt_3D;
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);
50 pcl::PointCloud <pcl::PointXYZ> *visible_points) {
51 cv::Mat plane = cv::Mat::zeros(frame.size(), CV_32FC1);
53 for (pcl::PointCloud<pcl::PointXYZ>::iterator pt = point_cloud.points.begin();
54 pt < point_cloud.points.end(); pt++) {
62 cv::Point xy =
project(*pt, projection_matrix);
63 if (xy.inside(frame)) {
64 if (visible_points != NULL) {
65 visible_points->push_back(*pt);
68 plane.at<
float>(xy) = 250;
73 cv::normalize(plane, plane_gray, 0, 255, cv::NORM_MINMAX, CV_8UC1);
74 cv::dilate(plane_gray, plane_gray, cv::Mat());
79 void onMouse(
int event,
int x,
int y,
int f,
void *g) {
81 cv::Point *P =
static_cast<cv::Point *
>(g);
84 case cv::EVENT_LBUTTONDOWN :
89 case cv::EVENT_LBUTTONUP :
void onMouse(int event, int x, int y, int f, void *g)
cv::Point project(const pcl::PointXYZ &pt, const cv::Mat &projection_matrix)
TFSIMD_FORCE_INLINE const tfScalar & y() const
pcl::PointCloud< myPointXYZRID > point_cloud
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & w() const