25#include <opencv2/opencv.hpp>
28#include <pcl/common/transforms.h>
29#include <pcl/filters/voxel_grid.h>
30#include <pcl/impl/point_types.hpp>
31#include <pcl/pcl_macros.h>
32#include <pcl/point_cloud.h>
33#include <pcl/point_types.h>
34#include <pcl/registration/icp.h>
35#include <pcl/visualization/pcl_visualizer.h>
38const bool ENABLE_SPATIAL_MAPPING =
false;
49pcl::PointCloud<pcl::PointXYZ>::Ptr convertCVMatToPCL(
const cv::Mat& cvPointCloud)
51 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
53 for (
int i = 0; i < cvPointCloud.
rows; ++i)
55 for (
int j = 0; j < cvPointCloud.
cols; ++j)
60 if (std::isfinite(point[0]) && std::isfinite(point[1]) && std::isfinite(point[2]))
62 pcl::PointXYZ pclPoint;
63 pclPoint.x = point[0];
64 pclPoint.y = point[1];
65 pclPoint.z = point[2];
66 cloud->points.push_back(pclPoint);
70 cloud->width =
static_cast<uint32_t>(cloud->points.size());
88 std::shared_ptr<ZEDCamera> pExampleZEDCam1 = globals::g_pCameraHandler->GetZED(CameraHandler::ZEDCamName::eHeadMainCam);
90 pExampleZEDCam1->Start();
93 pExampleZEDCam1->EnablePositionalTracking();
95 if (ENABLE_SPATIAL_MAPPING)
98 pExampleZEDCam1->EnableSpatialMapping();
117 pcl::PointCloud<pcl::PointXYZ>::Ptr pclGlobalMap(
new pcl::PointCloud<pcl::PointXYZ>);
119 pcl::visualization::PCLVisualizer::Ptr pclViewer(
new pcl::visualization::PCLVisualizer(
"SLAM Viewer"));
128 std::future<bool> fuFrameCopyStatus;
129 std::future<bool> fuDepthCopyStatus;
130 std::future<bool> fuPointCloudCopyStatus;
133 if (pExampleZEDCam1->GetUsingGPUMem())
136 fuFrameCopyStatus = pExampleZEDCam1->RequestFrameCopy(cvGPUNormalFrame1);
137 fuDepthCopyStatus = pExampleZEDCam1->RequestDepthCopy(cvGPUDepthFrame1,
false);
138 fuPointCloudCopyStatus = pExampleZEDCam1->RequestPointCloudCopy(cvGPUPointCloud1);
143 fuFrameCopyStatus = pExampleZEDCam1->RequestFrameCopy(cvNormalFrame1);
144 fuDepthCopyStatus = pExampleZEDCam1->RequestDepthCopy(cvDepthFrame1,
false);
145 fuPointCloudCopyStatus = pExampleZEDCam1->RequestPointCloudCopy(cvPointCloud1);
148 std::future<bool> fuPoseCopyStatus = pExampleZEDCam1->RequestPositionalPoseCopy(stPose);
151 if (fuFrameCopyStatus.get() && fuDepthCopyStatus.get() && fuPointCloudCopyStatus.get())
154 if (pExampleZEDCam1->GetUsingGPUMem())
157 cvGPUNormalFrame1.
download(cvNormalFrame1);
158 cvGPUDepthFrame1.
download(cvDepthFrame1);
159 cvGPUPointCloud1.
download(cvPointCloud1);
164 std::to_string(pExampleZEDCam1->GetIPS().GetExactIPS()),
172 std::to_string(pExampleZEDCam1->GetIPS().GetExactIPS()),
182 if (fuPoseCopyStatus.get())
184 LOG_INFO(logging::g_qConsoleLogger,
185 "Positional Tracking: X: {} | Y: {} | Z: {}",
186 stPose.stTranslation.dX,
187 stPose.stTranslation.dY,
188 stPose.stTranslation.dZ);
189 LOG_INFO(logging::g_qConsoleLogger,
190 "Positional Orientation: Roll: {} | Pitch: {} | Yaw: {}",
191 stPose.stEulerAngles.dXO,
192 stPose.stEulerAngles.dYO,
193 stPose.stEulerAngles.dZO);
197 LOG_INFO(logging::g_qConsoleLogger,
"ZED Getter FPS: {} | 1% Low: {}", pExampleZEDCam1->GetIPS().GetAverageIPS(), pExampleZEDCam1->GetIPS().Get1PercentLow());
199 if (ENABLE_SPATIAL_MAPPING)
201 LOG_INFO(logging::g_qConsoleLogger,
"Spatial Mapping State: {}", sl::toString(pExampleZEDCam1->GetSpatialMappingState()).get());
207 cv::imshow(
"POINT CLOUD COLOR 1", cvPointCloudColor1);
265 LOG_INFO(logging::g_qConsoleLogger,
"Main FPS: {}", FPS.
GetAverageIPS());
276 if (ENABLE_SPATIAL_MAPPING)
279 std::future<sl::Mesh> fuSpatialMap;
280 pExampleZEDCam1->ExtractSpatialMapAsync(fuSpatialMap);
281 sl::Mesh slSpatialMap = fuSpatialMap.get();
282 slSpatialMap.save(
"test.obj", sl::MESH_FILE_FORMAT::PLY);
289 network::g_bRoveCommUDPStatus =
false;
290 network::g_bRoveCommTCPStatus =
false;
293 globals::g_pCameraHandler->StopAllCameras();
Declares constants for the autonomy software.
Defines functions and objects used project wide.
Implements Logging for Autonomy.
Defines functions and objects used for Autonomy Networking.
This file is a utility used to check if any file from the example directory has been included....
void RunExample()
Example function to demonstrate the usage of LiDARHandler.
Definition GeoPlanner.hpp:25
Defines and implements functions related to GENERAL operations on images. All functions are defined w...
The CameraHandler class is responsible for managing all of the camera feeds that Autonomy_Software us...
Definition CameraHandler.h:34
This util class provides an easy way to keep track of iterations per second for any body of code.
Definition IPS.hpp:30
double GetAverageIPS() const
Calculates the average iterations per second.
Definition IPS.hpp:180
void Tick()
This method is used to update the iterations per second counter and recalculate all of the IPS metric...
Definition IPS.hpp:138
void download(OutputArray dst) const
void imshow(const String &winname, InputArray mat)
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
void SplitPointCloudColors(cv::Mat &cvInputPointCloud, cv::Mat &cvOutputColors)
Given a cv::Mat containing X, Y, Z, and BGRA values for each pixel in the third dimension,...
Definition ImageOperations.hpp:181
This struct is used within the ZEDCam class to store the camera pose with high precision....
Definition ZEDCamera.hpp:77