Skip to content

Commit

Permalink
Check camera sensors have non-zero width or height (backport #480) (#481
Browse files Browse the repository at this point in the history
)

* Check camera resolution (#480)

Signed-off-by: Ian Chen <[email protected]>
(cherry picked from commit aaef365)

Signed-off-by: Alejandro Hernández Cordero <[email protected]>
Co-authored-by: Ian Chen <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent 9b40869 commit b15ba73
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/BoundingBoxCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ bool BoundingBoxCameraSensor::CreateCamera()
auto width = sdfCamera->ImageWidth();
auto height = sdfCamera->ImageHeight();

if (width == 0u || height == 0u)
{
ignerr << "Unable to create a bounding box camera sensor with 0 width or "
<< "height. " << std::endl;
return false;
}

// Set Camera Properties
this->dataPtr->rgbCamera->SetImageFormat(rendering::PF_R8G8B8);
this->dataPtr->rgbCamera->SetImageWidth(width);
Expand Down
7 changes: 7 additions & 0 deletions src/CameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ bool CameraSensor::CreateCamera()
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
ignerr << "Unable to create a camera sensor with 0 width or height."
<< std::endl;
return false;
}

this->dataPtr->camera = this->Scene()->CreateCamera(this->Name());
this->dataPtr->camera->SetImageWidth(width);
this->dataPtr->camera->SetImageHeight(height);
Expand Down
11 changes: 9 additions & 2 deletions src/DepthCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,15 @@ bool DepthCameraSensor::CreateCamera()
return false;
}

int width = cameraSdf->ImageWidth();
int height = cameraSdf->ImageHeight();
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
ignerr << "Unable to create a depth camera sensor with 0 width or height."
<< std::endl;
return false;
}

double far = cameraSdf->FarClip();
double near = cameraSdf->NearClip();
Expand Down
11 changes: 9 additions & 2 deletions src/RgbdCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,15 @@ bool RgbdCameraSensor::CreateCameras()

this->PopulateInfo(cameraSdf);

int width = cameraSdf->ImageWidth();
int height = cameraSdf->ImageHeight();
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
ignerr << "Unable to create an RGBD camera sensor with 0 width or height."
<< std::endl;
return false;
}

this->dataPtr->depthCamera =
this->Scene()->CreateDepthCamera(this->Name());
Expand Down
7 changes: 7 additions & 0 deletions src/SegmentationCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ bool SegmentationCameraSensor::CreateCamera()
auto width = sdfCamera->ImageWidth();
auto height = sdfCamera->ImageHeight();

if (width == 0u || height == 0u)
{
ignerr << "Unable to create a segmentation camera sensor with 0 width or "
<< "height." << std::endl;
return false;
}

math::Angle angle = sdfCamera->HorizontalFov();
if (angle < 0.01 || angle > IGN_PI*2)
{
Expand Down
11 changes: 9 additions & 2 deletions src/ThermalCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,15 @@ bool ThermalCameraSensor::CreateCamera()
return false;
}

int width = cameraSdf->ImageWidth();
int height = cameraSdf->ImageHeight();
unsigned int width = cameraSdf->ImageWidth();
unsigned int height = cameraSdf->ImageHeight();

if (width == 0u || height == 0u)
{
ignerr << "Unable to create a thermal camera sensor with 0 width or height."
<< std::endl;
return false;
}

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

Expand Down

0 comments on commit b15ba73

Please sign in to comment.