8#ifndef META_OCEAN_CV_OPENCV_UTILITIES_H 
    9#define META_OCEAN_CV_OPENCV_UTILITIES_H 
   19#include <opencv2/core.hpp> 
   41        static inline cv::Mat toCvMat(
const Frame& frame, 
const bool copy = 
false);
 
   50        static inline Frame toOceanFrame(
const cv::Mat& frame, 
const bool copy = 
false, 
const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED);
 
   59        static inline SquareMatrixT3<T> toOceanSquareMatrix3(
const cv::Matx<T, 3, 3>& matrix);
 
   68        static inline SquareMatrixT3<T> toOceanSquareMatrix3Affine(
const cv::Matx<T, 2, 3>& affineTransformation);
 
   86        static inline cv::Matx<T, 2, 3> toCvMatx23Affine(
const SquareMatrixT3<T>& affineTransformation);
 
  102        static inline bool toOceanFrameTypeDataType(
const int cvDepth, 
FrameType::DataType& dataType);
 
 
  109    const unsigned int channels = frame.
channels();
 
  113    if (
toCvDepth(dataType, cvDepth) == 
false)
 
  115        ocean_assert(
false && 
"Ocean data type not supported by OpenCV");
 
  123        cvMat = cvMat.clone();
 
 
  131    const unsigned int width = (
unsigned int)(mat.size().width);
 
  132    const unsigned int height = (
unsigned int)(mat.size().height);
 
  134    const unsigned int channels = (
unsigned int)(mat.channels());
 
  135    ocean_assert(channels > 0u);
 
  137    const int cvDepth = mat.depth();
 
  147            ocean_assert(
false && 
"OpenCV depth type not supported by Ocean");
 
  154        switch ((std::underlying_type<FrameType::PixelFormat>::type)(pixelFormat))
 
  156            case FrameType::genericPixelFormat<FrameType::DT_UNSIGNED_INTEGER_8, 1u>():
 
  160            case FrameType::genericPixelFormat<FrameType::DT_UNSIGNED_INTEGER_8, 3u>():
 
  164            case FrameType::genericPixelFormat<FrameType::DT_UNSIGNED_INTEGER_8, 4u>():
 
  168            case FrameType::genericPixelFormat<FrameType::DT_SIGNED_FLOAT_32, 1u>():
 
  172            case FrameType::genericPixelFormat<FrameType::DT_SIGNED_FLOAT_64, 1u>():
 
  182    const unsigned int matStrideBytes = (
unsigned int)(mat.step);
 
  184    unsigned int paddingElements = 0u;
 
  187        ocean_assert(
false && 
"Invalid pixel format!");
 
 
  205    const T* v = transformation.val;
 
 
  212    return cv::Matx<T, 3, 3>(matrix[0], matrix[3], matrix[6], matrix[1], matrix[4], matrix[7], matrix[2], matrix[5], matrix[8]);
 
 
  218    ocean_assert(transformation.
isAffine());
 
  219    return cv::Matx<T, 2, 3>(transformation[0], transformation[3], transformation[6], transformation[1], transformation[4], transformation[7]);
 
 
  224#if defined(CV_VERSION_MAJOR) && CV_VERSION_MAJOR >= 4 
  285            cvDepth = CV_USRTYPE1;
 
  293            cvDepth = CV_USRTYPE1;
 
  297            cvDepth = CV_USRTYPE1;
 
  301            cvDepth = CV_USRTYPE1;
 
  313            cvDepth = CV_USRTYPE1;
 
 
  346#if defined(CV_VERSION_MAJOR) && CV_VERSION_MAJOR >= 4 
 
