Skip to content

Commit

Permalink
Add float image support for rectification in CV::Depth
Browse files Browse the repository at this point in the history
Summary: Added support for 1-channel and 3-channel float images.

Differential Revision: D67653914

fbshipit-source-id: d39d453dca9a9f753241780eedcd1fd20df3e2a2
  • Loading branch information
janherling authored and facebook-github-bot committed Dec 27, 2024
1 parent 48a89ec commit 7731f8d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions impl/ocean/cv/depth/Rectifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,29 @@ bool Rectifier::rectify(const AnyCamera& cameraA, const AnyCamera& cameraB, cons
ocean_assert(Numeric::isEqualEps(rectifiedA_T_rectifiedB.translation().y()) && Numeric::isEqualEps(rectifiedA_T_rectifiedB.translation().z()));
#endif

const void* borderColor = nullptr;

std::vector<float> floatBorderColor;

ocean_assert(frameA.pixelFormat() == frameB.pixelFormat());
if (frameA.dataType() == FrameType::DT_SIGNED_FLOAT_32 && frameA.pixelFormat() == frameB.pixelFormat())
{
floatBorderColor.resize(frameA.channels(), NumericF::nan());

borderColor = floatBorderColor.data();
}

constexpr unsigned int binSizeInPixel = 4u;

if (!resampleCameraImageWithOptionalTangentMapping(frameA, cameraA, cameraA_R_rectified, AnyCameraPinhole(pinholeCamera), rectifiedFrameA, nullptr, worker, binSizeInPixel, nullptr, useTangentMapping))
if (!resampleCameraImageWithOptionalTangentMapping(frameA, cameraA, cameraA_R_rectified, AnyCameraPinhole(pinholeCamera), rectifiedFrameA, nullptr, worker, binSizeInPixel, borderColor, useTangentMapping))
{
ocean_assert(false && "This should never happen!");

Log::error() << "Failed to rectify first image";
return false;
}

if (!resampleCameraImageWithOptionalTangentMapping(frameB, cameraB, cameraB_R_rectified, AnyCameraPinhole(pinholeCamera), rectifiedFrameB, nullptr, worker, binSizeInPixel, nullptr, useTangentMapping))
if (!resampleCameraImageWithOptionalTangentMapping(frameB, cameraB, cameraB_R_rectified, AnyCameraPinhole(pinholeCamera), rectifiedFrameB, nullptr, worker, binSizeInPixel, borderColor, useTangentMapping))
{
ocean_assert(false && "This should never happen!");

Expand Down Expand Up @@ -145,7 +157,7 @@ bool Rectifier::resampleCameraImageWithOptionalTangentMapping(const Frame& sourc

const Scalar width = Scalar(targetCamera.width());
const Scalar height = Scalar(targetCamera.height());
const Scalar width_2 = width / Scalar(2);
const Scalar width_2 = width / Scalar(2);
const Scalar height_2 = height / Scalar(2);
const Scalar fovx = 2 * Numeric::atan(width_2 / f);
const Scalar fovy = 2 * Numeric::atan(height_2 / f);
Expand All @@ -172,7 +184,7 @@ bool Rectifier::resampleCameraImageWithOptionalTangentMapping(const Frame& sourc
const Scalar newy = Numeric::tan(y * fovy / height) * f;
newCornerPosition = Vector2(newx + width_2, newy + height_2);
}

constexpr bool makeUnitVector = false; // we don't need a unit/normalized vector as we project the vector into the camera again

const Vector3 rayI = source_R_target * targetCamera.vector(newCornerPosition, makeUnitVector);
Expand Down Expand Up @@ -201,7 +213,7 @@ bool Rectifier::resampleCameraImageWithOptionalTangentMapping(const Frame& sourc
{
*source_OLT_target = std::move(lookupTable);
}

return true;
}

Expand Down

0 comments on commit 7731f8d

Please sign in to comment.