mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Add support to set the threshold for each RGB channel separately
Former-commit-id: 5edb206bb2657e78f711f67625fd5f6164d8296c
This commit is contained in:
@@ -36,8 +36,7 @@ static void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t & r, uint8_t & g, u
|
||||
}
|
||||
|
||||
|
||||
V4L2Grabber::V4L2Grabber(
|
||||
const std::string & device,
|
||||
V4L2Grabber::V4L2Grabber(const std::string & device,
|
||||
int input,
|
||||
VideoStandard videoStandard,
|
||||
int width,
|
||||
@@ -59,8 +58,11 @@ V4L2Grabber::V4L2Grabber(
|
||||
_frameDecimation(std::max(1, frameDecimation)),
|
||||
_horizontalPixelDecimation(std::max(1, horizontalPixelDecimation)),
|
||||
_verticalPixelDecimation(std::max(1, verticalPixelDecimation)),
|
||||
_noSignalCounterThreshold(50),
|
||||
_noSignalThresholdColor(ColorRgb{0,0,0}),
|
||||
_mode3D(VIDEO_2D),
|
||||
_currentFrame(0),
|
||||
_noSignalCounter(0),
|
||||
_streamNotifier(nullptr)
|
||||
{
|
||||
open_device();
|
||||
@@ -91,6 +93,14 @@ void V4L2Grabber::set3D(VideoMode mode)
|
||||
_mode3D = mode;
|
||||
}
|
||||
|
||||
void V4L2Grabber::setSignalThreshold(double redSignalThreshold, double greenSignalThreshold, double blueSignalThreshold, int noSignalCounterThreshold)
|
||||
{
|
||||
_noSignalThresholdColor.red = uint8_t(255*redSignalThreshold);
|
||||
_noSignalThresholdColor.green = uint8_t(255*greenSignalThreshold);
|
||||
_noSignalThresholdColor.blue = uint8_t(255*blueSignalThreshold);
|
||||
_noSignalCounterThreshold = std::max(1, noSignalCounterThreshold);
|
||||
}
|
||||
|
||||
void V4L2Grabber::start()
|
||||
{
|
||||
_streamNotifier->setEnabled(true);
|
||||
@@ -658,6 +668,8 @@ void V4L2Grabber::process_image(const uint8_t * data)
|
||||
int outputHeight = (height - _cropTop - _cropBottom + _verticalPixelDecimation/2) / _verticalPixelDecimation;
|
||||
Image<ColorRgb> image(outputWidth, outputHeight);
|
||||
|
||||
bool noSignal = true;
|
||||
|
||||
for (int ySource = _cropTop + _verticalPixelDecimation/2, yDest = 0; ySource < height - _cropBottom; ySource += _verticalPixelDecimation, ++yDest)
|
||||
{
|
||||
for (int xSource = _cropLeft + _horizontalPixelDecimation/2, xDest = 0; xSource < width - _cropRight; xSource += _horizontalPixelDecimation, ++xDest)
|
||||
@@ -683,10 +695,32 @@ void V4L2Grabber::process_image(const uint8_t * data)
|
||||
|
||||
ColorRgb & rgb = image(xDest, yDest);
|
||||
yuv2rgb(y, u, v, rgb.red, rgb.green, rgb.blue);
|
||||
noSignal &= rgb < _noSignalThresholdColor;
|
||||
}
|
||||
}
|
||||
|
||||
emit newFrame(image);
|
||||
if (noSignal)
|
||||
{
|
||||
++_noSignalCounter;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_noSignalCounter >= _noSignalCounterThreshold)
|
||||
{
|
||||
std::cout << "V4L2 Grabber: " << "Signal detected" << std::endl;
|
||||
}
|
||||
|
||||
_noSignalCounter = 0;
|
||||
}
|
||||
|
||||
if (_noSignalCounter < _noSignalCounterThreshold)
|
||||
{
|
||||
emit newFrame(image);
|
||||
}
|
||||
else if (_noSignalCounter == _noSignalCounterThreshold)
|
||||
{
|
||||
std::cout << "V4L2 Grabber: " << "Signal lost" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int V4L2Grabber::xioctl(int request, void *arg)
|
||||
|
@@ -11,22 +11,32 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
|
||||
int height,
|
||||
int frameDecimation,
|
||||
int pixelDecimation,
|
||||
double redSignalThreshold,
|
||||
double greenSignalThreshold,
|
||||
double blueSignalThreshold,
|
||||
Hyperion *hyperion,
|
||||
int hyperionPriority) :
|
||||
_timeout_ms(1000),
|
||||
_priority(hyperionPriority),
|
||||
_grabber(device,
|
||||
input,
|
||||
videoStandard,
|
||||
width,
|
||||
height,
|
||||
frameDecimation,
|
||||
pixelDecimation,
|
||||
pixelDecimation),
|
||||
input,
|
||||
videoStandard,
|
||||
width,
|
||||
height,
|
||||
frameDecimation,
|
||||
pixelDecimation,
|
||||
pixelDecimation),
|
||||
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_hyperion(hyperion),
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0})
|
||||
{
|
||||
// set the signal detection threshold of the grabber
|
||||
_grabber.setSignalThreshold(
|
||||
redSignalThreshold,
|
||||
greenSignalThreshold,
|
||||
blueSignalThreshold,
|
||||
50);
|
||||
|
||||
// register the image type
|
||||
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
|
||||
qRegisterMetaType<std::vector<ColorRgb>>("std::vector<ColorRgb>");
|
||||
@@ -71,8 +81,6 @@ void V4L2Wrapper::set3D(VideoMode mode)
|
||||
|
||||
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
|
||||
{
|
||||
// TODO: add a signal detector
|
||||
|
||||
// process the new image
|
||||
_processor->process(image, _ledColors);
|
||||
|
||||
|
Reference in New Issue
Block a user