50 #ifndef NV_VPI_DETAIL_OPENCV_UTILS_HPP
51 #define NV_VPI_DETAIL_OPENCV_UTILS_HPP
54 #include "../ImageFormat.h"
55 #include "../Status.h"
57 #include <opencv2/core/core.hpp>
65 namespace nv {
namespace vpi {
namespace detail {
71 switch (CV_MAT_DEPTH(cvType))
74 switch (CV_MAT_CN(cvType))
95 switch (CV_MAT_CN(cvType))
116 switch (CV_MAT_CN(cvType))
139 switch (CV_MAT_CN(cvType))
160 switch (CV_MAT_CN(cvType))
181 switch (CV_MAT_CN(cvType))
202 switch (CV_MAT_CN(cvType))
326 assert(elemSize != 0);
335 if (ToOpenCVType(pixType) != mat.type())
340 assert(imgData !=
nullptr);
344 imgPlane.
width = mat.cols;
345 imgPlane.
height = mat.rows;
362 if (mat.type() == CV_8UC1)
370 else if (mat.type() == CV_16UC1)
383 assert(imgData !=
nullptr);
390 imgPlanes[0].
width = mat.cols;
391 imgPlanes[1].
width = mat.cols / 2;
396 imgPlanes[0].
height = mat.rows / 2;
400 imgPlanes[0].
height = mat.rows * 2 / 3;
404 imgPlanes[0].
height = mat.rows * 4 / 5;
444 if (mat.step[0] != (
size_t)mat.cols)
449 for (
int p = 0; p < 3; ++p)
460 if (mat.step[0] != (
size_t)mat.cols * 2)
465 for (
int p = 0; p < 3; ++p)
478 assert(imgData !=
nullptr);
486 imgPlanes[0].
width = mat.cols;
487 imgPlanes[1].
width = mat.cols / 2;
488 imgPlanes[2].
width = mat.cols / 2;
493 imgPlanes[0].
height = mat.rows / 2;
496 imgPlanes[0].
height = mat.rows * 2 / 3;
499 imgPlanes[0].
height = mat.rows * 4 / 5;
523 assert(imgData != NULL);
525 if (mat.data == NULL)
542 memset(imgData, 0,
sizeof(*imgData));
552 status = FillImageDataOnePlaneImpl(mat, fmt, &imgData->
buffer.
pitch);
556 status = FillImageDataTwoPlanesImpl(mat, fmt, &imgData->
buffer.
pitch);
560 status = FillImageDataThreePlanesImpl(mat, fmt, &imgData->
buffer.
pitch);
573 assert(imgData != NULL);
575 if (matPlanes.empty())
585 memset(imgData, 0,
sizeof(*imgData));
591 for (
size_t p = 0; p < matPlanes.size(); ++p)
593 const cv::Mat &mat = matPlanes[p];
595 if (mat.data == NULL)
607 if (ToOpenCVType(pixType) != mat.type())
614 plane.
width = mat.cols;
627 assert(imgData != NULL);
629 if (mat.data == NULL)
645 assert(imgData !=
nullptr);
714 for (
int i = 0; i < 3; ++i)
741 for (
int i = 0; i < 2; ++i)
780 status = CalcHeightOpenCVMatOnePlane(imgPitch, height);
784 status = CalcHeightOpenCVMatTwoPlanes(imgPitch, height);
788 status = CalcHeightOpenCVMatThreePlanes(imgPitch, height);
808 int cvType = ToOpenCVType(pixType);
814 mat = cv::Mat(height, imgPitch.
planes[0].
width, cvType,
836 for (
int i = 0; i < imgPitch.
numPlanes; ++i)
849 cvTypes[i] = ToOpenCVType(pixType);
851 if (cvTypes[i] == -1)
859 for (
int i = 0; i < imgPitch.
numPlanes; ++i)
VPIMemLayout vpiPixelTypeGetMemLayout(VPIPixelType type)
Get the memory layout of a pixel type.
#define VPI_PIXEL_TYPE_INVALID
Signal format conversion errors.
VPIPacking vpiPixelTypeGetPacking(VPIPixelType type)
Get the packing of a pixel type.
VPIDataType vpiPixelTypeGetDataType(VPIPixelType type)
Get the data type of a pixel type.
int vpiPixelTypeGetBitsPerPixel(VPIPixelType type)
Get the number of bits per pixel of a pixel type.
#define VPI_PIXEL_TYPE_DEFAULT
Used to signal that the pixel type must be inferred from image format.
unsigned char VPIByte
Definition of a byte type.
VPIChromaSubsampling
Defines how chroma-subsampling is done.
int vpiChromaSubsamplingGetSamplesVert(VPIChromaSubsampling css)
Get the number of chroma samples for each group of 4 vertical luma samples.
int vpiChromaSubsamplingGetSamplesHoriz(VPIChromaSubsampling css)
Get the number of chroma samples for each group of 4 horizontal luma samples.
VPIDataType
Defines the channel data type.
@ VPI_PACKING_X64
One 64-bit channel.
@ VPI_PACKING_X8_Y8_Z8_W8
Four 8-bit channels in one 32-bit word.
@ VPI_PACKING_X8_Y8_Z8
Three 8-bit channels in three 8-bit words.
@ VPI_PACKING_X64_Y64
Two 64-bit channels in two 64-bit words.
@ VPI_PACKING_X32_Y32_Z32_W32
Four 32-bit channels in three 32-bit words.
@ VPI_PACKING_X8
One 8-bit channel.
@ VPI_PACKING_X32_Y32_Z32
Three 32-bit channels in three 32-bit words.
@ VPI_PACKING_X32
One 32-bit channel.
@ VPI_PACKING_X8_Y8
Two 8-bit channels in two 8-bit words.
@ VPI_PACKING_X64_Y64_Z64
Three 64-bit channels in three 64-bit words.
@ VPI_PACKING_X64_Y64_Z64_W64
Four 64-bit channels in four 64-bit words.
@ VPI_PACKING_X16_Y16_Z16
Three 16-bit channels in three 16-bit words.
@ VPI_PACKING_X16
One 16-bit channel.
@ VPI_PACKING_X16_Y16
Two 16-bit channels in two 16-bit words.
@ VPI_PACKING_X16_Y16_Z16_W16
Four 16-bit channels in one 64-bit word.
@ VPI_PACKING_X8_Y8__X8_Z8
2 pixels of 2 8-bit channels each, totalling 4 8-bit words.
@ VPI_PACKING_X32_Y32
Two 32-bit channels in two 32-bit words.
@ VPI_PACKING_Y8_X8__Z8_X8
2 pixels of 2 swapped 8-bit channels each, totalling 4 8-bit words.
@ VPI_MEM_LAYOUT_PITCH_LINEAR
Pixels are laid out in row-major order.
@ VPI_DATA_TYPE_FLOAT
Channel are floating point values.
@ VPI_DATA_TYPE_UNSIGNED
Channels are unsigned integer values.
@ VPI_DATA_TYPE_SIGNED
Channels are signed integer values.
VPIImageBuffer buffer
Stores the image contents.
VPIImagePlanePitchLinear planes[VPI_MAX_PLANE_COUNT]
Data of all image planes in pitch-linear layout.
VPIImageBufferPitchLinear pitch
Image stored in pitch-linear layout.
int32_t numPlanes
Number of planes.
VPIImageFormat format
Image format.
VPIPixelType pixelType
Type of each pixel within this plane.
VPIImageBufferType bufferType
Type of image buffer.
int64_t offsetBytes
Offset in bytes from pBase to the first column of the first plane row.
int32_t height
Height of this plane in pixels.
VPIByte * pBase
Pointer to the memory buffer which contains the plane data.
int32_t width
Width of this plane in pixels.
int32_t pitchBytes
Difference in bytes of beginning of one row and the beginning of the previous.
#define VPI_MAX_PLANE_COUNT
Maximum number of data planes an image can have.
@ VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR
Host-accessible with planes in pitch-linear memory layout.
Stores the image plane contents.
Stores information about image characteristics and content.
Represents one image plane in pitch-linear layout.
@ VPI_SUCCESS
Operation completed successfully.
@ VPI_ERROR_INTERNAL
Internal, non specific error.
@ VPI_ERROR_INVALID_ARGUMENT
Invalid argument, either wrong range or value not accepted.
@ VPI_ERROR_INVALID_IMAGE_FORMAT
Image type not accepted.