Skip to content

Commit 5562031

Browse files
authored
Merge pull request #495 from gazebosim/merge_9_main_20250114
Merge 9 -> main
2 parents 5569e6f + c36a5c4 commit 5562031

File tree

7 files changed

+70
-7
lines changed

7 files changed

+70
-7
lines changed

src/BoundingBoxCameraSensor.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ bool BoundingBoxCameraSensor::CreateCamera()
293293
auto width = sdfCamera->ImageWidth();
294294
auto height = sdfCamera->ImageHeight();
295295

296+
if (width == 0u || height == 0u)
297+
{
298+
gzerr << "Unable to create a bounding box camera sensor with 0 width or "
299+
<< "height. " << std::endl;
300+
return false;
301+
}
302+
296303
// Set Camera Properties
297304
this->dataPtr->rgbCamera->SetImageFormat(rendering::PF_R8G8B8);
298305
this->dataPtr->rgbCamera->SetImageWidth(width);

src/CameraSensor.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ bool CameraSensor::CreateCamera()
144144
unsigned int width = cameraSdf->ImageWidth();
145145
unsigned int height = cameraSdf->ImageHeight();
146146

147+
if (width == 0u || height == 0u)
148+
{
149+
gzerr << "Unable to create a camera sensor with 0 width or height."
150+
<< std::endl;
151+
return false;
152+
}
153+
147154
this->dataPtr->camera = this->Scene()->CreateCamera(this->Name());
148155
this->dataPtr->camera->SetImageWidth(width);
149156
this->dataPtr->camera->SetImageHeight(height);

src/DepthCameraSensor.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,15 @@ bool DepthCameraSensor::CreateCamera()
337337
return false;
338338
}
339339

340-
int width = cameraSdf->ImageWidth();
341-
int height = cameraSdf->ImageHeight();
340+
unsigned int width = cameraSdf->ImageWidth();
341+
unsigned int height = cameraSdf->ImageHeight();
342+
343+
if (width == 0u || height == 0u)
344+
{
345+
gzerr << "Unable to create a depth camera sensor with 0 width or height."
346+
<< std::endl;
347+
return false;
348+
}
342349

343350
double far = cameraSdf->FarClip();
344351
double near = cameraSdf->NearClip();

src/RgbdCameraSensor.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,15 @@ bool RgbdCameraSensor::CreateCameras()
278278
return false;
279279
}
280280

281-
int width = cameraSdf->ImageWidth();
282-
int height = cameraSdf->ImageHeight();
281+
unsigned int width = cameraSdf->ImageWidth();
282+
unsigned int height = cameraSdf->ImageHeight();
283+
284+
if (width == 0u || height == 0u)
285+
{
286+
gzerr << "Unable to create an RGBD camera sensor with 0 width or height."
287+
<< std::endl;
288+
return false;
289+
}
283290

284291
this->dataPtr->depthCamera =
285292
this->Scene()->CreateDepthCamera(this->Name());

src/SegmentationCameraSensor.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ bool SegmentationCameraSensor::CreateCamera()
353353
auto width = sdfCamera->ImageWidth();
354354
auto height = sdfCamera->ImageHeight();
355355

356+
if (width == 0u || height == 0u)
357+
{
358+
gzerr << "Unable to create a segmentation camera sensor with 0 width or "
359+
<< "height." << std::endl;
360+
return false;
361+
}
362+
356363
math::Angle angle = sdfCamera->HorizontalFov();
357364
if (angle < 0.01 || angle > GZ_PI*2)
358365
{

src/ThermalCameraSensor.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,15 @@ bool ThermalCameraSensor::CreateCamera()
255255
return false;
256256
}
257257

258-
int width = cameraSdf->ImageWidth();
259-
int height = cameraSdf->ImageHeight();
258+
unsigned int width = cameraSdf->ImageWidth();
259+
unsigned int height = cameraSdf->ImageHeight();
260+
261+
if (width == 0u || height == 0u)
262+
{
263+
gzerr << "Unable to create a thermal camera sensor with 0 width or height."
264+
<< std::endl;
265+
return false;
266+
}
260267

261268
sdf::PixelFormatType pixelFormat = cameraSdf->PixelFormat();
262269

src/WideAngleCameraSensor.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ bool WideAngleCameraSensor::CreateCamera()
228228
unsigned int width = cameraSdf->ImageWidth();
229229
unsigned int height = cameraSdf->ImageHeight();
230230

231+
if (width == 0u || height == 0u)
232+
{
233+
gzerr << "Unable to create a wide angle camera sensor with 0 width or "
234+
<< "height." << std::endl;
235+
return false;
236+
}
237+
231238
this->dataPtr->camera = this->Scene()->CreateWideAngleCamera(this->Name());
232239

233240
if (!this->dataPtr->camera)
@@ -326,6 +333,12 @@ bool WideAngleCameraSensor::CreateCamera()
326333
case sdf::PixelFormatType::RGB_INT8:
327334
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_R8G8B8);
328335
break;
336+
case sdf::PixelFormatType::L_INT8:
337+
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_L8);
338+
break;
339+
case sdf::PixelFormatType::L_INT16:
340+
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_L16);
341+
break;
329342
default:
330343
gzerr << "Unsupported pixel format ["
331344
<< static_cast<int>(pixelFormat) << "]\n";
@@ -360,7 +373,9 @@ void WideAngleCameraSensor::OnNewWideAngleFrame(
360373
{
361374
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
362375

363-
unsigned int len = _width * _height * _channels;
376+
unsigned int bytesPerChannel = rendering::PixelUtil::BytesPerChannel(
377+
this->dataPtr->camera->ImageFormat());
378+
unsigned int len = _width * _height * _channels * bytesPerChannel;
364379
unsigned int bufferSize = len * sizeof(unsigned char);
365380

366381
if (!this->dataPtr->imageBuffer)
@@ -460,6 +475,12 @@ bool WideAngleCameraSensor::Update(
460475
format = gz::common::Image::RGB_INT8;
461476
msgsPixelFormat = msgs::PixelFormatType::RGB_INT8;
462477
break;
478+
case gz::rendering::PF_L8:
479+
msgsPixelFormat = msgs::PixelFormatType::L_INT8;
480+
break;
481+
case gz::rendering::PF_L16:
482+
msgsPixelFormat = msgs::PixelFormatType::L_INT16;
483+
break;
463484
default:
464485
gzerr << "Unsupported pixel format ["
465486
<< this->dataPtr->camera->ImageFormat() << "]\n";

0 commit comments

Comments
 (0)