Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions retinify/include/retinify/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ struct Intrinsics
/// @brief
/// Skew coefficient
double skew{0};

[[nodiscard]] auto operator==(const Intrinsics &other) const noexcept -> bool
{
return fx == other.fx && //
fy == other.fy && //
cx == other.cx && //
cy == other.cy && //
skew == other.skew;
}
};

/// @brief
Expand All @@ -218,6 +227,18 @@ struct Distortion
double k4{0};
double k5{0};
double k6{0};

[[nodiscard]] auto operator==(const Distortion &other) const noexcept -> bool
{
return k1 == other.k1 && //
k2 == other.k2 && //
p1 == other.p1 && //
p2 == other.p2 && //
k3 == other.k3 && //
k4 == other.k4 && //
k5 == other.k5 && //
k6 == other.k6;
}
};

/// @brief
Expand Down Expand Up @@ -270,6 +291,22 @@ struct CalibrationParameters
/// @brief
/// Right camera hardware serial
std::array<char, 128> rightCameraSerial{};

[[nodiscard]] auto operator==(const CalibrationParameters &other) const noexcept -> bool
{
return leftIntrinsics == other.leftIntrinsics && //
leftDistortion == other.leftDistortion && //
rightIntrinsics == other.rightIntrinsics && //
rightDistortion == other.rightDistortion && //
rotation == other.rotation && //
translation == other.translation && //
imageWidth == other.imageWidth && //
imageHeight == other.imageHeight && //
reprojectionError == other.reprojectionError && //
calibrationTime == other.calibrationTime && //
leftCameraSerial == other.leftCameraSerial && //
rightCameraSerial == other.rightCameraSerial; //
}
};

/// @brief
Expand Down Expand Up @@ -354,4 +391,22 @@ RETINIFY_API auto InitUndistortRectifyMap(const Intrinsics &intrinsics, const Di
std::uint32_t imageWidth, std::uint32_t imageHeight, //
float *mapx, std::size_t mapxStride, //
float *mapy, std::size_t mapyStride) noexcept -> void;

/// @brief
/// Initialize identity maps for undistortion/rectification.
/// @param mapx
/// Output map for x-coordinates
/// @param mapxStride
/// Stride (in bytes) of a row in mapx
/// @param mapy
/// Output map for y-coordinates
/// @param mapyStride
/// Stride (in bytes) of a row in mapy
/// @param imageWidth
/// Image width in pixels
/// @param imageHeight
/// Image height in pixels
RETINIFY_API auto InitIdentityMap(float *mapx, std::size_t mapxStride, //
float *mapy, std::size_t mapyStride, //
std::size_t imageWidth, std::size_t imageHeight) noexcept -> void;
} // namespace retinify
11 changes: 7 additions & 4 deletions retinify/include/retinify/pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include "retinify/geometry.hpp"
#include "retinify/status.hpp"

#include <array>
Expand Down Expand Up @@ -60,11 +61,13 @@ class RETINIFY_API Pipeline
/// The pixel format of the input images.
/// @param depthMode
/// The depth mode option for the stereo matching.
/// @param calibrationParameters
/// The stereo camera calibration parameters.
/// @return
/// A Status object indicating whether the initialization was successful.
[[nodiscard]] auto Initialize(std::uint32_t imageWidth, std::uint32_t imageHeight, //
PixelFormat pixelFormat = PixelFormat::RGB8, //
DepthMode depthMode = DepthMode::ACCURATE) noexcept -> Status;
[[nodiscard]] auto Initialize(std::uint32_t imageWidth, std::uint32_t imageHeight, //
PixelFormat pixelFormat = PixelFormat::RGB8, DepthMode depthMode = DepthMode::ACCURATE, //
const CalibrationParameters &calibrationParameters = CalibrationParameters{}) noexcept -> Status;

/// @brief
/// Executes the stereo matching pipeline using the given left and right image data.
Expand All @@ -90,7 +93,7 @@ class RETINIFY_API Pipeline
class Impl;
auto impl() noexcept -> Impl *;
[[nodiscard]] auto impl() const noexcept -> const Impl *;
static constexpr std::size_t BufferSize = 2048;
static constexpr std::size_t BufferSize{2048};
alignas(alignof(std::max_align_t)) std::array<unsigned char, BufferSize> buffer_{};
};
} // namespace retinify
27 changes: 27 additions & 0 deletions retinify/src/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,31 @@ auto InitUndistortRectifyMap(const Intrinsics &intrinsics, const Distortion &dis
}
}
}

auto InitIdentityMap(float *mapX, std::size_t mapXStride, //
float *mapY, std::size_t mapYStride, //
std::size_t imageWidth, std::size_t imageHeight) noexcept -> void
{
if (mapX == nullptr || mapY == nullptr)
{
return;
}

auto *mapXBytes = reinterpret_cast<unsigned char *>(mapX);
auto *mapYBytes = reinterpret_cast<unsigned char *>(mapY);

for (std::size_t row = 0; row < imageHeight; ++row)
{
const std::size_t offsetX = row * mapXStride;
const std::size_t offsetY = row * mapYStride;
auto *mapXRow = reinterpret_cast<float *>(mapXBytes + offsetX);
auto *mapYRow = reinterpret_cast<float *>(mapYBytes + offsetY);
const float y = static_cast<float>(row);
for (std::size_t col = 0; col < imageWidth; ++col)
{
mapXRow[col] = static_cast<float>(col);
mapYRow[col] = y;
}
}
}
} // namespace retinify
103 changes: 103 additions & 0 deletions retinify/src/imgproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,109 @@ auto DisparityOcclusionFilter32FC1(const Mat &src, Mat &dst, Stream &stream) noe
#endif
}

