From 9713f06c8f539574635e1ad7ead0321d6e7c3e77 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 11 Nov 2024 01:09:21 -0800 Subject: [PATCH 1/2] Check camera resolution (#480) Signed-off-by: Ian Chen (cherry picked from commit aaef365e6c51dcf98334e9f7a70e5fc4e3281f91) # Conflicts: # src/RgbdCameraSensor.cc --- src/BoundingBoxCameraSensor.cc | 7 +++++++ src/CameraSensor.cc | 7 +++++++ src/DepthCameraSensor.cc | 11 +++++++++-- src/RgbdCameraSensor.cc | 12 ++++++++++++ src/SegmentationCameraSensor.cc | 7 +++++++ src/ThermalCameraSensor.cc | 11 +++++++++-- src/WideAngleCameraSensor.cc | 7 +++++++ 7 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/BoundingBoxCameraSensor.cc b/src/BoundingBoxCameraSensor.cc index 777dc14a..6733f02f 100644 --- a/src/BoundingBoxCameraSensor.cc +++ b/src/BoundingBoxCameraSensor.cc @@ -316,6 +316,13 @@ bool BoundingBoxCameraSensor::CreateCamera() auto width = sdfCamera->ImageWidth(); auto height = sdfCamera->ImageHeight(); + if (width == 0u || height == 0u) + { + gzerr << "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); diff --git a/src/CameraSensor.cc b/src/CameraSensor.cc index 11811862..ca62a5ed 100644 --- a/src/CameraSensor.cc +++ b/src/CameraSensor.cc @@ -212,6 +212,13 @@ bool CameraSensor::CreateCamera() unsigned int width = cameraSdf->ImageWidth(); unsigned int height = cameraSdf->ImageHeight(); + if (width == 0u || height == 0u) + { + gzerr << "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); diff --git a/src/DepthCameraSensor.cc b/src/DepthCameraSensor.cc index f965e18e..05fca45c 100644 --- a/src/DepthCameraSensor.cc +++ b/src/DepthCameraSensor.cc @@ -324,8 +324,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) + { + gzerr << "Unable to create a depth camera sensor with 0 width or height." + << std::endl; + return false; + } double far = cameraSdf->FarClip(); double near = cameraSdf->NearClip(); diff --git a/src/RgbdCameraSensor.cc b/src/RgbdCameraSensor.cc index 9009b658..0349d249 100644 --- a/src/RgbdCameraSensor.cc +++ b/src/RgbdCameraSensor.cc @@ -274,10 +274,22 @@ bool RgbdCameraSensor::CreateCameras() return false; } +<<<<<<< HEAD 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) + { + gzerr << "Unable to create an RGBD camera sensor with 0 width or height." + << std::endl; + return false; + } +>>>>>>> aaef365 (Check camera resolution (#480)) this->dataPtr->depthCamera = this->Scene()->CreateDepthCamera(this->Name()); diff --git a/src/SegmentationCameraSensor.cc b/src/SegmentationCameraSensor.cc index 70fa38f8..8cab3657 100644 --- a/src/SegmentationCameraSensor.cc +++ b/src/SegmentationCameraSensor.cc @@ -345,6 +345,13 @@ bool SegmentationCameraSensor::CreateCamera() auto width = sdfCamera->ImageWidth(); auto height = sdfCamera->ImageHeight(); + if (width == 0u || height == 0u) + { + gzerr << "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 > GZ_PI*2) { diff --git a/src/ThermalCameraSensor.cc b/src/ThermalCameraSensor.cc index b87112df..94267650 100644 --- a/src/ThermalCameraSensor.cc +++ b/src/ThermalCameraSensor.cc @@ -244,8 +244,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) + { + gzerr << "Unable to create a thermal camera sensor with 0 width or height." + << std::endl; + return false; + } sdf::PixelFormatType pixelFormat = cameraSdf->PixelFormat(); diff --git a/src/WideAngleCameraSensor.cc b/src/WideAngleCameraSensor.cc index c1ddb2fb..856da09e 100644 --- a/src/WideAngleCameraSensor.cc +++ b/src/WideAngleCameraSensor.cc @@ -217,6 +217,13 @@ bool WideAngleCameraSensor::CreateCamera() unsigned int width = cameraSdf->ImageWidth(); unsigned int height = cameraSdf->ImageHeight(); + if (width == 0u || height == 0u) + { + gzerr << "Unable to create a wide angle camera sensor with 0 width or " + << "height." << std::endl; + return false; + } + this->dataPtr->camera = this->Scene()->CreateWideAngleCamera(this->Name()); if (!this->dataPtr->camera) From 55e527e2632ad2e7f974b89ea5627c36c2b05a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Mon, 11 Nov 2024 10:20:14 +0100 Subject: [PATCH 2/2] Fixed merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- src/RgbdCameraSensor.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/RgbdCameraSensor.cc b/src/RgbdCameraSensor.cc index 0349d249..4b1bf7ae 100644 --- a/src/RgbdCameraSensor.cc +++ b/src/RgbdCameraSensor.cc @@ -274,12 +274,8 @@ bool RgbdCameraSensor::CreateCameras() return false; } -<<<<<<< HEAD this->PopulateInfo(cameraSdf); - int width = cameraSdf->ImageWidth(); - int height = cameraSdf->ImageHeight(); -======= unsigned int width = cameraSdf->ImageWidth(); unsigned int height = cameraSdf->ImageHeight(); @@ -289,7 +285,6 @@ bool RgbdCameraSensor::CreateCameras() << std::endl; return false; } ->>>>>>> aaef365 (Check camera resolution (#480)) this->dataPtr->depthCamera = this->Scene()->CreateDepthCamera(this->Name());