I am using libargus for getting image from mipi-csi camera then converting to opencv mat on Tx2 with jetpack 4.4.1 . It is working fine in 1920x1080 , 3840x2160 . But when i tried higher resolution like 5472x3648 converting opencv creates corrupted image . 5472x3648 β this resolution works fine while using nvjpegencoder.
I use this code for converting opencv
IFrame *iFrame = interface_cast<IFrame>(frame);
if (!iFrame)
ORIGINATE_ERROR("Failed to get IFrame interface");
// Get the IImageNativeBuffer extension interface.
NV::IImageNativeBuffer *iNativeBuffer =
interface_cast<NV::IImageNativeBuffer>(iFrame->getImage());
if (!iNativeBuffer)
ORIGINATE_ERROR("IImageNativeBuffer not supported by Image.");
if (m_dmabuf == -1)
{
m_dmabuf = iNativeBuffer->createNvBuffer(m_resolution,
NvBufferColorFormat_ABGR32,
NvBufferLayout_Pitch);
if (m_dmabuf == -1)
ORIGINATE_ERROR("\tFailed to create NvBuffer\n");
}
else if (iNativeBuffer->copyToNvBuffer(m_dmabuf) != STATUS_OK)
{
ORIGINATE_ERROR("Failed to copy frame to NvBuffer.");
}
void *pdata = NULL;
NvBufferMemMap(m_dmabuf, 0, NvBufferMem_Read, &pdata);
NvBufferMemSyncForCpu(m_dmabuf, 0, &pdata);
cv::Mat imgbuf = cv::Mat(m_resolution.height(), m_resolution.width(), CV_8UC4, pdata);
cv::cvtColor(imgbuf, mat, cv::COLOR_RGBA2BGR);
NvBufferMemUnMap(m_dmabuf, 0, &pdata);
I tried CV_8UC4 with COLOR_RGBA2BGR variable, it gave me segmentation fault at cvtColor line.
Then i tried CV_8UC3 with COLOR_YUV2BGR_NV21 and it gave this error
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.1.1) /home/nvidia/host/build_opencv/nv_opencv/modules/imgproc/src/color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<1>; VDcn = cv::impl::{anonymous}::Set<3, 4>; VDepth = cv::impl::{anonymous}::Set<0>; cv::impl::{anonymous}::SizePolicy sizePolicy = (cv::impl::<unnamed>::SizePolicy)1; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Invalid number of channels in input image:
> 'VScn::contains(scn)'
> where
> 'scn' is 3