Hi!
We are trying to convert YUV frames captured using libuvc (usb cameras) to RGB, but we are not able to get the right color.
The format that libuvc gives the frames in is YUV422 acording with the headers:
enum uvc_frame_format {
....
UVC_FRAME_FORMAT_COMPRESSED,
/** YUYV/YUV2/YUV422: YUV encoding with one luminance value per pixel and
* one UV (chrominance) pair for every two pixels.
*/
With dimensions 1920x1024, stride 3840 (1920*2)
And the code we are using to convert the color is:
cv::Mat ConvertFrame(uvc_frame_t *frame, int inputFormat=G2D_YUYV){
void *G2D_Handler=NULL;
if (g2d_open(&G2D_Handler)!=0){
puts("G2D_Start: Error opening g2d device");
};
int size = frame->data_bytes;
struct g2d_buf *srcM = g2d_alloc (size,1);
struct g2d_buf *dstM = g2d_alloc (frame->width * frame->height * 3,1);
memcpy(srcM->buf_vaddr, frame->data, size);
struct g2d_surface src,dst;
src.planes[0] = srcM->buf_paddr;
src.planes[1] = 0; //srcM->buf_paddr;
src.planes[2] = 0; //srcM->buf_paddr;
src.left = 0;
src.top = 0;
src.right = frame->width;
src.bottom = frame->height;
src.stride = frame->step;
src.width = frame->width;
src.height = frame->height;
src.rot = G2D_ROTATION_0;
src.format = inputFormat;
cv::Mat out(frame->height, frame->width, CV_8UC3, dstM->buf_vaddr );
dst.planes[0] = dstM->buf_paddr;
dst.left = 0;
dst.top = 0;
dst.right = out.cols;
dst.bottom = out.rows;
dst.stride = out.step1();
dst.width = out.cols;
dst.height = out.rows;
dst.rot = G2D_ROTATION_0;
dst.format = G2D_RGB888 ;
int r = g2d_blit(G2D_Handler, &src, &dst);
if (r!=0) puts("convertFrame :: ERROR g2d_blit");
r=g2d_finish(G2D_Handler);
if (r!=0) puts("convertFrame :: ERROR g2d_finish");
char name[128];
snprintf(name,128,"g2dOutput_%d.png", inputFormat );
cv::imwrite(name,out);
g2d_free (srcM);
return out;
}
The better results we could get are with inputFormat = G2D_YUYV, but as can be seen in the attached image, this is far to be correct.
Can someone give us an idea on how to solve this problem?
Thanks in advance!
Hello ivan_garcia
Currently, libg2d does not support YUYV convert to BGR. I will discuss with R&D team to enable.
Regards