mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
make v4l signal detection switchable (#415)
This commit is contained in:
@@ -47,6 +47,12 @@ V4L2Grabber::V4L2Grabber(const QString & device
|
||||
, _frameDecimation(std::max(1, frameDecimation))
|
||||
, _noSignalCounterThreshold(50)
|
||||
, _noSignalThresholdColor(ColorRgb{0,0,0})
|
||||
, _signalDetectionEnabled(true)
|
||||
, _noSignalDetected(false)
|
||||
, _x_frac_min(0.25)
|
||||
, _y_frac_min(0.25)
|
||||
, _x_frac_max(0.75)
|
||||
, _y_frac_max(0.75)
|
||||
, _currentFrame(0)
|
||||
, _noSignalCounter(0)
|
||||
, _streamNotifier(nullptr)
|
||||
@@ -54,11 +60,6 @@ V4L2Grabber::V4L2Grabber(const QString & device
|
||||
, _log(Logger::getInstance("V4L2:"+device))
|
||||
, _initialized(false)
|
||||
, _deviceAutoDiscoverEnabled(false)
|
||||
, _noSignalDetected(false)
|
||||
, _x_frac_min(0.25)
|
||||
, _y_frac_min(0.25)
|
||||
, _x_frac_max(0.75)
|
||||
, _y_frac_max(0.75)
|
||||
|
||||
{
|
||||
_imageResampler.setHorizontalPixelDecimation(std::max(1, horizontalPixelDecimation));
|
||||
@@ -809,50 +810,57 @@ void V4L2Grabber::process_image(const uint8_t * data)
|
||||
Image<ColorRgb> image(0, 0);
|
||||
_imageResampler.processImage(data, _width, _height, _lineLength, _pixelFormat, image);
|
||||
|
||||
// check signal (only in center of the resulting image, because some grabbers have noise values along the borders)
|
||||
bool noSignal = true;
|
||||
|
||||
// top left
|
||||
unsigned xOffset = image.width() * _x_frac_min;
|
||||
unsigned yOffset = image.height() * _y_frac_min;
|
||||
|
||||
// bottom right
|
||||
unsigned xMax = image.width() * _x_frac_max;
|
||||
unsigned yMax = image.height() * _y_frac_max;
|
||||
|
||||
|
||||
for (unsigned x = xOffset; noSignal && x < xMax; ++x)
|
||||
if (_signalDetectionEnabled)
|
||||
{
|
||||
for (unsigned y = yOffset; noSignal && y < yMax; ++y)
|
||||
// check signal (only in center of the resulting image, because some grabbers have noise values along the borders)
|
||||
bool noSignal = true;
|
||||
|
||||
// top left
|
||||
unsigned xOffset = image.width() * _x_frac_min;
|
||||
unsigned yOffset = image.height() * _y_frac_min;
|
||||
|
||||
// bottom right
|
||||
unsigned xMax = image.width() * _x_frac_max;
|
||||
unsigned yMax = image.height() * _y_frac_max;
|
||||
|
||||
|
||||
for (unsigned x = xOffset; noSignal && x < xMax; ++x)
|
||||
{
|
||||
noSignal &= (ColorRgb&)image(x, y) <= _noSignalThresholdColor;
|
||||
for (unsigned y = yOffset; noSignal && y < yMax; ++y)
|
||||
{
|
||||
noSignal &= (ColorRgb&)image(x, y) <= _noSignalThresholdColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (noSignal)
|
||||
{
|
||||
++_noSignalCounter;
|
||||
if (noSignal)
|
||||
{
|
||||
++_noSignalCounter;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_noSignalCounter >= _noSignalCounterThreshold)
|
||||
{
|
||||
_noSignalDetected = true;
|
||||
Info(_log, "Signal detected");
|
||||
}
|
||||
|
||||
_noSignalCounter = 0;
|
||||
}
|
||||
|
||||
if ( _noSignalCounter < _noSignalCounterThreshold)
|
||||
{
|
||||
emit newFrame(image);
|
||||
}
|
||||
else if (_noSignalCounter == _noSignalCounterThreshold)
|
||||
{
|
||||
_noSignalDetected = false;
|
||||
Info(_log, "Signal lost");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_noSignalCounter >= _noSignalCounterThreshold)
|
||||
{
|
||||
_noSignalDetected = true;
|
||||
Info(_log, "Signal detected");
|
||||
}
|
||||
|
||||
_noSignalCounter = 0;
|
||||
}
|
||||
|
||||
if (_noSignalCounter < _noSignalCounterThreshold)
|
||||
{
|
||||
emit newFrame(image);
|
||||
}
|
||||
else if (_noSignalCounter == _noSignalCounterThreshold)
|
||||
{
|
||||
_noSignalDetected = false;
|
||||
Info(_log, "Signal lost");
|
||||
}
|
||||
}
|
||||
|
||||
int V4L2Grabber::xioctl(int request, void *arg)
|
||||
@@ -877,3 +885,13 @@ void V4L2Grabber::throw_errno_exception(const QString & error)
|
||||
{
|
||||
throw std::runtime_error(QString(error + " error code " + QString::number(errno) + ", " + strerror(errno)).toStdString());
|
||||
}
|
||||
|
||||
void V4L2Grabber::setSignalDetectionEnable(bool enable)
|
||||
{
|
||||
_signalDetectionEnabled = enable;
|
||||
}
|
||||
|
||||
bool V4L2Grabber::getSignalDetectionEnabled()
|
||||
{
|
||||
return _signalDetectionEnabled;
|
||||
}
|
||||
|
@@ -122,3 +122,13 @@ void V4L2Wrapper::action()
|
||||
{
|
||||
checkSources();
|
||||
}
|
||||
|
||||
void V4L2Wrapper::setSignalDetectionEnable(bool enable)
|
||||
{
|
||||
_grabber.setSignalDetectionEnable(enable);
|
||||
}
|
||||
|
||||
bool V4L2Wrapper::getSignalDetectionEnable()
|
||||
{
|
||||
return _grabber.getSignalDetectionEnabled();
|
||||
}
|
||||
|
@@ -544,6 +544,13 @@
|
||||
"append" : "edt_append_pixel",
|
||||
"propertyOrder" : 15
|
||||
},
|
||||
"signalDetection" :
|
||||
{
|
||||
"type" : "boolean",
|
||||
"title" : "edt_conf_v4l2_signalDetection_title",
|
||||
"default" : true,
|
||||
"propertyOrder" : 16
|
||||
},
|
||||
"redSignalThreshold" :
|
||||
{
|
||||
"type" : "number",
|
||||
@@ -553,7 +560,7 @@
|
||||
"default" : 0.1,
|
||||
"step" : 0.005,
|
||||
"append" : "edt_append_percent",
|
||||
"propertyOrder" : 16
|
||||
"propertyOrder" : 17
|
||||
},
|
||||
"greenSignalThreshold" :
|
||||
{
|
||||
@@ -564,7 +571,7 @@
|
||||
"default" : 0.1,
|
||||
"step" : 0.025,
|
||||
"append" : "edt_append_percent",
|
||||
"propertyOrder" : 17
|
||||
"propertyOrder" : 18
|
||||
},
|
||||
"blueSignalThreshold" :
|
||||
{
|
||||
@@ -575,7 +582,7 @@
|
||||
"default" : 0.1,
|
||||
"step" : 0.005,
|
||||
"append" : "edt_append_percent",
|
||||
"propertyOrder" : 18
|
||||
"propertyOrder" : 19
|
||||
},
|
||||
"signalDetectionVerticalOffsetMin" :
|
||||
{
|
||||
@@ -586,7 +593,7 @@
|
||||
"default" : 0.1,
|
||||
"step" : 0.005,
|
||||
"append" : "edt_append_percent",
|
||||
"propertyOrder" : 19
|
||||
"propertyOrder" : 20
|
||||
},
|
||||
"signalDetectionVerticalOffsetMax" :
|
||||
{
|
||||
@@ -597,7 +604,7 @@
|
||||
"default" : 0.1,
|
||||
"step" : 0.005,
|
||||
"append" : "edt_append_percent",
|
||||
"propertyOrder" : 20
|
||||
"propertyOrder" : 21
|
||||
},
|
||||
"signalDetectionHorizontalOffsetMin" :
|
||||
{
|
||||
@@ -608,7 +615,7 @@
|
||||
"default" : 0.1,
|
||||
"step" : 0.005,
|
||||
"append" : "edt_append_percent",
|
||||
"propertyOrder" : 21
|
||||
"propertyOrder" : 22
|
||||
},
|
||||
"signalDetectionHorizontalOffsetMax" :
|
||||
{
|
||||
@@ -619,7 +626,7 @@
|
||||
"default" : 0.1,
|
||||
"step" : 0.005,
|
||||
"append" : "edt_append_percent",
|
||||
"propertyOrder" : 22
|
||||
"propertyOrder" : 23
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
|
Reference in New Issue
Block a user