From f715e5b0b2b5d523cae91cea8b4ffa78743301ca Mon Sep 17 00:00:00 2001 From: Josh Lubawy Date: Wed, 16 Mar 2016 23:38:17 -0700 Subject: [PATCH 1/2] Add support for YUV 4:2:0 NV12 frame format in VFW camera capture --- modules/videoio/src/cap_vfw.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/videoio/src/cap_vfw.cpp b/modules/videoio/src/cap_vfw.cpp index ca5500c73..d64a5ee37 100644 --- a/modules/videoio/src/cap_vfw.cpp +++ b/modules/videoio/src/cap_vfw.cpp @@ -43,6 +43,8 @@ #include +#include + #ifdef __GNUC__ #define WM_CAP_FIRSTA (WM_USER) #define capSendMessage(hwnd,m,w,l) (IsWindow(hwnd)?SendMessage(hwnd,m,w,l):0) @@ -498,8 +500,17 @@ IplImage* CvCaptureCAM_VFW::retrieveFrame(int) frame = cvCreateImage( cvSize( vfmt0.biWidth, vfmt0.biHeight ), 8, 3 ); } - if( vfmt0.biCompression != BI_RGB || - vfmt0.biBitCount != 24 ) + if ( vfmt0.biCompression == MAKEFOURCC('N','V','1','2') ) + { + // Frame is in YUV 4:2:0 NV12 format, convert to BGR color space + // See https://msdn.microsoft.com/en-us/library/windows/desktop/dd206750(v=vs.85).aspx#nv12) + IplImage src; + cvInitImageHeader( &src, cvSize( vfmt0.biWidth, vfmt0.biHeight * 3 / 2 ), IPL_DEPTH_8U, 1, IPL_ORIGIN_BL, 4 ); + cvSetData( &src, hdr->lpData, src.widthStep ); + cvCvtColor( &src, frame, CV_YUV2BGR_NV12 ); + } + else if( vfmt0.biCompression != BI_RGB || + vfmt0.biBitCount != 24 ) { BITMAPINFOHEADER vfmt1 = icvBitmapHeader( vfmt0.biWidth, vfmt0.biHeight, 24 ); From 1bd8bcbdd9f63102a415fc1f4a53cc57ab788d62 Mon Sep 17 00:00:00 2001 From: Josh Lubawy Date: Thu, 17 Mar 2016 01:00:49 -0700 Subject: [PATCH 2/2] Remove cstdio debug --- modules/videoio/src/cap_vfw.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/videoio/src/cap_vfw.cpp b/modules/videoio/src/cap_vfw.cpp index d64a5ee37..555e84830 100644 --- a/modules/videoio/src/cap_vfw.cpp +++ b/modules/videoio/src/cap_vfw.cpp @@ -43,8 +43,6 @@ #include -#include - #ifdef __GNUC__ #define WM_CAP_FIRSTA (WM_USER) #define capSendMessage(hwnd,m,w,l) (IsWindow(hwnd)?SendMessage(hwnd,m,w,l):0)