Add support to set the threshold for each RGB channel separately

Former-commit-id: 5edb206bb2657e78f711f67625fd5f6164d8296c
This commit is contained in:
johan
2014-03-04 22:04:15 +01:00
parent 4888294e03
commit 5e3cb497fa
9 changed files with 92 additions and 48 deletions

View File

@@ -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);
}
}
_connection.setImage(image, _priority, 1000);
}

View File

@@ -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;
};

View File

@@ -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();

View File

@@ -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()));