Added image handler to v4l2 grabber to send colors to Hyperion

Former-commit-id: be6fb4dd8080b3325ba6161f48c093f8a145786d
This commit is contained in:
johan
2014-02-23 22:39:23 +01:00
parent e58f84d5c8
commit 99fd50805c
5 changed files with 135 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/v4l2)
SET(V4L2_QT_HEADERS
${CURRENT_HEADER_DIR}/V4L2Grabber.h
${CURRENT_HEADER_DIR}/V4L2Wrapper.h
)
SET(V4L2_HEADERS
@@ -12,6 +13,7 @@ SET(V4L2_HEADERS
SET(V4L2_SOURCES
${CURRENT_SOURCE_DIR}/V4L2Grabber.cpp
${CURRENT_SOURCE_DIR}/V4L2Wrapper.cpp
)
QT4_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})

View File

@@ -0,0 +1,67 @@
#include <grabber/V4L2Wrapper.h>
#include <hyperion/ImageProcessorFactory.h>
V4L2Wrapper::V4L2Wrapper(const std::string &device,
int input,
VideoStandard videoStandard,
int width,
int height,
int frameDecimation,
int pixelDecimation,
Hyperion *hyperion,
int hyperionPriority) :
_timeout_ms(1000),
_priority(hyperionPriority),
_grabber(device,
input,
videoStandard,
width,
height,
frameDecimation,
pixelDecimation,
pixelDecimation),
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
_hyperion(hyperion),
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0})
{
// connect the new frame signal using a queued connection, because it will be called from a different thread
QObject::connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::QueuedConnection);
}
V4L2Wrapper::~V4L2Wrapper()
{
delete _processor;
}
void V4L2Wrapper::start()
{
_grabber.start();
}
void V4L2Wrapper::stop()
{
_grabber.stop();
}
void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
{
_grabber.setCropping(cropLeft, cropRight, cropTop, cropBottom);
}
void V4L2Wrapper::set3D(VideoMode mode)
{
_grabber.set3D(mode);
}
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
{
// TODO: add a signal detector
// process the new image
_processor->process(image, _ledColors);
// send colors to Hyperion
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
}