Skip to content

Commit aaef365

Browse files
authored
Check camera resolution (gazebosim#480)
Signed-off-by: Ian Chen <ichen@openrobotics.org>
1 parent 2f22722 commit aaef365

7 files changed

+55
-6
lines changed

src/BoundingBoxCameraSensor.cc

+7
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

+7
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

+9-2
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

+9-2
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

+7
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

+9-2
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

+7
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)

0 commit comments

Comments
 (0)