Skip to content

Commit

Permalink
Merge pull request #495 from gazebosim/merge_9_main_20250114
Browse files Browse the repository at this point in the history
Merge 9 -> main
  • Loading branch information
iche033 authored Jan 15, 2025
2 parents 5569e6f + c36a5c4 commit 5562031
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/BoundingBoxCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,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);
Expand Down
7 changes: 7 additions & 0 deletions src/CameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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);
Expand Down
11 changes: 9 additions & 2 deletions src/DepthCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,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();
Expand Down
11 changes: 9 additions & 2 deletions src/RgbdCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,15 @@ bool RgbdCameraSensor::CreateCameras()
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 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 @@ -353,6 +353,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)
{
Expand Down
11 changes: 9 additions & 2 deletions src/ThermalCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,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();

Expand Down
23 changes: 22 additions & 1 deletion src/WideAngleCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,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)
Expand Down Expand Up @@ -326,6 +333,12 @@ bool WideAngleCameraSensor::CreateCamera()
case sdf::PixelFormatType::RGB_INT8:
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_R8G8B8);
break;
case sdf::PixelFormatType::L_INT8:
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_L8);
break;
case sdf::PixelFormatType::L_INT16:
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_L16);
break;
default:
gzerr << "Unsupported pixel format ["
<< static_cast<int>(pixelFormat) << "]\n";
Expand Down Expand Up @@ -360,7 +373,9 @@ void WideAngleCameraSensor::OnNewWideAngleFrame(
{
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);

unsigned int len = _width * _height * _channels;
unsigned int bytesPerChannel = rendering::PixelUtil::BytesPerChannel(
this->dataPtr->camera->ImageFormat());
unsigned int len = _width * _height * _channels * bytesPerChannel;
unsigned int bufferSize = len * sizeof(unsigned char);

if (!this->dataPtr->imageBuffer)
Expand Down Expand Up @@ -460,6 +475,12 @@ bool WideAngleCameraSensor::Update(
format = gz::common::Image::RGB_INT8;
msgsPixelFormat = msgs::PixelFormatType::RGB_INT8;
break;
case gz::rendering::PF_L8:
msgsPixelFormat = msgs::PixelFormatType::L_INT8;
break;
case gz::rendering::PF_L16:
msgsPixelFormat = msgs::PixelFormatType::L_INT16;
break;
default:
gzerr << "Unsupported pixel format ["
<< this->dataPtr->camera->ImageFormat() << "]\n";
Expand Down

0 comments on commit 5562031

Please sign in to comment.