- Set 'Software Frame Decimation' begin to 0

- Removed grabber specific device name from Log
- Keep pixel format when switching resolution
- Display 'Flip mode' correct in Log
- BGR24 images always flipped
This commit is contained in:
Paulchen Panther 2021-01-29 21:08:47 +01:00
parent bfc818ab45
commit 07a6d5e5b1
6 changed files with 31 additions and 15 deletions

View File

@ -70,7 +70,7 @@
"fps" : 15, "fps" : 15,
"standard" : "NO_CHANGE", "standard" : "NO_CHANGE",
"flip" : "NO_CHANGE", "flip" : "NO_CHANGE",
"fpsSoftwareDecimation" : 1, "fpsSoftwareDecimation" : 0,
"sizeDecimation" : 8, "sizeDecimation" : 8,
"cropLeft" : 0, "cropLeft" : 0,
"cropRight" : 0, "cropRight" : 0,

View File

@ -5,7 +5,7 @@
namespace { const bool verbose = false; } namespace { const bool verbose = false; }
MFGrabber::MFGrabber(const QString & device, unsigned width, unsigned height, unsigned fps, int pixelDecimation, QString flipMode) MFGrabber::MFGrabber(const QString & device, unsigned width, unsigned height, unsigned fps, int pixelDecimation, QString flipMode)
: Grabber("V4L2:"+device) : Grabber("V4L2:MEDIA_FOUNDATION")
, _currentDeviceName(device) , _currentDeviceName(device)
, _newDeviceName(device) , _newDeviceName(device)
, _hr(S_FALSE) , _hr(S_FALSE)
@ -15,7 +15,7 @@ MFGrabber::MFGrabber(const QString & device, unsigned width, unsigned height, un
, _frameByteSize(-1) , _frameByteSize(-1)
, _noSignalCounterThreshold(40) , _noSignalCounterThreshold(40)
, _noSignalCounter(0) , _noSignalCounter(0)
, _fpsSoftwareDecimation(1) , _fpsSoftwareDecimation(0)
, _brightness(0) , _brightness(0)
, _contrast(0) , _contrast(0)
, _saturation(0) , _saturation(0)
@ -65,6 +65,7 @@ bool MFGrabber::init()
// enumerate the video capture devices on the user's system // enumerate the video capture devices on the user's system
enumVideoCaptureDevices(); enumVideoCaptureDevices();
//
if(!autoDiscovery && !_deviceProperties.contains(_currentDeviceName)) if(!autoDiscovery && !_deviceProperties.contains(_currentDeviceName))
{ {
Debug(_log, "Device '%s' is not available. Changing to auto.", QSTRING_CSTR(_currentDeviceName)); Debug(_log, "Device '%s' is not available. Changing to auto.", QSTRING_CSTR(_currentDeviceName));
@ -134,9 +135,9 @@ bool MFGrabber::init()
if(foundIndex < 0 && bestGuess >= 0) if(foundIndex < 0 && bestGuess >= 0)
{ {
if(!autoDiscovery && _width != 0 && _height != 0) if(!autoDiscovery && _width != 0 && _height != 0)
Warning(_log, "Selected resolution not found in supported modes. Forcing best resolution"); Warning(_log, "Selected resolution not found in supported modes. Set default configuration");
else else
Debug(_log, "Forcing best resolution"); Debug(_log, "Set default configuration");
foundIndex = bestGuess; foundIndex = bestGuess;
} }
@ -536,7 +537,7 @@ void MFGrabber::process_image(const void *frameImageBuffer, int size)
unsigned int processFrameIndex = _currentFrame++; unsigned int processFrameIndex = _currentFrame++;
// frame skipping // frame skipping
if((processFrameIndex % _fpsSoftwareDecimation != 0) && (_fpsSoftwareDecimation > 1)) if((processFrameIndex % (_fpsSoftwareDecimation + 1) != 0) && (_fpsSoftwareDecimation > 0))
return; return;
// CEC detection // CEC detection
@ -637,7 +638,9 @@ void MFGrabber::stop()
_initialized = false; _initialized = false;
_threadManager.stop(); _threadManager.stop();
uninit_device(); uninit_device();
_pixelFormat = _pixelFormatConfig; // restore pixelformat to configs value if it is not auto or device name has not changed
if(_pixelFormatConfig != PixelFormat::NO_CHANGE || _newDeviceName != _currentDeviceName)
_pixelFormat = _pixelFormatConfig;
_deviceProperties.clear(); _deviceProperties.clear();
Info(_log, "Stopped"); Info(_log, "Stopped");
} }
@ -797,8 +800,8 @@ bool MFGrabber::setFramerate(int fps)
void MFGrabber::setFpsSoftwareDecimation(int decimation) void MFGrabber::setFpsSoftwareDecimation(int decimation)
{ {
_fpsSoftwareDecimation = decimation; _fpsSoftwareDecimation = decimation;
if(decimation > 1) if(decimation > 0)
Debug(_log,"Every %ith image per second are processed", decimation); Debug(_log,"Skip %i frame per second", decimation);
} }
bool MFGrabber::setEncoding(QString enc) bool MFGrabber::setEncoding(QString enc)
@ -836,8 +839,9 @@ void MFGrabber::reloadGrabber()
Debug(_log,"Reloading Media Foundation Grabber"); Debug(_log,"Reloading Media Foundation Grabber");
// stop grabber // stop grabber
uninit(); uninit();
// restore pixelformat to configs value // restore pixelformat to configs value if it is not auto or device name has not changed
_pixelFormat = _pixelFormatConfig; if(_pixelFormatConfig != PixelFormat::NO_CHANGE || _newDeviceName != _currentDeviceName)
_pixelFormat = _pixelFormatConfig;
// set _newDeviceName // set _newDeviceName
_newDeviceName = _currentDeviceName; _newDeviceName = _currentDeviceName;
// start grabber // start grabber

View File

@ -71,6 +71,18 @@ void MFThread::run()
} }
else else
{ {
if (_pixelFormat == PixelFormat::BGR24)
{
if (_flipMode == FlipMode::NO_CHANGE)
_imageResampler.setFlipMode(FlipMode::HORIZONTAL);
else if (_flipMode == FlipMode::HORIZONTAL)
_imageResampler.setFlipMode(FlipMode::NO_CHANGE);
else if (_flipMode == FlipMode::VERTICAL)
_imageResampler.setFlipMode(FlipMode::BOTH);
else if (_flipMode == FlipMode::BOTH)
_imageResampler.setFlipMode(FlipMode::VERTICAL);
}
Image<ColorRgb> image = Image<ColorRgb>(); Image<ColorRgb> image = Image<ColorRgb>();
_imageResampler.processImage(_localData, _width, _height, _lineLength, PixelFormat::BGR24, image); _imageResampler.processImage(_localData, _width, _height, _lineLength, PixelFormat::BGR24, image);
emit newFrame(_threadIndex, image, _currentFrame); emit newFrame(_threadIndex, image, _currentFrame);

View File

@ -6,7 +6,7 @@
#include <QTimer> #include <QTimer>
MFWrapper::MFWrapper(const QString &device, unsigned grabWidth, unsigned grabHeight, unsigned fps, int pixelDecimation, QString flipMode) MFWrapper::MFWrapper(const QString &device, unsigned grabWidth, unsigned grabHeight, unsigned fps, int pixelDecimation, QString flipMode)
: GrabberWrapper("V4L2:"+device, &_grabber, grabWidth, grabHeight, 10) : GrabberWrapper("V4L2:MEDIA_FOUNDATION", &_grabber, grabWidth, grabHeight, 10)
, _grabber(device, grabWidth, grabHeight, fps, pixelDecimation, flipMode) , _grabber(device, grabWidth, grabHeight, fps, pixelDecimation, flipMode)
{ {
_ggrabber = &_grabber; _ggrabber = &_grabber;

View File

@ -38,7 +38,7 @@ void Grabber::setVideoMode(VideoMode mode)
void Grabber::setFlipMode(FlipMode mode) void Grabber::setFlipMode(FlipMode mode)
{ {
Debug(_log,"Set flipmode to %d", mode); Debug(_log,"Set flipmode to %s", QSTRING_CSTR(flipModeToString(mode)));
_flipMode = mode; _flipMode = mode;
if ( _useImageResampler ) if ( _useImageResampler )
{ {

View File

@ -110,9 +110,9 @@
{ {
"type" : "integer", "type" : "integer",
"title" : "edt_conf_v4l2_fpsSoftwareDecimation_title", "title" : "edt_conf_v4l2_fpsSoftwareDecimation_title",
"minimum" : 1, "minimum" : 0,
"maximum" : 60, "maximum" : 60,
"default" : 1, "default" : 0,
"required" : true, "required" : true,
"propertyOrder" : 14 "propertyOrder" : 14
}, },