Zero-Copy v4l2 capture

I am building an application which needs to capture an image from 4 different cameras, process image using OpenCV build with OpenCL and stitches 4 Images at the end.

I am new to this stream, I was able to build an application using v4l2 to capture Images. I am creating cv::UMat using OpenCL Buffer Created with clCreateBuffer. But transfer captured frame form v4l2 Buffer to OpenCL Buffer, I am using memcpy which is consuming more time (~15ms using OpenMP for-loop for 4 Images).

Code Snippet for memcpy operation
cl_mem newBuffer[4] ;
unsigned char *cDataIn[4];
cv::UMat UmatFullRes[4];

/* Init (only once) /
for (int j = 0; j < 4; j++) {
newBuffer[j] = clCreateBuffer(context, CL_MEM_READ_WRITE, (1280
8004), NULL, NULL);
cDataIn[j] = (unsigned char
)clEnqueueMapBuffer(cmdq[j], newBuffer[j],CL_FALSE, CL_MAP_WRITE | CL_MAP_READ, 0, (12808004), 0,NULL, NULL, NULL);
}
for (int j = 0; j < 4; j++) {
memcpy(cDataIn[j], buf[j], (1280 * 800 * 4));
cv::ocl::convertFromBuffer(newBuffer[j], 1280 * 4, 800, 1280, CV_8UC4, UmatFullRes[j]);
}
In the above code snippet buf[j] is the unsigned char buffer returned from captureFrame function in the capture.cpp file.

I am trying to implement the capture process with Zero-Copy (VIDIOC_EXPBUF) to OpenCL buffer to avoid memcpy operation.

I am searching for a person who could help me to understand “How to use VIDIOC_EXPBUF in my case?”, and help me in building application.

Hi supreeth

PowerVR drivers unfortunately don’t support zero-copy buffer creation in OpenCL 1.2. If you specify CL_MEM_USE_HOST_PTR, then the copy will be delayed until the GPU needs to read the contents. The only way to avoid the copy is to allocate the host pointer using clSVMAlloc(), which is an OpenCL 2.0 feature.

Kind Regards,
David