Skip to content

Commit 19c7bb8

Browse files
author
ChuckEllison
committed
rfix pointcloud2 crash
1 parent 73df85e commit 19c7bb8

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

src/subscribers/pointcloud2_subscriber.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,31 @@ void PointCloud2Subscriber::subscriberCallback(const sensor_msgs::msg::PointClou
175175
int u = int(img_pts[i].x);
176176
int v = int(img_pts[i].y);
177177

178-
// Check if point is inside field of view and has valid projection
179-
// Filter out rear points that are incorrectly projected into front view
180-
// Keep points that are properly in front of sensor for current camera view
181-
// RELAXED BOUNDS: Allow points slightly outside FOV to capture more lidar data
178+
// Check if inflated point is inside field of view.
179+
// The scaling requires capturing points that slightly outside FOV.
180+
// Take care transfering to image since it will crash if the pixels
181+
// outside FOV are applied to image.
182182
if ((u >= -pixel_size_) && (u < width_ + pixel_size_) &&
183183
(v >= -pixel_size_) && (v < height_ + pixel_size_) &&
184184
obj_pts[i].z > 0.1) // Filter out points behind/very close to sensor that cause incorrect projection
185185
{
186-
// update depth image
187-
if(depthImage.image.at<float>(v, u) > obj_pts[i].z)
186+
// draw box around each pixel based on pixel_size param
187+
int shift = pixel_size_ / 2;
188+
int lowerIndex1 = v - shift;
189+
if(lowerIndex1 < 0) lowerIndex1 = 0;
190+
int upperIndex1 = v + shift;
191+
if(upperIndex1 > height_ - 1) upperIndex1 = height_ - 1;
192+
int lowerIndex2 = u - shift;
193+
if(lowerIndex2 < 0) lowerIndex2 = 0;
194+
int upperIndex2 = u + shift;
195+
if(upperIndex2 > width_ - 1) upperIndex2 = width_ - 1;
196+
for(int j = lowerIndex1; j <= upperIndex1; j++)
188197
{
189-
// draw box around each pixel based on pixel_size param
190-
int shift = pixel_size_ / 2;
191-
int lowerIndex1 = v - shift;
192-
if(lowerIndex1 < 0) lowerIndex1 = 0;
193-
int upperIndex1 = v + shift;
194-
if(upperIndex1 > height_ - 1) upperIndex1 = height_ - 1;
195-
int lowerIndex2 = u - shift;
196-
if(lowerIndex2 < 0) lowerIndex2 = 0;
197-
int upperIndex2 = u + shift;
198-
if(upperIndex2 > width_ - 1) upperIndex2 = width_ - 1;
199-
for(int j = lowerIndex1; j <= upperIndex1; j++)
198+
for(int k = lowerIndex2; k <= upperIndex2; k++)
200199
{
201-
for(int k = lowerIndex2; k <= upperIndex2; k++)
200+
// Update the depth image if point is closer to camera that previous values
201+
if(depthImage.image.at<float>(j, k) > obj_pts[i].z)
202202
{
203-
// Update the depth image if point is closer to camera
204203
depthImage.image.at<float>(j, k) = obj_pts[i].z;
205204
depthMask.at<uint8_t>(j, k) = 255; // 255 = has data, 0 = no data
206205

0 commit comments

Comments
 (0)