Main example function.
119{
120
122
123
125
126
127 std::shared_ptr<ZEDCamera> pExampleZEDCam1 = globals::g_pCameraHandler->GetZED(CameraHandler::ZEDCamName::eHeadMainCam);
128
129 pExampleZEDCam1->Start();
130
131
139
141
142
144
145
147
148
149 while (true)
150 {
151
152 std::future<bool> fuDepthCopyStatus;
153 std::future<bool> fuPointCloudCopyStatus;
154
155
156 if (pExampleZEDCam1->GetUsingGPUMem())
157 {
158
159 fuDepthCopyStatus = pExampleZEDCam1->RequestDepthCopy(cvGPUDepthFrame1);
160 fuPointCloudCopyStatus = pExampleZEDCam1->RequestPointCloudCopy(cvGPUPointCloud1);
161 }
162 else
163 {
164
165 fuDepthCopyStatus = pExampleZEDCam1->RequestDepthCopy(cvDepthFrame1);
166 fuPointCloudCopyStatus = pExampleZEDCam1->RequestPointCloudCopy(cvPointCloud1);
167 }
168
169
170 if (fuDepthCopyStatus.get() && fuPointCloudCopyStatus.get())
171 {
172 if (pExampleZEDCam1->GetUsingGPUMem())
173 {
174
175 cvGPUDepthFrame1.
download(cvDepthFrame1);
176 cvGPUPointCloud1.
download(cvPointCloud1);
177 }
178
179
180 if (!cvDepthFrame1.
empty())
181 {
182
186
187
189
190
193 }
194
195
196 static pcl::PointCloud<pcl::PointXYZ>::Ptr pclCloud(new pcl::PointCloud<pcl::PointXYZ>());
197 static pcl::PointCloud<pcl::PointXYZ>::Ptr pclFilteredPointCloud(new pcl::PointCloud<pcl::PointXYZ>);
198 static pcl::PointCloud<pcl::PointXYZ>::Ptr pclDownsampledPointCloud(new pcl::PointCloud<pcl::PointXYZ>);
199 static pcl::visualization::PCLVisualizer::Ptr pclViewer;
200
201
202 if (!pclViewer)
203 {
204 pclViewer.reset(new pcl::visualization::PCLVisualizer("Depth Point Cloud"));
205 pclViewer->setBackgroundColor(0, 0, 0);
206 pclViewer->addPointCloud<pcl::PointXYZ>(pclDownsampledPointCloud, "depth_cloud");
207 pclViewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "depth_cloud");
208 pclViewer->addCoordinateSystem(20.0);
209 pclViewer->initCameraParameters();
210 }
211
212
213 pclCloud->width = cvPointCloud1.
cols;
214 pclCloud->height = cvPointCloud1.
rows;
215 pclCloud->is_dense = false;
216 pclCloud->points.resize(pclCloud->width * pclCloud->height);
217
218
219 for (
int nY = 0; nY < cvPointCloud1.
rows; ++nY)
220 {
221 for (
int nX = 0; nX < cvPointCloud1.
cols; ++nX)
222 {
224 size_t siIDx = nY * cvPointCloud1.
cols + nX;
225
226
227 if (cvPoint[2] > 0)
228 {
229 pclCloud->points[siIDx].x = cvPoint[0];
230 pclCloud->points[siIDx].y = cvPoint[1];
231 pclCloud->points[siIDx].z = cvPoint[2];
232 }
233 else
234 {
235
236 pclCloud->points[siIDx].x = std::numeric_limits<float>::quiet_NaN();
237 pclCloud->points[siIDx].y = std::numeric_limits<float>::quiet_NaN();
238 pclCloud->points[siIDx].z = std::numeric_limits<float>::quiet_NaN();
239 }
240 }
241 }
242
243
244 std::vector<int> vIndices;
245 pcl::removeNaNFromPointCloud(*pclCloud, *pclFilteredPointCloud, vIndices);
246
247 pcl::VoxelGrid<pcl::PointXYZ> pclVoxelGrid;
248 pclVoxelGrid.setInputCloud(pclFilteredPointCloud);
249 pclVoxelGrid.setLeafSize(VOXEL_GRID_LEAF_SIZE, VOXEL_GRID_LEAF_SIZE, VOXEL_GRID_LEAF_SIZE);
250 pclVoxelGrid.filter(*pclDownsampledPointCloud);
251
252 pclViewer->updatePointCloud(pclDownsampledPointCloud, "depth_cloud");
253 pclViewer->spinOnce(10);
254 }
255
256
258
260 if (chKey == 27)
261 break;
262 }
263
264
266
268
270
271 network::g_bRoveCommUDPStatus = false;
272 network::g_bRoveCommTCPStatus = false;
273
274
275 globals::g_pCameraHandler->StopAllCameras();
276}
void DepthMouseCallback(int nEvent, int nX, int nY, int nFlags, void *pUserData)
Mouse callback function for depth image clicks.
Definition ZEDCAMPointCloudTest.hpp:52
void SuppressPCLLogging()
Suppresses PCL logging messages.
Definition ZEDCAMPointCloudTest.hpp:106
void PointCloudMouseCallback(int nEvent, int nX, int nY, int nFlags, void *pUserData)
Mouse callback function for point cloud clicks.
Definition ZEDCAMPointCloudTest.hpp:82
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
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
static Vec< _Tp, cn > normalize(const Vec< _Tp, cn > &v)
void imshow(const String &winname, InputArray mat)
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
void setMouseCallback(const String &winname, MouseCallback onMouse, void *userdata=0)
void applyColorMap(InputArray src, OutputArray dst, int colormap)
This struct is used within the ZEDCam class to store the camera pose with high precision....
Definition ZEDCamera.hpp:77