@@ -52,6 +52,7 @@ V4L2Grabber::V4L2Grabber(const std::string & device,
52
52
_pixelFormat(pixelFormat),
53
53
_width(width),
54
54
_height(height),
55
+ _frameByteSize(-1 ),
55
56
_cropLeft(0 ),
56
57
_cropRight(0 ),
57
58
_cropTop(0 ),
@@ -426,32 +427,35 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
426
427
throw_errno_exception (" VIDIOC_G_FMT" );
427
428
}
428
429
429
- // check pixel format
430
+ // store width & height
431
+ _width = fmt.fmt .pix .width ;
432
+ _height = fmt.fmt .pix .height ;
433
+
434
+ // print the eventually used width and height
435
+ std::cout << " V4L2 width=" << _width << " height=" << _height << std::endl;
436
+
437
+ // check pixel format and frame size
430
438
switch (fmt.fmt .pix .pixelformat )
431
439
{
432
440
case V4L2_PIX_FMT_UYVY:
433
441
_pixelFormat = PIXELFORMAT_UYVY;
442
+ _frameByteSize = _width * _height * 2 ;
434
443
std::cout << " V4L2 pixel format=UYVY" << std::endl;
435
444
break ;
436
445
case V4L2_PIX_FMT_YUYV:
437
446
_pixelFormat = PIXELFORMAT_YUYV;
447
+ _frameByteSize = _width * _height * 2 ;
438
448
std::cout << " V4L2 pixel format=YUYV" << std::endl;
439
449
break ;
440
450
case V4L2_PIX_FMT_RGB32:
441
451
_pixelFormat = PIXELFORMAT_RGB32;
452
+ _frameByteSize = _width * _height * 4 ;
442
453
std::cout << " V4L2 pixel format=RGB32" << std::endl;
443
454
break ;
444
455
default :
445
456
throw_exception (" Only pixel formats UYVY, YUYV, and RGB32 are supported" );
446
457
}
447
458
448
- // store width & height
449
- _width = fmt.fmt .pix .width ;
450
- _height = fmt.fmt .pix .height ;
451
-
452
- // print the eventually used width and height
453
- std::cout << " V4L2 width=" << _width << " height=" << _height << std::endl;
454
-
455
459
switch (_ioMethod) {
456
460
case IO_METHOD_READ:
457
461
init_read (fmt.fmt .pix .sizeimage );
@@ -667,9 +671,9 @@ bool V4L2Grabber::process_image(const void *p, int size)
667
671
{
668
672
// We do want a new frame...
669
673
670
- if (size != 2 *_width*_height )
674
+ if (size != _frameByteSize )
671
675
{
672
- std::cout << " Frame too small: " << size << " != " << ( 2 *_width*_height) << std::endl;
676
+ std::cout << " Frame too small: " << size << " != " << _frameByteSize << std::endl;
673
677
}
674
678
else
675
679
{
0 commit comments