Kill "Rainbow lights" when v4l grabber has no signal (#334)

* on v4l screenshot, print out nosignal threshold values

* separate fractional parameters for no signal detection

* fully implement handling for "rainbow grabber"
This commit is contained in:
redPanther
2016-12-16 19:48:43 +01:00
committed by GitHub
parent b227f5a71c
commit d59c94421d
12 changed files with 251 additions and 36 deletions

View File

@@ -23,15 +23,16 @@
#define CLEAR(x) memset(&(x), 0, sizeof(x))
V4L2Grabber::V4L2Grabber(const std::string & device,
int input,
VideoStandard videoStandard,
PixelFormat pixelFormat,
int width,
int height,
int frameDecimation,
int horizontalPixelDecimation,
int verticalPixelDecimation)
V4L2Grabber::V4L2Grabber(const std::string & device
, int input
, VideoStandard videoStandard
, PixelFormat pixelFormat
, int width
, int height
, int frameDecimation
, int horizontalPixelDecimation
, int verticalPixelDecimation
)
: _deviceName(device)
, _input(input)
, _videoStandard(videoStandard)
@@ -53,6 +54,12 @@ V4L2Grabber::V4L2Grabber(const std::string & 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));
_imageResampler.setVerticalPixelDecimation(std::max(1, verticalPixelDecimation));
@@ -196,6 +203,24 @@ void V4L2Grabber::setSignalThreshold(double redSignalThreshold, double greenSign
Info(_log, "Signal threshold set to: %s", ss.str().c_str() );
}
void V4L2Grabber::setSignalDetectionOffset(double horizontalMin, double verticalMin, double horizontalMax, double verticalMax)
{
// rainbow 16 stripes 0.47 0.2 0.49 0.8
// unicolor: 0.25 0.25 0.75 0.75
_x_frac_min = horizontalMin;
_y_frac_min = verticalMin;
_x_frac_max = horizontalMax;
_y_frac_max = verticalMax;
Info(_log, "Signal detection area set to: %f,%f x %f,%f", _x_frac_min, _y_frac_min, _x_frac_max, _y_frac_max );
}
QRectF V4L2Grabber::getSignalDetectionOffset()
{
return QRectF(_x_frac_min, _y_frac_min, _x_frac_max, _y_frac_max);
}
bool V4L2Grabber::start()
{
try
@@ -787,16 +812,21 @@ void V4L2Grabber::process_image(const uint8_t * data)
// check signal (only in center of the resulting image, because some grabbers have noise values along the borders)
bool noSignal = true;
for (unsigned x = 0; noSignal && x < (image.width()>>1); ++x)
// 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)
{
int xImage = (image.width()>>2) + x;
for (unsigned y = 0; noSignal && y < (image.height()>>1); ++y)
for (unsigned y = yOffset; noSignal && y < yMax; ++y)
{
int yImage = (image.height()>>2) + y;
ColorRgb & rgb = image(xImage, yImage);
noSignal &= rgb <= _noSignalThresholdColor;
noSignal &= (ColorRgb&)image(x, y) <= _noSignalThresholdColor;
}
}
@@ -808,6 +838,7 @@ void V4L2Grabber::process_image(const uint8_t * data)
{
if (_noSignalCounter >= _noSignalCounterThreshold)
{
_noSignalDetected = true;
Info(_log, "Signal detected");
}
@@ -820,6 +851,7 @@ void V4L2Grabber::process_image(const uint8_t * data)
}
else if (_noSignalCounter == _noSignalCounterThreshold)
{
_noSignalDetected = false;
Info(_log, "Signal lost");
}
}

View File

@@ -74,6 +74,12 @@ void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int crop
_grabber.setCropping(cropLeft, cropRight, cropTop, cropBottom);
}
void V4L2Wrapper::setSignalDetectionOffset(double verticalMin, double horizontalMin, double verticalMax, double horizontalMax)
{
_grabber.setSignalDetectionOffset(verticalMin, horizontalMin, verticalMax, horizontalMax);
}
void V4L2Wrapper::set3D(VideoMode mode)
{
_grabber.set3D(mode);

View File

@@ -540,7 +540,7 @@
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.01,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 16
},
@@ -551,7 +551,7 @@
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.01,
"step" : 0.025,
"append" : "edt_append_percent",
"propertyOrder" : 17
},
@@ -562,9 +562,53 @@
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.01,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 18
},
"signalDetectionVerticalOffsetMin" :
{
"type" : "number",
"title" : "edt_conf_v4l2_signalDetectionVerticalOffsetMin_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 19
},
"signalDetectionVerticalOffsetMax" :
{
"type" : "number",
"title" : "edt_conf_v4l2_signalDetectionVerticalOffsetMax_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 20
},
"signalDetectionHorizontalOffsetMin" :
{
"type" : "number",
"title" : "edt_conf_v4l2_signalDetectionHorizontalOffsetMin_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 21
},
"signalDetectionHorizontalOffsetMax" :
{
"type" : "number",
"title" : "edt_conf_v4l2_signalDetectionHorizontalOffsetMax_title",
"minimum" : 0.0,
"maximum" : 1.0,
"default" : 0.1,
"step" : 0.005,
"append" : "edt_append_percent",
"propertyOrder" : 22
}
},
"additionalProperties" : false