auto RemapImage8U(const Mat &src, const Mat &mapX, const Mat &mapY, Mat &dst, Stream &stream) noexcept -> Status
{
if (src.Empty() || mapX.Empty() || mapY.Empty() || dst.Empty())
{
LogError("Source, maps, or destination is empty.");
return Status{StatusCategory::RETINIFY, StatusCode::INVALID_ARGUMENT};
}

if (src.BytesPerElement() != sizeof(std::uint8_t) || dst.BytesPerElement() != sizeof(std::uint8_t))
{
LogError("Source and destination must be 8-bit unsigned.");
return Status{StatusCategory::RETINIFY, StatusCode::INVALID_ARGUMENT};
}

if (mapX.BytesPerElement() != sizeof(float) || mapY.BytesPerElement() != sizeof(float))
{
LogError("Maps must be 32-bit floating-point.");
return Status{StatusCategory::RETINIFY, StatusCode::INVALID_ARGUMENT};
}

if (src.Channels() != dst.Channels())
{
LogError("Source and destination must have the same number of channels.");
return Status{StatusCategory::RETINIFY, StatusCode::INVALID_ARGUMENT};
}

if (mapX.Channels() != 1 || mapY.Channels() != 1)
{
LogError("Maps must have 1 channel.");
return Status{StatusCategory::RETINIFY, StatusCode::INVALID_ARGUMENT};
}

if ((dst.Cols() != mapX.Cols()) || (dst.Rows() != mapX.Rows()) || (dst.Cols() != mapY.Cols()) || (dst.Rows() != mapY.Rows()))
{
LogError("Destination and maps must have the same size.");
return Status{StatusCategory::RETINIFY, StatusCode::INVALID_ARGUMENT};
}

if ((src.Cols() == 0) || (src.Rows() == 0))
{
LogError("Source size must be non-zero.");
return Status{StatusCategory::RETINIFY, StatusCode::INVALID_ARGUMENT};
}

if (src.Channels() != 1 && src.Channels() != 3)
{
LogError("Source and destination must have 1 or 3 channels.");
return Status{StatusCategory::RETINIFY, StatusCode::INVALID_ARGUMENT};
}

#ifdef BUILD_WITH_TENSORRT
const auto *srcData = static_cast<const Npp8u *>(src.Data());
auto *dstData = static_cast<Npp8u *>(dst.Data());
const auto *mapXData = static_cast<const Npp32f *>(mapX.Data());
const auto *mapYData = static_cast<const Npp32f *>(mapY.Data());
const auto srcSize = NppiSize{static_cast<int>(src.Cols()), static_cast<int>(src.Rows())};
const auto dstSize = NppiSize{static_cast<int>(dst.Cols()), static_cast<int>(dst.Rows())};
const auto srcRoi = NppiRect{0, 0, srcSize.width, srcSize.height};
const auto srcStride = static_cast<int>(src.Stride());
const auto dstStride = static_cast<int>(dst.Stride());
const auto mapXStep = static_cast<int>(mapX.Stride());
const auto mapYStep = static_cast<int>(mapY.Stride());

NppStatus status{};

if (src.Channels() == 1)
{
status = nppiRemap_8u_C1R_Ctx(srcData, srcSize, srcStride, srcRoi, //
mapXData, mapXStep, mapYData, mapYStep, //
dstData, dstStride, dstSize, //
NPPI_INTER_LINEAR, stream.GetNppStreamContext());

if (status != NPP_SUCCESS)
{
LogError("nppiRemap_8u_C1R failed");
return Status{StatusCategory::CUDA, StatusCode::FAIL};
}

return Status{};
}

status = nppiRemap_8u_C3R_Ctx(srcData, srcSize, srcStride, srcRoi, //
mapXData, mapXStep, mapYData, mapYStep, dstData, dstStride, dstSize, //
NPPI_INTER_LINEAR, stream.GetNppStreamContext());

if (status != NPP_SUCCESS)
{
LogError("nppiRemap_8u_C3R failed");
return Status{StatusCategory::CUDA, StatusCode::FAIL};
}

return Status{};
#else
(void)src;
(void)mapX;
(void)mapY;
(void)dst;
(void)stream;
LogError("This function is not available");
return Status{StatusCategory::RETINIFY, StatusCode::FAIL};
#endif
}

auto HorizontalFlip8UC3(const Mat &src, Mat &dst, Stream &stream) noexcept -> Status
{
if (src.Empty() || dst.Empty())
Expand Down
16 changes: 16 additions & 0 deletions retinify/src/imgproc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ namespace retinify
/// Status code.
[[nodiscard]] auto DisparityOcclusionFilter32FC1(const Mat &src, Mat &dst, Stream &stream) noexcept -> Status;

/// @brief
/// Remap an 8-bit, 1-channel image using the provided x and y maps.
/// @param src
/// Input image (8-bit, 1- or 3-channel).
/// @param mapX
/// X map (32-bit floating-point, 1-channel).
/// @param mapY
/// Y map (32-bit floating-point, 1-channel).
/// @param dst
/// Output image (8-bit, 1- or 3-channel).
/// @param stream
/// Execution stream.
/// @return
/// Status code.
[[nodiscard]] auto RemapImage8U(const Mat &src, const Mat &mapX, const Mat &mapY, Mat &dst, Stream &stream) noexcept -> Status;

/// @brief
/// Horizontally flip an 8-bit, 1-channel image.
/// @param src
Expand Down
Loading