Skip to content

Commit

Permalink
Fix readability warning and comments
Browse files Browse the repository at this point in the history
Signed-off-by: Shameek Ganguly <[email protected]>
  • Loading branch information
shameekganguly committed Oct 2, 2023
1 parent 0e338b3 commit 6650772
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 4 deletions.
47 changes: 45 additions & 2 deletions src/DepthCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ bool DepthCameraSensor::CreateCamera()
cameraSdf->SetLensIntrinsicsCx(intrinsicMatrix(0, 2));
cameraSdf->SetLensIntrinsicsCy(intrinsicMatrix(1, 2));
}
// set custom projection matrix based on intrinsics param specified in sdf
else {
else
{
// set custom projection matrix based on intrinsics param specified in sdf
double fx = cameraSdf->LensIntrinsicsFx();
double fy = cameraSdf->LensIntrinsicsFy();
double cx = cameraSdf->LensIntrinsicsCx();
Expand All @@ -422,6 +423,48 @@ bool DepthCameraSensor::CreateCamera()
this->dataPtr->depthCamera->SetProjectionMatrix(projectionMatrix);
}

// Update the DOM object intrinsics to have consistent
// projection matrix values between ogre camera and camera_info msg
// If these values are not defined in the SDF then we need to update
// these values to something reasonable. The projection matrix is
// the cumulative effect of intrinsic and extrinsic parameters
if(!cameraSdf->HasLensProjection())
{
// Note that the matrix from Ogre via camera->ProjectionMatrix() has a
// different format than the projection matrix used in SDFormat.
// This is why they are converted using projectionToCameraIntrinsic.
// The resulting matrix is the intrinsic matrix, but since the user has
// not overridden the values, this is also equal to the projection matrix.
auto intrinsicMatrix =
gz::rendering::projectionToCameraIntrinsic(
this->dataPtr->depthCamera->ProjectionMatrix(),
this->dataPtr->depthCamera->ImageWidth(),
this->dataPtr->depthCamera->ImageHeight()
);
cameraSdf->SetLensProjectionFx(intrinsicMatrix(0, 0));
cameraSdf->SetLensProjectionFy(intrinsicMatrix(1, 1));
cameraSdf->SetLensProjectionCx(intrinsicMatrix(0, 2));
cameraSdf->SetLensProjectionCy(intrinsicMatrix(1, 2));
}
else
{
// set custom projection matrix based on projection param specified in sdf
// tx and ty are not used
double fx = cameraSdf->LensProjectionFx();
double fy = cameraSdf->LensProjectionFy();
double cx = cameraSdf->LensProjectionCx();
double cy = cameraSdf->LensProjectionCy();
double s = 0;

auto projectionMatrix = BuildProjectionMatrix(
this->dataPtr->depthCamera->ImageWidth(),
this->dataPtr->depthCamera->ImageHeight(),
fx, fy, cx, cy, s,
this->dataPtr->depthCamera->NearClipPlane(),
this->dataPtr->depthCamera->FarClipPlane());
this->dataPtr->depthCamera->SetProjectionMatrix(projectionMatrix);
}

this->PopulateInfo(cameraSdf);

// Create depth texture when the camera is reconfigured from default values
Expand Down
47 changes: 45 additions & 2 deletions src/RgbdCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,9 @@ bool RgbdCameraSensor::CreateCameras()
cameraSdf->SetLensIntrinsicsCx(intrinsicMatrix(0, 2));
cameraSdf->SetLensIntrinsicsCy(intrinsicMatrix(1, 2));
}
// set custom projection matrix based on intrinsics param specified in sdf
else {
else
{
// set custom projection matrix based on intrinsics param specified in sdf
double fx = cameraSdf->LensIntrinsicsFx();
double fy = cameraSdf->LensIntrinsicsFy();
double cx = cameraSdf->LensIntrinsicsCx();
Expand All @@ -388,6 +389,48 @@ bool RgbdCameraSensor::CreateCameras()
this->dataPtr->depthCamera->SetProjectionMatrix(projectionMatrix);
}

// Update the DOM object intrinsics to have consistent
// projection matrix values between ogre camera and camera_info msg
// If these values are not defined in the SDF then we need to update
// these values to something reasonable. The projection matrix is
// the cumulative effect of intrinsic and extrinsic parameters
if(!cameraSdf->HasLensProjection())
{
// Note that the matrix from Ogre via camera->ProjectionMatrix() has a
// different format than the projection matrix used in SDFormat.
// This is why they are converted using projectionToCameraIntrinsic.
// The resulting matrix is the intrinsic matrix, but since the user has
// not overridden the values, this is also equal to the projection matrix.
auto intrinsicMatrix =
gz::rendering::projectionToCameraIntrinsic(
this->dataPtr->depthCamera->ProjectionMatrix(),
this->dataPtr->depthCamera->ImageWidth(),
this->dataPtr->depthCamera->ImageHeight()
);
cameraSdf->SetLensProjectionFx(intrinsicMatrix(0, 0));
cameraSdf->SetLensProjectionFy(intrinsicMatrix(1, 1));
cameraSdf->SetLensProjectionCx(intrinsicMatrix(0, 2));
cameraSdf->SetLensProjectionCy(intrinsicMatrix(1, 2));
}
else
{
// set custom projection matrix based on projection param specified in sdf
// tx and ty are not used
double fx = cameraSdf->LensProjectionFx();
double fy = cameraSdf->LensProjectionFy();
double cx = cameraSdf->LensProjectionCx();
double cy = cameraSdf->LensProjectionCy();
double s = 0;

auto projectionMatrix = BuildProjectionMatrix(
this->dataPtr->depthCamera->ImageWidth(),
this->dataPtr->depthCamera->ImageHeight(),
fx, fy, cx, cy, s,
this->dataPtr->depthCamera->NearClipPlane(),
this->dataPtr->depthCamera->FarClipPlane());
this->dataPtr->depthCamera->SetProjectionMatrix(projectionMatrix);
}

this->PopulateInfo(cameraSdf);

// Create depth texture when the camera is reconfigured from default values
Expand Down

0 comments on commit 6650772

Please sign in to comment.