Commit 4701b22e authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #3607 from soyersoyer:yuyv_pixfmt

parents dcff28b7 d84d3a51
...@@ -136,7 +136,8 @@ enum { CAP_PROP_POS_MSEC =0, ...@@ -136,7 +136,8 @@ enum { CAP_PROP_POS_MSEC =0,
// Currently, these are supported through the libv4l interface only. // Currently, these are supported through the libv4l interface only.
enum { CAP_MODE_BGR = 0, // BGR24 (default) enum { CAP_MODE_BGR = 0, // BGR24 (default)
CAP_MODE_RGB = 1, // RGB24 CAP_MODE_RGB = 1, // RGB24
CAP_MODE_GRAY = 2 // Y8 CAP_MODE_GRAY = 2, // Y8
CAP_MODE_YUYV = 3 // YUYV
}; };
......
...@@ -299,7 +299,8 @@ enum ...@@ -299,7 +299,8 @@ enum
{ {
CV_CAP_MODE_BGR = 0, // BGR24 (default) CV_CAP_MODE_BGR = 0, // BGR24 (default)
CV_CAP_MODE_RGB = 1, // RGB24 CV_CAP_MODE_RGB = 1, // RGB24
CV_CAP_MODE_GRAY = 2 // Y8 CV_CAP_MODE_GRAY = 2, // Y8
CV_CAP_MODE_YUYV = 3 // YUYV
}; };
enum enum
......
...@@ -646,6 +646,8 @@ static inline int channels_for_mode(int mode) ...@@ -646,6 +646,8 @@ static inline int channels_for_mode(int mode)
switch(mode) { switch(mode) {
case CV_CAP_MODE_GRAY: case CV_CAP_MODE_GRAY:
return 1; return 1;
case CV_CAP_MODE_YUYV:
return 2;
default: default:
return 3; return 3;
} }
...@@ -713,31 +715,26 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName) ...@@ -713,31 +715,26 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture, char *deviceName)
/* libv4l will convert from any format to V4L2_PIX_FMT_BGR24, /* libv4l will convert from any format to V4L2_PIX_FMT_BGR24,
V4L2_PIX_FMT_RGV24, or V4L2_PIX_FMT_YUV420 */ V4L2_PIX_FMT_RGV24, or V4L2_PIX_FMT_YUV420 */
unsigned int requestedPixelFormat; unsigned int requestedPixelFormat;
int width;
int height;
switch (capture->mode) { switch (capture->mode) {
case CV_CAP_MODE_RGB: case CV_CAP_MODE_RGB:
requestedPixelFormat = V4L2_PIX_FMT_RGB24; requestedPixelFormat = V4L2_PIX_FMT_RGB24;
width = capture->width;
height = capture->height;
break; break;
case CV_CAP_MODE_GRAY: case CV_CAP_MODE_GRAY:
requestedPixelFormat = V4L2_PIX_FMT_YUV420; requestedPixelFormat = V4L2_PIX_FMT_YUV420;
width = capture->width; break;
height = capture->height; case CV_CAP_MODE_YUYV:
requestedPixelFormat = V4L2_PIX_FMT_YUYV;
break; break;
default: default:
requestedPixelFormat = V4L2_PIX_FMT_BGR24; requestedPixelFormat = V4L2_PIX_FMT_BGR24;
width = capture->width;
height = capture->height;
break; break;
} }
CLEAR (capture->form); CLEAR (capture->form);
capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
capture->form.fmt.pix.pixelformat = requestedPixelFormat; capture->form.fmt.pix.pixelformat = requestedPixelFormat;
capture->form.fmt.pix.field = V4L2_FIELD_ANY; capture->form.fmt.pix.field = V4L2_FIELD_ANY;
capture->form.fmt.pix.width = width; capture->form.fmt.pix.width = capture->width;
capture->form.fmt.pix.height = height; capture->form.fmt.pix.height = capture->height;
if (-1 == xioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form)) { if (-1 == xioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form)) {
fprintf(stderr, "VIDEOIO ERROR: libv4l unable to ioctl S_FMT\n"); fprintf(stderr, "VIDEOIO ERROR: libv4l unable to ioctl S_FMT\n");
...@@ -949,6 +946,10 @@ static int _capture_V4L (CvCaptureCAM_V4L *capture, char *deviceName) ...@@ -949,6 +946,10 @@ static int _capture_V4L (CvCaptureCAM_V4L *capture, char *deviceName)
requestedVideoPalette = VIDEO_PALETTE_YUV420; requestedVideoPalette = VIDEO_PALETTE_YUV420;
depth = 8; depth = 8;
break; break;
case CV_CAP_MODE_YUYV:
requestedVideoPalette = VIDEO_PALETTE_YUYV;
depth = 16;
break;
default: default:
requestedVideoPalette = VIDEO_PALETTE_RGB24; requestedVideoPalette = VIDEO_PALETTE_RGB24;
depth = 24; depth = 24;
...@@ -1319,6 +1320,7 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) { ...@@ -1319,6 +1320,7 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) {
switch(capture->imageProperties.palette) { switch(capture->imageProperties.palette) {
case VIDEO_PALETTE_RGB24: case VIDEO_PALETTE_RGB24:
case VIDEO_PALETTE_YUV420: case VIDEO_PALETTE_YUV420:
case VIDEO_PALETTE_YUYV:
memcpy((char *)capture->frame.imageData, memcpy((char *)capture->frame.imageData,
(char *)(capture->memoryMap + capture->memoryBuffer.offsets[capture->bufferIndex]), (char *)(capture->memoryMap + capture->memoryBuffer.offsets[capture->bufferIndex]),
capture->frame.imageSize); capture->frame.imageSize);
...@@ -1464,6 +1466,10 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { ...@@ -1464,6 +1466,10 @@ static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) {
cropHeight = h*8; cropHeight = h*8;
cropWidth = w*8; cropWidth = w*8;
break; break;
case CV_CAP_MODE_YUYV:
cropHeight = h*16;
cropWidth = w*16;
break;
default: default:
cropHeight = h*24; cropHeight = h*24;
cropWidth = w*24; cropWidth = w*24;
...@@ -1719,6 +1725,7 @@ static int icvSetPropertyCAM_V4L(CvCaptureCAM_V4L* capture, int property_id, dou ...@@ -1719,6 +1725,7 @@ static int icvSetPropertyCAM_V4L(CvCaptureCAM_V4L* capture, int property_id, dou
case CV_CAP_MODE_BGR: case CV_CAP_MODE_BGR:
case CV_CAP_MODE_RGB: case CV_CAP_MODE_RGB:
case CV_CAP_MODE_GRAY: case CV_CAP_MODE_GRAY:
case CV_CAP_MODE_YUYV:
capture->mode = mode; capture->mode = mode;
/* recreate the capture buffer for the same output resolution /* recreate the capture buffer for the same output resolution
but a different pixel format */ but a different pixel format */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment