Hi Folks,
I am trying to apply some basic operations on frames captured by camera. When I try to do so using OpenCV functions ( for eg, absdiff ) it appears pretty slow. To make the code more optimized w.r.t runtime, I am trying to use cuda based calls ( for eg, cv::cuda::absdiff ) instead. I am trying to read frames from camera as cv::Mat using the following code snippet:
int fd = iImageNativeBuffer->createNvBuffer(Argus::Size {m_framesize.width, m_framesize.height},
NvBufferColorFormat_YUV420, NvBufferLayout_Pitch, &status);
if (status != STATUS_OK)
TEST_ERROR_RETURN(status != STATUS_OK, "Failed to create a native buffer");
NvBufferParams params;
NvBufferGetParams(fd, ¶ms);
int fsize = params.pitch[0] * m_framesize.height ;
char *data_mem = (char*)mmap(NULL, fsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, params.offset[0]);
if (data_mem == MAP_FAILED)
printf("mmap failed : %s\n", strerror(errno));
struct timeval tp;
gettimeofday(&tp, NULL);
long start = tp.tv_sec * 1000 + tp.tv_usec / 1000;
cout<<"Time at frame capture : "<< start - prevTime <<" ms "<<endl;
prevTime = start;
cv::Mat imgbuf = cv::Mat(m_framesize.height, m_framesize.width, CV_8UC1, data_mem,params.pitch[0]);
cv::cuda::absdiff takes cv::cuda::GpuMat as argument and hence I am required to convert cv::Mat to cv::cuda::GpuMat using the upload function as used below :
gpu::GpuMat gimgCurrFrame;
gimgCurrFrame.upload(currFrameGray);
where currFrameGray is single channel Mat image
The upload function call consumes a lot of time and hence the whole purpose of running the code on GPU is defeated because of the conversion required.
Following are some of the queries I have in this context :
-
As per my knowledge,on TX1 supports memory is shared between CPU and GPU. If that is the case then why is this conversion required (if it is) ?
-
Is there any other way of using CUDA based OpenCV function calls without conversion from cv::Mat to cv::cuda::GpuMat ?
-
Based on my research, I have found a way to read frames in CUeglFrame format. Is there a way to use cuda based OpenCV functions like cv::cuda::absdiff using this format ?
-
Is there a way to read camera frames in cv::cuda::GpuMat instead of cv::Mat ?
Thanks
Thanks