summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevron Rees <kevron.m.rees@intel.com>2014-12-19 14:14:29 -0800
committerKevron Rees <kevron.m.rees@intel.com>2014-12-19 14:14:50 -0800
commit2e2ff7dbe832911bf2843da5b4d3d7598d82341d (patch)
treea86d017c81af99597ed1daf521a7813fc1360c88
parent78acac75f5a56159d4bdb62c1645aa98992dc65d (diff)
downloadautomotive-message-broker-2e2ff7dbe832911bf2843da5b4d3d7598d82341d.tar.gz
fixed issues with OpenCV plugin
-rw-r--r--CMakeLists.txt2
-rw-r--r--examples/opencvdbusconfig.in2
-rw-r--r--plugins/common/ambpluginimpl.h13
-rw-r--r--plugins/opencvlux/CMakeLists.txt6
-rw-r--r--plugins/opencvlux/README30
-rw-r--r--plugins/opencvlux/opencvluxplugin.cpp163
-rw-r--r--plugins/opencvlux/opencvluxplugin.h33
7 files changed, 107 insertions, 142 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d62d3408..fbbc5afc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,7 @@ set(CMAKE_BUILD_TYPE, Debug)
include(FindPkgConfig)
set(PROJECT_NAME "automotive-message-broker")
-set(PROJECT_VERSION "0.12.900")
+set(PROJECT_VERSION "0.12.901")
set(PROJECT_CODENAME "agera")
set(PROJECT_QUALITY "beta")
diff --git a/examples/opencvdbusconfig.in b/examples/opencvdbusconfig.in
index 0040e1a5..7634c755 100644
--- a/examples/opencvdbusconfig.in
+++ b/examples/opencvdbusconfig.in
@@ -4,7 +4,7 @@
{
"name" : "OpenCV LUX",
"path" : "@PLUGIN_INSTALL_PATH@/opencvluxplugin.so",
- "threaded" : "false",
+ "threaded" : "true",
"opencl" : "true",
"fps" : "30",
"pixelLowerBound" : "18",
diff --git a/plugins/common/ambpluginimpl.h b/plugins/common/ambpluginimpl.h
index 070b6d10..d9482f0f 100644
--- a/plugins/common/ambpluginimpl.h
+++ b/plugins/common/ambpluginimpl.h
@@ -138,14 +138,23 @@ protected:
* \param zone Zone of the property to be found.
* \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype)
*/
- virtual AbstractPropertyType* findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone);
+ virtual AbstractPropertyType* findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone = Zone::None);
/*! Registers property in AMB
* \param zone Zone of the property to be registered.
* \param typeFactory Function to be used to create instance of the AbstractPropertyType for registered property
* \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype)
*/
- virtual std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory);
+ std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory);
+
+ template <class T>
+ std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone)
+ {
+ auto typeFactory = [](){
+ return new T;
+ };
+ return addPropertySupport(zone, typeFactory);
+ }
//
// data:
diff --git a/plugins/opencvlux/CMakeLists.txt b/plugins/opencvlux/CMakeLists.txt
index f7ef01c7..a4c6d852 100644
--- a/plugins/opencvlux/CMakeLists.txt
+++ b/plugins/opencvlux/CMakeLists.txt
@@ -46,15 +46,17 @@ if(Qt5Core_FOUND)
endif(Qt5Core_FOUND)
set(CMAKE_AUTOMOC ON)
-include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${QT_INCLUDE_DIRS})
+include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${QT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/plugins/common)
set(opencvluxplugin_headers opencvluxplugin.h)
set(opencvluxplugin_sources opencvluxplugin.cpp)
add_library(opencvluxplugin MODULE ${opencvluxplugin_sources})
set_target_properties(opencvluxplugin PROPERTIES PREFIX "")
-target_link_libraries(opencvluxplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${OpenCV_LIBS} ${Boost_LIBRARIES} ${QT_LIBRARIES})
+target_link_libraries(opencvluxplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${OpenCV_LIBS} ${Boost_LIBRARIES} ${QT_LIBRARIES} amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common)
install(TARGETS opencvluxplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH})
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README ${CMAKE_CURRENT_SOURCE_DIR}/README @ONLY)
+
endif(opencvlux_plugin)
diff --git a/plugins/opencvlux/README b/plugins/opencvlux/README
index f8db1d2f..d182c32d 100644
--- a/plugins/opencvlux/README
+++ b/plugins/opencvlux/README
@@ -1,6 +1,7 @@
OpenCV "lux" plugin
+Version: @PROJECT_VERSION@
-This plugin simulates the ExteriorBrigtness property using a traditional webcamera. It works
+This plugin simulates the ExteriorBrigtness property using a traditional webcamera. It works
by taking the mean pixel intensity of the web camera image and estimating lux. The particular
can be calibrated using the "pixelUpperBound" and "pixelLowerBound" variables.
@@ -13,14 +14,14 @@ Currently, this plugin has been tested with OpenCV 2.4.4.
To use the OpenCV plugin, add the following to the "sources" array in /etc/ambd/config:
{
- "name" : "OpenCV LUX",
- "path" : "/usr/lib/automotive-message-broker/opencvluxplugin.so",
- "threaded" : "true",
- "pixelLowerBound" : "0",
- "pixelUpperBound" : "255",
- "fps" : "30",
- "opencl" : "false",
- "device" : "0"
+ "name" : "OpenCV LUX",
+ "path" : "/usr/lib/automotive-message-broker/opencvluxplugin.so",
+ "threaded" : "true",
+ "pixelLowerBound" : "0",
+ "pixelUpperBound" : "255",
+ "fps" : "30",
+ "opencl" : "false",
+ "device" : "0"
}
NOTE: some features require the qtmainloop to be running. see the main README for details.
@@ -50,13 +51,13 @@ How many times per second to poll image data from the camera.
Default: "30"
"pixelLowerBound"
-Lowest calibration value for a camera. This is the average pixel intensity value the camera reports when
+Lowest calibration value for a camera. This is the average pixel intensity value the camera reports when
it is completely covered.
Default: "0"
"pixelUpperBound"
-The highest calibration value for camera. This is the average pixel intensity value when a very bright
+The highest calibration value for camera. This is the average pixel intensity value when a very bright
light (like the sun) is being projected at the camera.
Default: "255"
@@ -89,16 +90,19 @@ open or closed. If closed for a period of time, DriverDrowsiness will change to
Default: "false"
-AMB Properties:
+Properties:
VideoLogging
Turn on and off video logging
-
Type: bool
Access: readwrite
DriverDrowsiness
True if the driver has been detected drowsy.
+Type: bool
+Access: readonly
+OpenCL
+True if OpenCL acceleration is enabled.
Type: bool
Access: readonly
diff --git a/plugins/opencvlux/opencvluxplugin.cpp b/plugins/opencvlux/opencvluxplugin.cpp
index ea4f2e12..c23ec775 100644
--- a/plugins/opencvlux/opencvluxplugin.cpp
+++ b/plugins/opencvlux/opencvluxplugin.cpp
@@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "timestamp.h"
#include <listplusplus.h>
#include <superptr.hpp>
+#include <ambplugin.h>
#include <iostream>
#include <thread>
@@ -45,26 +46,28 @@ const std::string OpenCL = "OpenCL";
extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
{
- VehicleProperty::registerProperty(VideoLogging, [](){
+ auto plugin = new AmbPlugin<OpenCvLuxPlugin>(routingengine, config);
+ plugin->init();
+
+ return plugin;
+}
+
+OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config, AbstractSource &parent)
+ :AmbPluginImpl(re, config, parent), lastLux(0), speed(0), latitude(0), longitude(0)
+{
+ videoLogging = addPropertySupport(Zone::None, [](){
return new BasicPropertyType<bool>(VideoLogging, false);
});
- VehicleProperty::registerProperty(DriverDrowsiness, [](){
+ driverDrowsiness = addPropertySupport(Zone::None, [](){
return new OpenCvLuxPlugin::DriverDrowsinessType(DriverDrowsiness, false);
});
- VehicleProperty::registerProperty(OpenCL, [](){
+ openCl = addPropertySupport(Zone::None, [](){
return new BasicPropertyType<bool>(OpenCL, false);
});
- return new OpenCvLuxPlugin(routingengine, config);
-}
-
-OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config)
- :AbstractSource(re, config), lastLux(0), speed(0), latitude(0), longitude(0), extBrightness(new VehicleProperty::ExteriorBrightnessType(0))
-{
- driverDrowsiness = amb::make_unique(new DriverDrowsinessType(DriverDrowsiness, false));
- openCl = amb::make_unique(new BasicPropertyType<bool>(OpenCL, false));
+ extBrightness = addPropertySupport<VehicleProperty::ExteriorBrightnessType>(Zone::None);
shared = amb::make_unique(new Shared);
shared->parent = this;
@@ -131,7 +134,9 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string>
openCl->setValue(cv::ocl::useOpenCL());
}
else
+ {
DebugOut(DebugOut::Warning) << "You really don't have openCL support." << endl;
+ }
}
if(config.find("ddd") != config.end())
@@ -167,9 +172,9 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string>
}
- routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
- routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
- routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
+ routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, &parent);
+ routingEngine->subscribeToProperty(VehicleProperty::Latitude, &parent);
+ routingEngine->subscribeToProperty(VehicleProperty::Longitude, &parent);
}
OpenCvLuxPlugin::~OpenCvLuxPlugin()
@@ -177,7 +182,7 @@ OpenCvLuxPlugin::~OpenCvLuxPlugin()
}
-const string OpenCvLuxPlugin::uuid()
+const string OpenCvLuxPlugin::uuid() const
{
return "3c7a1ea0-7d2e-11e2-9e96-0800200c9a66";
}
@@ -192,28 +197,11 @@ void OpenCvLuxPlugin::getPropertyAsync(AsyncPropertyReply *reply)
{
/// we want to turn on the camera for one shot to get an image and determine the intensity
- if(init())
- grabImage(shared.get());
+ init();
+ grabImage(shared.get());
}
- if(reply->property == VehicleProperty::ExteriorBrightness)
- {
- replyQueue.push_back(reply);
- }
- else if(reply->property == VideoLogging)
- {
- BasicPropertyType<bool> tmp(VideoLogging, shared->loggingOn);
- reply->value = &tmp;
- reply->success = true;
- reply->completed(reply);
- }
- else ///We don't support what you are asking for. Reply false
- {
- reply->value = nullptr;
- reply->success = false;
- reply->error = AsyncPropertyReply::InvalidOperation;
- reply->completed(reply);
- }
+ AmbPluginImpl::getPropertyAsync(reply);
}
void OpenCvLuxPlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
@@ -223,29 +211,25 @@ void OpenCvLuxPlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
AsyncPropertyReply *OpenCvLuxPlugin::setProperty(AsyncSetPropertyRequest request )
{
- AsyncPropertyReply *reply = new AsyncPropertyReply(request);
-
- reply->success = false;
- reply->error = AsyncPropertyReply::InvalidOperation;
-
if(request.property == VideoLogging)
{
shared->loggingOn = request.value->value<bool>();
- reply->success = true;
- reply->error = AsyncPropertyReply::NoError;
+ }
+ if(request.property == OpenCL)
+ {
+ QMutexLocker lock(&mutex);
+ cv::ocl::setUseOpenCL(request.value->value<bool>());
}
- reply->completed(reply);
-
- return reply;
+ return AmbPluginImpl::setProperty(request);;
}
void OpenCvLuxPlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
{
if(!shared->mRequests.size())
{
- if(init())
- g_timeout_add(1000 / shared->fps, grabImage, shared.get());
+ init();
+ g_timeout_add(1000 / shared->fps, grabImage, shared.get());
}
shared->mRequests.push_back(property);
@@ -256,21 +240,6 @@ void OpenCvLuxPlugin::unsubscribeToPropertyChanges(VehicleProperty::Property pro
removeOne(&shared->mRequests,property);
}
-PropertyList OpenCvLuxPlugin::supported()
-{
- PropertyList props;
- props.push_back(VehicleProperty::ExteriorBrightness);
- props.push_back(DriverDrowsiness);
- props.push_back(VideoLogging);
-
- return props;
-}
-
-int OpenCvLuxPlugin::supportedOperations()
-{
- return Get | Set;
-}
-
void OpenCvLuxPlugin::propertyChanged(AbstractPropertyType *value)
{
QMutexLocker lock(&mutex);
@@ -326,7 +295,7 @@ static int grabImage(void *data)
}
}
- /*if(shared->threaded)
+ if(shared->threaded)
{
QFutureWatcher<uint> *watcher = new QFutureWatcher<uint>();
QObject::connect(watcher, &QFutureWatcher<uint>::finished, shared->parent, &OpenCvLuxPlugin::imgProcResult);
@@ -338,10 +307,11 @@ static int grabImage(void *data)
}
else
{
- shared->parent->writeVideoFrame(m_image);
+ if(shared->parent->videoLogging->value<bool>())
+ shared->parent->writeVideoFrame(m_image);
try
{
- int lux = evalImage(m_image, shared);
+ uint16_t lux = evalImage(m_image, shared);
shared->parent->updateProperty(lux);
}
catch(...)
@@ -350,7 +320,7 @@ static int grabImage(void *data)
}
//detectLight(m_image,shared);
- }*/
+ }
if(shared->mRequests.size())
{
@@ -386,7 +356,7 @@ static uint evalImage(cv::UMat qImg, OpenCvLuxPlugin::Shared *shared)
}
-bool OpenCvLuxPlugin::init()
+void OpenCvLuxPlugin::init()
{
if(!shared->m_capture)
{
@@ -398,13 +368,11 @@ bool OpenCvLuxPlugin::init()
if(!shared->m_capture->isOpened())
{
- DebugOut()<<"we failed to open camera device ("<<device<<") or no camera found"<<endl;
- return false;
+ DebugOut() << "we failed to open camera device (" << device << ") or no camera found" << endl;
+ return;
}
- if(configuration.find("logging") != configuration.end() &&
- configuration["logging"] == "true" &&
- (!shared->mWriter || !shared->mWriter->isOpened()))
+ if(!shared->mWriter || !shared->mWriter->isOpened())
{
cv::Size s = cv::Size((int) shared->m_capture->get(cv::CAP_PROP_FRAME_WIDTH),
(int) shared->m_capture->get(cv::CAP_PROP_FRAME_HEIGHT));
@@ -413,7 +381,7 @@ bool OpenCvLuxPlugin::init()
if(codec.empty() || codec.size() != 4)
{
- DebugOut(DebugOut::Warning)<<"Invalid codec. Using default: MJPG"<<endl;
+ DebugOut(DebugOut::Warning)<<"Invalid codec: "<<codec <<". Using default: MJPG"<<endl;
codec = "MJPG";
}
@@ -430,7 +398,7 @@ bool OpenCvLuxPlugin::init()
DebugOut()<<"camera frame height: "<<shared->m_capture->get(cv::CAP_PROP_FRAME_HEIGHT)<<endl;
DebugOut()<<"camera frame fps: "<<shared->m_capture->get(cv::CAP_PROP_FPS)<<endl;
- return true;
+ return;
}
@@ -485,33 +453,15 @@ void OpenCvLuxPlugin::writeVideoFrame(cv::UMat f)
}
}
-void OpenCvLuxPlugin::updateProperty(uint lux)
+void OpenCvLuxPlugin::updateProperty(uint16_t lux)
{
- extBrightness->setValue(lux);
-
- for(auto reply : replyQueue)
- {
- reply->value = extBrightness.get();
- reply->success = true;
- try{
- if(reply->completed)
- reply->completed(reply);
- }
- catch(...)
- {
- DebugOut(DebugOut::Warning)<<"reply failed"<<endl;
- }
- }
-
- replyQueue.clear();
+ extBrightness->setValue(lux);
if(lux != lastLux && shared->mRequests.size())
{
lastLux = lux;
routingEngine->updateProperty(extBrightness.get(), uuid());
}
-
-
}
void OpenCvLuxPlugin::imgProcResult()
@@ -531,10 +481,10 @@ void OpenCvLuxPlugin::imgProcResult()
}
}
-TrafficLight::Color detectLight(cv::Mat img, OpenCvLuxPlugin::Shared *shared)
+TrafficLight::Color detectLight(cv::UMat img, OpenCvLuxPlugin::Shared *shared)
{
- cv::Mat gray;
+ cv::UMat gray;
cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(gray, gray, cv::Size(9,9), 2, 2);
@@ -554,11 +504,11 @@ TrafficLight::Color detectLight(cv::Mat img, OpenCvLuxPlugin::Shared *shared)
try {
- cv::Mat light(img, rect);
+ cv::UMat light(img, rect);
- cv::circle( img, center, radius, cv::Scalar(0,0,255), 3, 8, 0 );
+ cv::circle(img, center, radius, cv::Scalar(0,0,255), 3, 8, 0 );
- cv::rectangle(img, rect,cv::Scalar(255,0,0));
+ cv::rectangle(img, rect.tl(), rect.br(), cv::Scalar(255,0,0));
cv::Scalar avgPixel = cv::mean(light);
@@ -624,14 +574,19 @@ void OpenCvLuxPlugin::detectEyes(cv::UMat frame)
hasEyes = true;
DebugOut() << "Number of eyes: " << eyes.size() << endl;
- driverDrowsiness->setValue(false);
- routingEngine->updateProperty(driverDrowsiness.get(), this->uuid());
+ if(driverDrowsiness->value<bool>())
+ {
+ driverDrowsiness->setValue(false);
+ routingEngine->updateProperty(driverDrowsiness.get(), this->uuid());
+ }
}
else
{
- DebugOut() << "No eyes!!!" << endl;
- driverDrowsiness->setValue(true);
- routingEngine->updateProperty(driverDrowsiness.get(), this->uuid());
+ if(!driverDrowsiness->value<bool>())
+ {
+ driverDrowsiness->setValue(true);
+ routingEngine->updateProperty(driverDrowsiness.get(), this->uuid());
+ }
}
}
}
diff --git a/plugins/opencvlux/opencvluxplugin.h b/plugins/opencvlux/opencvluxplugin.h
index 550a9fb9..aecd08e2 100644
--- a/plugins/opencvlux/opencvluxplugin.h
+++ b/plugins/opencvlux/opencvluxplugin.h
@@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#define OPENCVLUXPLUGIN_H
#include <abstractsource.h>
+#include <ambpluginimpl.h>
#include <string>
#include <memory>
@@ -31,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
using namespace std;
-class OpenCvLuxPlugin: public QObject, public AbstractSource
+class OpenCvLuxPlugin: public QObject, public AmbPluginImpl
{
Q_OBJECT
public:
@@ -57,40 +58,35 @@ public:
int frameCount;
};
- OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config);
+ OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config, AbstractSource& parent);
~OpenCvLuxPlugin();
- const string uuid();
+ const string uuid() const;
void getPropertyAsync(AsyncPropertyReply *reply);
void getRangePropertyAsync(AsyncRangePropertyReply *reply);
AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
void subscribeToPropertyChanges(VehicleProperty::Property property);
void unsubscribeToPropertyChanges(VehicleProperty::Property property);
- PropertyList supported();
-
- int supportedOperations();
void propertyChanged(AbstractPropertyType* value);
void supportedChanged(const PropertyList &);
- void updateProperty(uint lux);
+ void updateProperty(uint16_t lux);
void writeVideoFrame(cv::UMat frame);
void detectEyes(cv::UMat frame);
-public Q_SLOTS:
- void imgProcResult();
+ void init();
+ std::shared_ptr<AbstractPropertyType> videoLogging;
-private: /// methods:
- bool init();
+public Q_SLOTS:
+ void imgProcResult();
private:
-
-
uint speed;
uint latitude;
uint longitude;
@@ -99,7 +95,7 @@ private:
std::string device;
std::list<AsyncPropertyReply*> replyQueue;
- std::unique_ptr<VehicleProperty::ExteriorBrightnessType> extBrightness;
+ std::shared_ptr<AbstractPropertyType> extBrightness;
std::unique_ptr<Shared> shared;
QMutex mutex;
@@ -107,13 +103,12 @@ private:
std::unique_ptr<cv::CascadeClassifier> faceCascade;
std::unique_ptr<cv::CascadeClassifier> eyeCascade;
- std::unique_ptr<DriverDrowsinessType> driverDrowsiness;
-
- std::unique_ptr<BasicPropertyType<bool>> openCl;
+ std::shared_ptr<AbstractPropertyType> driverDrowsiness;
+ std::shared_ptr<AbstractPropertyType> openCl;
};
static int grabImage(void *data);
-static uint evalImage(cv::Mat qImg, OpenCvLuxPlugin::Shared *shared);
+static uint evalImage(cv::UMat qImg, OpenCvLuxPlugin::Shared *shared);
namespace TrafficLight
{
@@ -126,7 +121,7 @@ enum Color
};
}
-TrafficLight::Color detectLight(cv::Mat img, OpenCvLuxPlugin::Shared* shared);
+TrafficLight::Color detectLight(cv::UMat img, OpenCvLuxPlugin::Shared* shared);
#endif // EXAMPLEPLUGIN_H