Hi,
How to extract image frames from NvMOTFrame->NvBufSurfaceParams->NvBufSurfacePlaneParams->?
Can you give me reference code?
Hi,
How to extract image frames from NvMOTFrame->NvBufSurfaceParams->NvBufSurfacePlaneParams->?
Can you give me reference code?
For accessing frame buffer, you can refer to this, https://devtalk.nvidia.com/default/topic/1061205/deepstream-sdk/rtsp-camera-access-frame-issue/post/5377678/#5377678, it’s similar.
I get the following error while using that code mentioned in your link
NvMOTStatus NvMOT_Process(NvMOTContextHandle contextHandle,NvMOTProcessParams *pParams,NvMOTTrackedObjBatch *pTrackedObjectsBatch)
{
NvBufSurfaceParams* buf_list = fr->bufferList[0];
NvBufSurfaceMappedAddr mapd_addr = buf_list->mappedAddr;
cv::Mat bgr_frame = cv::Mat (cv::Size( 640, 368), CV_8UC3);
cv::Mat in_mat =cv::Mat (368, 640,CV_8UC4, mapd_addr.addr[0],1920);
cv::cvtColor (in_mat, bgr_frame, cv::COLOR_RGB2BGR);
cv::imwrite("./img1.png",in_mat);
return NvMOTStatus_OK;
}
error:
what(): OpenCV(4.2.0-dev) opencv/opencv/modules/core/include/opencv2/core/mat.inl.hpp:548: error: (-215:Assertion failed) total() == 0 || data != NULL in function 'Mat'
Did you sync GPU buffer hereby buf_list for CPU access before creating cv Mat buffer?
NvBufSurfaceSyncForCpu(NvBufSurface *surf, int index, int plane)
Previous err was due to
pQuery->colorFormats[0] = NVBUF_COLOR_FORMAT_RGBA;
in NvMOT_Query,
Now I get frames but it is full of stripes I have attached actual and result frame.
My code is
NvMOTStatus NvMOT_Process(NvMOTContextHandle contextHandle,NvMOTProcessParams *pParams,NvMOTTrackedObjBatch *pTrackedObjectsBatch)
{
NvBufSurfaceParams* buf_list = fr->bufferList[0];
NvBufSurfaceMappedAddr mapd_addr = buf_list->mappedAddr;
cv::Mat bgr_frame = cv::Mat (cv::Size( 640, 368), CV_8UC4);
cv::Mat in_mat =cv::Mat (368, 640,CV_8UC4, mapd_addr.addr[0],1920);
cv::cvtColor (in_mat, bgr_frame, cv::COLOR_RGBA2BGR);
cv::imwrite("./result.png",in_mat);
return NvMOTStatus_OK;
}
help me to convert image
Can you extract your source which can compile and run in our environments for a further check?
or if not possible please check below 2 points:
1 as before mentioned, Did you sync GPU buffer hereby buf_list for CPU access before creating cv Mat buffer?
NvBufSurfaceSyncForCpu(NvBufSurface surf, int index, int plane)
2 cv::Mat in_mat =cv::Mat (368, 640,CV_8UC4, mapd_addr.addr[0],1920);
are you sure your buffer color format is RGBA? if yes, the pitch should be width pixels bytes per pixel (640*4)
yes, my width is 1280 and pitch is 5120, finally I got the frame :) Thank you.
I am facing the same issue and I am a little puzzled on how to read frame data off of NvBufSurfaceParams**, and how you I can call NvBufSurfaceSyncForCpu with an NvBufSurfaceParams** rather than an NvBufSurface.