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;
347 imgPlane.
data = mat.data;
361 if (mat.type() == CV_8UC1)
369 else if (mat.type() == CV_16UC1)
382 assert(imgData !=
nullptr);
389 imgPlanes[0].
width = mat.cols;
390 imgPlanes[1].
width = mat.cols / 2;
395 imgPlanes[0].
height = mat.rows / 2;
399 imgPlanes[0].
height = mat.rows * 2 / 3;
403 imgPlanes[0].
height = mat.rows * 4 / 5;
415 imgPlanes[0].
data = mat.data;
416 imgPlanes[1].
data =
const_cast<uint8_t *
>(mat.ptr(imgPlanes[0].height, 0));
441 if (mat.step[0] != (
size_t)mat.cols)
446 for (
int p = 0; p < 3; ++p)
457 if (mat.step[0] != (
size_t)mat.cols * 2)
462 for (
int p = 0; p < 3; ++p)
475 assert(imgData !=
nullptr);
483 imgPlanes[0].
width = mat.cols;
484 imgPlanes[1].
width = mat.cols / 2;
485 imgPlanes[2].
width = mat.cols / 2;
490 imgPlanes[0].
height = mat.rows / 2;
493 imgPlanes[0].
height = mat.rows * 2 / 3;
496 imgPlanes[0].
height = mat.rows * 4 / 5;
509 imgPlanes[0].
data = mat.data;
510 imgPlanes[1].
data = mat.data + mat.step[0] * imgPlanes[0].
height;
511 imgPlanes[2].
data =
reinterpret_cast<uint8_t *
>(imgPlanes[1].
data) + imgPlanes[1].height * imgPlanes[1].pitchBytes;
518 assert(imgData != NULL);
520 if (mat.data == NULL)
537 memset(imgData, 0,
sizeof(*imgData));
547 status = FillImageDataOnePlaneImpl(mat, fmt, &imgData->
buffer.
pitch);
551 status = FillImageDataTwoPlanesImpl(mat, fmt, &imgData->
buffer.
pitch);
555 status = FillImageDataThreePlanesImpl(mat, fmt, &imgData->
buffer.
pitch);
568 assert(imgData != NULL);
570 if (matPlanes.empty())
580 memset(imgData, 0,
sizeof(*imgData));
586 for (
size_t p = 0; p < matPlanes.size(); ++p)
588 const cv::Mat &mat = matPlanes[p];
590 if (mat.data == NULL)
602 if (ToOpenCVType(pixType) != mat.type())
609 plane.
width = mat.cols;
612 plane.
data = mat.data;
621 assert(imgData != NULL);
623 if (mat.data == NULL)
639 assert(imgData !=
nullptr);
706 for (
int i = 0; i < 3; ++i)
733 for (
int i = 0; i < 2; ++i)
771 status = CalcHeightOpenCVMatOnePlane(imgPitch, height);
775 status = CalcHeightOpenCVMatTwoPlanes(imgPitch, height);
779 status = CalcHeightOpenCVMatThreePlanes(imgPitch, height);
799 int cvType = ToOpenCVType(pixType);
826 for (
int i = 0; i < imgPitch.
numPlanes; ++i)
839 cvTypes[i] = ToOpenCVType(pixType);
841 if (cvTypes[i] == -1)
849 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.
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.
void * data
Pointer to the first row of this plane.
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.
int32_t height
Height of this plane in pixels.
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.