This class implements utility functions for the migration from OpenCV to Ocean.
Definition OpenCVUtilities.h:32
static cv::Matx< T, 2, 3 > toCvMatx23Affine(const SquareMatrixT3< T > &affineTransformation)
Convert an Ocean SquareMatrix3 (column-major) to an OpenCV 2-by-3 matrix (row-major)
Definition OpenCVUtilities.h:216
static cv::Matx< T, 3, 3 > toCvMatx33(const SquareMatrixT3< T > &matrix)
Convert an Ocean SquareMatrix3 (column-major) to an OpenCV 3-by-3 matrix (row-major)
Definition OpenCVUtilities.h:210
static SquareMatrixT3< T > toOceanSquareMatrix3Affine(const cv::Matx< T, 2, 3 > &affineTransformation)
Convert an OpenCV 2-by-3 matrix (row-major) to an Ocean SquareMatrix3 (column-major)
Definition OpenCVUtilities.h:203
static SquareMatrixT3< T > toOceanSquareMatrix3(const cv::Matx< T, 3, 3 > &matrix)
Convert an OpenCV 3-by-3 matrix (row-major) to an Ocean SquareMatrix3 (column-wise order)
Definition OpenCVUtilities.h:197
static bool toCvDepth(const FrameType::DataType dataType, int &cvDepth)
Converts an Ocean frame data type to a corresponding depth type in OpenCV.
Definition OpenCVUtilities.h:222
static cv::Mat toCvMat(const Frame &frame, const bool copy=false)
Convert an Ocean Frame image to an OpenCV image.
Definition OpenCVUtilities.h:105
static bool toOceanFrameTypeDataType(const int cvDepth, FrameType::DataType &dataType)
Converts an OpenCV depth type to a corresponding Ocean frame data type.
Definition OpenCVUtilities.h:322
static Frame toOceanFrame(const cv::Mat &frame, const bool copy=false, const FrameType::PixelFormat pixelFormat=FrameType::FORMAT_UNDEFINED)
Convert an OpenCV image to an Ocean Frame image object.
Definition OpenCVUtilities.h:129
This class implements Ocean's image class.
Definition Frame.h:1808
static bool strideBytes2paddingElements(const PixelFormat &pixelFormat, const unsigned int imageWidth, const unsigned int planeStrideBytes, unsigned int &planePaddingElements, const unsigned int planeIndex=0u)
Determines the number of padding elements at the end of a row of a plane for which the pixel format,...
unsigned int strideBytes(const unsigned int planeIndex=0u) const
Returns the number of bytes within one row, including optional padding at the end of a row for a spec...
Definition Frame.h:4149
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition Frame.h:4251
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4531
CopyMode
Definition of individual copy modes.
Definition Frame.h:1815
@ CM_USE_KEEP_LAYOUT
The source memory is used only, no copy is created, the padding layout is preserved.
Definition Frame.h:1817
@ CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA
Makes a copy of the source memory, the padding layout is preserved, but the padding data is not copie...
Definition Frame.h:1821
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
@ FORMAT_BGR24
Pixel format with byte order BGR and 24 bits per pixel.
Definition Frame.h:226
@ FORMAT_UNDEFINED
Undefined pixel format.
Definition Frame.h:187
@ FORMAT_F32
Pixel format for a frame with one channel and 32 bit floating point precision per element.
Definition Frame.h:992
@ FORMAT_F64
Pixel format for a frame with one channel and 64 bit floating point precision per element.
Definition Frame.h:997
@ FORMAT_BGRA32
Pixel format with byte order BGRA and 32 bits per pixel.
Definition Frame.h:277
@ FORMAT_Y8
Pixel format for grayscale images with byte order Y and 8 bits per pixel.
Definition Frame.h:594
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3170
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition Frame.h:1050
DataType
Definition of individual channel data type.
Definition Frame.h:37
@ DT_UNSIGNED_INTEGER_64
Unsigned 64 bit integer data type (uint64_t).
Definition Frame.h:53
@ DT_UNSIGNED_INTEGER_16
Unsigned 16 bit integer data type (uint16_t).
Definition Frame.h:45
@ DT_SIGNED_INTEGER_16
Signed 16 bit integer data type (int16_t).
Definition Frame.h:47
@ DT_SIGNED_INTEGER_32
Signed 232 bit integer data type (int32_t).
Definition Frame.h:51
@ DT_SIGNED_INTEGER_64
Signed 64 bit integer data type (int64_t).
Definition Frame.h:55
@ DT_UNDEFINED
Undefined data type.
Definition Frame.h:39
@ DT_SIGNED_FLOAT_64
Signed 64 bit float data type (double).
Definition Frame.h:61
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition Frame.h:41
@ DT_UNSIGNED_INTEGER_32
Unsigned 32 bit integer data type (uint32_t).
Definition Frame.h:49
@ DT_SIGNED_FLOAT_16
Signed 16 bit float data type.
Definition Frame.h:57
@ DT_SIGNED_FLOAT_32
Signed 32 bit float data type (float).
Definition Frame.h:59
@ DT_SIGNED_INTEGER_8
Signed 8 bit integer data type (int8_t).
Definition Frame.h:43
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3175
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition Frame.h:3200
DataType dataType() const
Returns the data type of the pixel format of this frame.
Definition Frame.h:3190
static constexpr PixelFormat genericPixelFormat()
Returns a specific generic pixel format with a specified data type and channel number.
Definition Frame.h:3381
This class implements a 3x3 square matrix.
Definition SquareMatrix3.h:89
bool isAffine() const
Returns true if this matrix is a affine transformation.
Definition SquareMatrix3.h:1354
The namespace covering the entire Ocean framework.
Definition Accessor.h:15