mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Add support to set the threshold for each RGB channel separately
Former-commit-id: 5edb206bb2657e78f711f67625fd5f6164d8296c
This commit is contained in:
parent
4888294e03
commit
5e3cb497fa
@ -24,8 +24,7 @@ class V4L2Grabber : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
V4L2Grabber(
|
||||
const std::string & device,
|
||||
V4L2Grabber(const std::string & device,
|
||||
int input,
|
||||
VideoStandard videoStandard,
|
||||
int width,
|
||||
@ -43,6 +42,11 @@ public slots:
|
||||
|
||||
void set3D(VideoMode mode);
|
||||
|
||||
void setSignalThreshold(double redSignalThreshold,
|
||||
double greenSignalThreshold,
|
||||
double blueSignalThreshold,
|
||||
int noSignalCounterThreshold);
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
@ -110,10 +114,14 @@ private:
|
||||
int _frameDecimation;
|
||||
int _horizontalPixelDecimation;
|
||||
int _verticalPixelDecimation;
|
||||
int _noSignalCounterThreshold;
|
||||
|
||||
ColorRgb _noSignalThresholdColor;
|
||||
|
||||
VideoMode _mode3D;
|
||||
|
||||
int _currentFrame;
|
||||
int _noSignalCounter;
|
||||
|
||||
QSocketNotifier * _streamNotifier;
|
||||
};
|
||||
|
@ -19,6 +19,9 @@ public:
|
||||
int height,
|
||||
int frameDecimation,
|
||||
int pixelDecimation,
|
||||
double redSignalThreshold,
|
||||
double greenSignalThreshold,
|
||||
double blueSignalThreshold,
|
||||
Hyperion * hyperion,
|
||||
int hyperionPriority);
|
||||
virtual ~V4L2Wrapper();
|
||||
|
@ -48,3 +48,10 @@ inline std::ostream& operator<<(std::ostream& os, const ColorRgb& color)
|
||||
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
/// Compare operator to check if a color is 'smaller' than another color
|
||||
inline bool operator<(const ColorRgb & lhs, const ColorRgb & rhs)
|
||||
{
|
||||
return (lhs.red < rhs.red) && (lhs.green < rhs.green) && (lhs.blue < rhs.blue);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
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,6 +11,9 @@ 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),
|
||||
@ -27,6 +30,13 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
|
||||
_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);
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
// hyperion-v4l2 includes
|
||||
#include "ImageHandler.h"
|
||||
|
||||
ImageHandler::ImageHandler(const std::string & address, int priority, double signalThreshold, bool skipProtoReply) :
|
||||
ImageHandler::ImageHandler(const std::string & address, int priority, bool skipProtoReply) :
|
||||
_priority(priority),
|
||||
_connection(address),
|
||||
_signalThreshold(signalThreshold),
|
||||
_signalProcessor(100, 50, 0, uint8_t(std::min(255, std::max(0, int(255*signalThreshold)))))
|
||||
_connection(address)
|
||||
{
|
||||
_connection.setSkipReply(skipProtoReply);
|
||||
}
|
||||
@ -16,23 +14,5 @@ ImageHandler::~ImageHandler()
|
||||
|
||||
void ImageHandler::receiveImage(const Image<ColorRgb> & image)
|
||||
{
|
||||
// check if we should do signal detection
|
||||
if (_signalThreshold < 0)
|
||||
{
|
||||
_connection.setImage(image, _priority, 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_signalProcessor.process(image))
|
||||
{
|
||||
std::cout << "Signal state = " << (_signalProcessor.getCurrentBorder().unknown ? "off" : "on") << std::endl;
|
||||
}
|
||||
|
||||
// consider an unknown border as no signal
|
||||
// send the image to Hyperion if we have a signal
|
||||
if (!_signalProcessor.getCurrentBorder().unknown)
|
||||
{
|
||||
_connection.setImage(image, _priority, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,6 @@
|
||||
#include <utils/Image.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
// blackborder includes
|
||||
#include <blackborder/BlackBorderProcessor.h>
|
||||
|
||||
// hyperion v4l2 includes
|
||||
#include "ProtoConnection.h"
|
||||
|
||||
@ -17,7 +14,7 @@ class ImageHandler : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageHandler(const std::string & address, int priority, double signalThreshold, bool skipProtoReply);
|
||||
ImageHandler(const std::string & address, int priority, bool skipProtoReply);
|
||||
virtual ~ImageHandler();
|
||||
|
||||
public slots:
|
||||
@ -31,10 +28,4 @@ private:
|
||||
|
||||
/// Hyperion proto connection object
|
||||
ProtoConnection _connection;
|
||||
|
||||
/// Threshold used for signal detection
|
||||
double _signalThreshold;
|
||||
|
||||
/// Blackborder detector which is used as a signal detector (unknown border = no signal)
|
||||
hyperion::BlackBorderProcessor _signalProcessor;
|
||||
};
|
||||
|
@ -63,6 +63,9 @@ int main(int argc, char** argv)
|
||||
IntParameter & argFrameDecimation = parameters.add<IntParameter> ('f', "frame-decimator", "Decimation factor for the video frames [default=1]");
|
||||
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||
DoubleParameter & argSignalThreshold = parameters.add<DoubleParameter> ('t', "signal-threshold", "The signal threshold for detecting the presence of a signal. Value should be between 0.0 and 1.0.");
|
||||
DoubleParameter & argRedSignalThreshold = parameters.add<DoubleParameter> (0x0, "red-threshold", "The red signal threshold. Value should be between 0.0 and 1.0. (overrides --signal-threshold)");
|
||||
DoubleParameter & argGreenSignalThreshold = parameters.add<DoubleParameter> (0x0, "green-threshold", "The green signal threshold. Value should be between 0.0 and 1.0. (overrides --signal-threshold)");
|
||||
DoubleParameter & argBlueSignalThreshold = parameters.add<DoubleParameter> (0x0, "blue-threshold", "The blue signal threshold. Value should be between 0.0 and 1.0. (overrides --signal-threshold)");
|
||||
SwitchParameter<> & arg3DSBS = parameters.add<SwitchParameter<>> (0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side");
|
||||
SwitchParameter<> & arg3DTAB = parameters.add<SwitchParameter<>> (0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom");
|
||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
|
||||
@ -110,6 +113,13 @@ int main(int argc, char** argv)
|
||||
std::max(1, argSizeDecimation.getValue()),
|
||||
std::max(1, argSizeDecimation.getValue()));
|
||||
|
||||
// set signal detection
|
||||
grabber.setSignalThreshold(
|
||||
std::min(1.0, std::max(0.0, argRedSignalThreshold.isSet() ? argRedSignalThreshold.getValue() : argSignalThreshold.getValue())),
|
||||
std::min(1.0, std::max(0.0, argGreenSignalThreshold.isSet() ? argGreenSignalThreshold.getValue() : argSignalThreshold.getValue())),
|
||||
std::min(1.0, std::max(0.0, argBlueSignalThreshold.isSet() ? argBlueSignalThreshold.getValue() : argSignalThreshold.getValue())),
|
||||
50);
|
||||
|
||||
// set cropping values
|
||||
grabber.setCropping(
|
||||
std::max(0, argCropLeft.getValue()),
|
||||
@ -138,7 +148,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageHandler handler(argAddress.getValue(), argPriority.getValue(), argSignalThreshold.getValue(), argSkipReply.isSet());
|
||||
ImageHandler handler(argAddress.getValue(), argPriority.getValue(), argSkipReply.isSet());
|
||||
QObject::connect(&grabber, SIGNAL(newFrame(Image<ColorRgb>)), &handler, SLOT(receiveImage(Image<ColorRgb>)));
|
||||
grabber.start();
|
||||
QCoreApplication::exec();
|
||||
|
@ -184,6 +184,9 @@ int main(int argc, char** argv)
|
||||
grabberConfig.get("height", -1).asInt(),
|
||||
grabberConfig.get("frameDecimation", 2).asInt(),
|
||||
grabberConfig.get("sizeDecimation", 8).asInt(),
|
||||
grabberConfig.get("redSignalThreshold", 0.0).asDouble(),
|
||||
grabberConfig.get("greenSignalThreshold", 0.0).asDouble(),
|
||||
grabberConfig.get("blueSignalThreshold", 0.0).asDouble(),
|
||||
&hyperion,
|
||||
grabberConfig.get("priority", 800).asInt());
|
||||
v4l2Grabber->set3D(parse3DMode(grabberConfig.get("mode", "2D").asString()));
|
||||
|
Loading…
Reference in New Issue
Block a user