mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added signal detection option
Former-commit-id: 1bd70d02814d6238c488db765d9d25af655c1872
This commit is contained in:
parent
f5317bc2d9
commit
305a2e856a
@ -120,7 +120,7 @@ void OptionsParser::usage() const {
|
|||||||
for(i = parameters.parameters.begin();
|
for(i = parameters.parameters.begin();
|
||||||
i != parameters.parameters.end(); i++)
|
i != parameters.parameters.end(); i++)
|
||||||
{
|
{
|
||||||
cerr.width(31);
|
cerr.width(33);
|
||||||
cerr << std::left << " " + (*i)->usageLine();
|
cerr << std::left << " " + (*i)->usageLine();
|
||||||
|
|
||||||
cerr.width(40);
|
cerr.width(40);
|
||||||
|
@ -17,12 +17,15 @@ include_directories(
|
|||||||
set(Hyperion_V4L2_HEADERS
|
set(Hyperion_V4L2_HEADERS
|
||||||
V4L2Grabber.h
|
V4L2Grabber.h
|
||||||
ProtoConnection.h
|
ProtoConnection.h
|
||||||
|
ImageHandler.h
|
||||||
|
VideoStandardParameter.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(Hyperion_V4L2_SOURCES
|
set(Hyperion_V4L2_SOURCES
|
||||||
hyperion-v4l2.cpp
|
hyperion-v4l2.cpp
|
||||||
V4L2Grabber.cpp
|
V4L2Grabber.cpp
|
||||||
ProtoConnection.cpp
|
ProtoConnection.cpp
|
||||||
|
ImageHandler.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(Hyperion_V4L2_PROTOS
|
set(Hyperion_V4L2_PROTOS
|
||||||
@ -42,6 +45,7 @@ add_executable(hyperion-v4l2
|
|||||||
|
|
||||||
target_link_libraries(hyperion-v4l2
|
target_link_libraries(hyperion-v4l2
|
||||||
getoptPlusPlus
|
getoptPlusPlus
|
||||||
|
blackborder
|
||||||
hyperion-utils
|
hyperion-utils
|
||||||
${PROTOBUF_LIBRARIES}
|
${PROTOBUF_LIBRARIES}
|
||||||
pthread
|
pthread
|
||||||
|
41
src/hyperion-v4l2/ImageHandler.cpp
Normal file
41
src/hyperion-v4l2/ImageHandler.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// hyperion-v4l2 includes
|
||||||
|
#include "ImageHandler.h"
|
||||||
|
|
||||||
|
ImageHandler::ImageHandler(const std::string &address, int priority, double signalThreshold, bool skipProtoReply) :
|
||||||
|
_priority(priority),
|
||||||
|
_connection(address),
|
||||||
|
_signalThreshold(signalThreshold),
|
||||||
|
_signalProcessor(100, 50, 0, uint8_t(std::min(255, std::max(0, int(255*signalThreshold)))))
|
||||||
|
{
|
||||||
|
_connection.setSkipReply(skipProtoReply);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageHandler::receiveImage(const Image<ColorRgb> &image)
|
||||||
|
{
|
||||||
|
// check if we should do signal detection
|
||||||
|
if (_signalThreshold < 0)
|
||||||
|
{
|
||||||
|
_connection.setImage(image, _priority, 200);
|
||||||
|
}
|
||||||
|
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, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageHandler::imageCallback(void *arg, const Image<ColorRgb> &image)
|
||||||
|
{
|
||||||
|
ImageHandler * handler = static_cast<ImageHandler *>(arg);
|
||||||
|
handler->receiveImage(image);
|
||||||
|
}
|
||||||
|
|
34
src/hyperion-v4l2/ImageHandler.h
Normal file
34
src/hyperion-v4l2/ImageHandler.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// blackborder includes
|
||||||
|
#include <blackborder/BlackBorderProcessor.h>
|
||||||
|
|
||||||
|
// hyperion-v4l includes
|
||||||
|
#include "ProtoConnection.h"
|
||||||
|
|
||||||
|
/// This class handles callbacks from the V4L2 grabber
|
||||||
|
class ImageHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ImageHandler(const std::string & address, int priority, double signalThreshold, bool skipProtoReply);
|
||||||
|
|
||||||
|
/// Handle a single image
|
||||||
|
/// @param image The image to process
|
||||||
|
void receiveImage(const Image<ColorRgb> & image);
|
||||||
|
|
||||||
|
/// static function used to direct callbacks to a ImageHandler object
|
||||||
|
/// @param arg This should be an ImageHandler instance
|
||||||
|
/// @param image The image to process
|
||||||
|
static void imageCallback(void * arg, const Image<ColorRgb> & image);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// Priority for calls to Hyperion
|
||||||
|
const int _priority;
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
};
|
36
src/hyperion-v4l2/VideoStandardParameter.h
Normal file
36
src/hyperion-v4l2/VideoStandardParameter.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// getoptPlusPLus includes
|
||||||
|
#include <getoptPlusPlus/getoptpp.h>
|
||||||
|
|
||||||
|
using namespace vlofgren;
|
||||||
|
|
||||||
|
/// Data parameter for the video standard
|
||||||
|
typedef vlofgren::PODParameter<V4L2Grabber::VideoStandard> VideoStandardParameter;
|
||||||
|
|
||||||
|
namespace vlofgren {
|
||||||
|
/// Translates a string (as passed on the commandline) to a color standard
|
||||||
|
///
|
||||||
|
/// @param[in] s The string (as passed on the commandline)
|
||||||
|
/// @return The color standard
|
||||||
|
/// @throws Parameter::ParameterRejected If the string did not result in a video standard
|
||||||
|
template<>
|
||||||
|
V4L2Grabber::VideoStandard VideoStandardParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
|
||||||
|
{
|
||||||
|
QString input = QString::fromStdString(s).toLower();
|
||||||
|
|
||||||
|
if (input == "pal")
|
||||||
|
{
|
||||||
|
return V4L2Grabber::PAL;
|
||||||
|
}
|
||||||
|
else if (input == "ntsc")
|
||||||
|
{
|
||||||
|
return V4L2Grabber::NTSC;
|
||||||
|
}
|
||||||
|
else if (input == "no-change")
|
||||||
|
{
|
||||||
|
return V4L2Grabber::NO_CHANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw Parameter::ParameterRejected("Invalid value for video standard. Valid values are: PAL, NTSC, and NO-CHANGE");
|
||||||
|
return V4L2Grabber::NO_CHANGE;
|
||||||
|
}
|
||||||
|
}
|
@ -9,43 +9,17 @@
|
|||||||
// getoptPlusPLus includes
|
// getoptPlusPLus includes
|
||||||
#include <getoptPlusPlus/getoptpp.h>
|
#include <getoptPlusPlus/getoptpp.h>
|
||||||
|
|
||||||
|
// blackborder includes
|
||||||
|
#include <blackborder/BlackBorderProcessor.h>
|
||||||
|
|
||||||
|
// hyperion-v4l2 includes
|
||||||
#include "V4L2Grabber.h"
|
#include "V4L2Grabber.h"
|
||||||
#include "ProtoConnection.h"
|
#include "ProtoConnection.h"
|
||||||
|
#include "VideoStandardParameter.h"
|
||||||
|
#include "ImageHandler.h"
|
||||||
|
|
||||||
using namespace vlofgren;
|
using namespace vlofgren;
|
||||||
|
|
||||||
/// Data parameter for the video standard
|
|
||||||
typedef vlofgren::PODParameter<V4L2Grabber::VideoStandard> VideoStandardParameter;
|
|
||||||
|
|
||||||
namespace vlofgren {
|
|
||||||
/// Translates a string (as passed on the commandline) to a color standard
|
|
||||||
///
|
|
||||||
/// @param[in] s The string (as passed on the commandline)
|
|
||||||
/// @return The color standard
|
|
||||||
/// @throws Parameter::ParameterRejected If the string did not result in a video standard
|
|
||||||
template<>
|
|
||||||
V4L2Grabber::VideoStandard VideoStandardParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
|
|
||||||
{
|
|
||||||
QString input = QString::fromStdString(s).toLower();
|
|
||||||
|
|
||||||
if (input == "pal")
|
|
||||||
{
|
|
||||||
return V4L2Grabber::PAL;
|
|
||||||
}
|
|
||||||
else if (input == "ntsc")
|
|
||||||
{
|
|
||||||
return V4L2Grabber::NTSC;
|
|
||||||
}
|
|
||||||
else if (input == "no-change")
|
|
||||||
{
|
|
||||||
return V4L2Grabber::NO_CHANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw Parameter::ParameterRejected("Invalid value for video standard. Valid values are: PAL, NTSC, and NO-CHANGE");
|
|
||||||
return V4L2Grabber::NO_CHANGE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// save the image as screenshot
|
// save the image as screenshot
|
||||||
void saveScreenshot(void *, const Image<ColorRgb> & image)
|
void saveScreenshot(void *, const Image<ColorRgb> & image)
|
||||||
{
|
{
|
||||||
@ -54,13 +28,6 @@ void saveScreenshot(void *, const Image<ColorRgb> & image)
|
|||||||
pngImage.save("screenshot.png");
|
pngImage.save("screenshot.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
// send the image to Hyperion
|
|
||||||
void sendImage(void * arg, const Image<ColorRgb> & image)
|
|
||||||
{
|
|
||||||
ProtoConnection * connection = static_cast<ProtoConnection *>(arg);
|
|
||||||
connection->setImage(image, 50, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -69,20 +36,21 @@ int main(int argc, char** argv)
|
|||||||
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
|
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
|
||||||
ParameterSet & parameters = optionParser.getParameters();
|
ParameterSet & parameters = optionParser.getParameters();
|
||||||
|
|
||||||
StringParameter & argDevice = parameters.add<StringParameter> ('d', "device", "The device to use [default=/dev/video0]");
|
StringParameter & argDevice = parameters.add<StringParameter> ('d', "device", "The device to use [default=/dev/video0]");
|
||||||
VideoStandardParameter & argVideoStandard = parameters.add<VideoStandardParameter>('v', "video-standard", "The used video standard. Valid values are PAL. NYSC, or NO-CHANGE [default=PAL]");
|
VideoStandardParameter & argVideoStandard = parameters.add<VideoStandardParameter>('v', "video-standard", "The used video standard. Valid values are PAL. NYSC, or NO-CHANGE [default=PAL]");
|
||||||
IntParameter & argInput = parameters.add<IntParameter> (0x0, "input", "Input channel (optional)");
|
IntParameter & argInput = parameters.add<IntParameter> (0x0, "input", "Input channel (optional)");
|
||||||
IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "Try to set the width of the video input (optional)");
|
IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "Try to set the width of the video input (optional)");
|
||||||
IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "Try to set the height of the video input (optional)");
|
IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "Try to set the height of the video input (optional)");
|
||||||
IntParameter & argCropWidth = parameters.add<IntParameter> (0x0, "crop-width", "Number of pixels to crop from the left and right sides in the picture before decimation [default=0]");
|
IntParameter & argCropWidth = parameters.add<IntParameter> (0x0, "crop-width", "Number of pixels to crop from the left and right sides in the picture before decimation [default=0]");
|
||||||
IntParameter & argCropHeight = parameters.add<IntParameter> (0x0, "crop-height", "Number of pixels to crop from the top and the bottom in the picture before decimation [default=0]");
|
IntParameter & argCropHeight = parameters.add<IntParameter> (0x0, "crop-height", "Number of pixels to crop from the top and the bottom in the picture before decimation [default=0]");
|
||||||
IntParameter & argSizeDecimation = parameters.add<IntParameter> ('s', "size-decimator", "Decimation factor for the output size [default=1]");
|
IntParameter & argSizeDecimation = parameters.add<IntParameter> ('s', "size-decimator", "Decimation factor for the output size [default=1]");
|
||||||
IntParameter & argFrameDecimation = parameters.add<IntParameter> ('f', "frame-decimator","Decimation factor for the video frames [default=1]");
|
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");
|
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
|
||||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
|
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.");
|
||||||
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
|
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]");
|
||||||
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]");
|
||||||
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit");
|
SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion");
|
||||||
|
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit");
|
||||||
|
|
||||||
// set defaults
|
// set defaults
|
||||||
argDevice.setDefault("/dev/video0");
|
argDevice.setDefault("/dev/video0");
|
||||||
@ -96,6 +64,7 @@ int main(int argc, char** argv)
|
|||||||
argFrameDecimation.setDefault(1);
|
argFrameDecimation.setDefault(1);
|
||||||
argAddress.setDefault("127.0.0.1:19445");
|
argAddress.setDefault("127.0.0.1:19445");
|
||||||
argPriority.setDefault(800);
|
argPriority.setDefault(800);
|
||||||
|
argSignalThreshold.setDefault(-1);
|
||||||
|
|
||||||
// parse all options
|
// parse all options
|
||||||
optionParser.parse(argc, const_cast<const char **>(argv));
|
optionParser.parse(argc, const_cast<const char **>(argv));
|
||||||
@ -126,10 +95,8 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ProtoConnection connection(argAddress.getValue());
|
ImageHandler handler(argAddress.getValue(), argPriority.getValue(), argSignalThreshold.getValue(), argSkipReply.isSet());
|
||||||
connection.setSkipReply(argSkipReply.isSet());
|
grabber.setCallback(&ImageHandler::imageCallback, &handler);
|
||||||
|
|
||||||
grabber.setCallback(&sendImage, &connection);
|
|
||||||
grabber.capture();
|
grabber.capture();
|
||||||
}
|
}
|
||||||
grabber.stop();
|
grabber.stop();
|
||||||
|
Loading…
Reference in New Issue
Block a user