From fdbaa9a5e0f2716835dc7e45b192fea4f2c24da3 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Wed, 6 Mar 2013 14:14:10 -0800 Subject: [PATCH] removed qt from opencv plugin --- CMakeLists.txt | 15 +-- lib/CMakeLists.txt | 15 ++- lib/automotive-message-broker.pc.in | 4 +- plugins/opencvlux/CMakeLists.txt | 8 +- plugins/opencvlux/opencvluxplugin.cpp | 142 ++++++++++------------ plugins/opencvlux/opencvluxplugin.h | 50 ++++---- plugins/websocketsourceplugin/websocketsource.cpp | 10 +- 7 files changed, 118 insertions(+), 126 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9123046..1d38fd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,6 @@ option(opencvlux_plugin "OpenCV Lux plugin" OFF) if(opencvlux_plugin) message(STATUS "OpenCV Lux plugin enabled") - set(use_qtcore ON) endif(opencvlux_plugin) @@ -51,16 +50,6 @@ else(libtool_LIBRARY) message(FATAL_ERROR "libtool missing. please install libtool") endif(libtool_LIBRARY) -find_library(uuid_LIBRARY uuid DOC "Uuid libraries") -find_path(uuid_INCLUDE_DIR uuid/uuid.h DOC "Libtool headers") - -if(uuid_LIBRARY) - message(STATUS "uuid found") -else(uuid_LIBRARY) - message(FATAL_ERROR "uuid missing. please install uuid-dev") -endif(uuid_LIBRARY) - - find_package(Boost REQUIRED) pkg_check_modules(glib REQUIRED glib-2.0) @@ -69,8 +58,8 @@ pkg_check_modules(json REQUIRED json-glib-1.0) add_definitions(-std=c++0x) add_definitions(-DDBusServiceName="org.automotive.message.broker") -set(include_dirs ${libtool_INCLUDE_DIR} ${glib_INCLUDE_DIRS} ${gio_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${json_INCLUDE_DIRS} ${uuid_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib) -set(link_libraries -lamb ${libtool_LIBRARY} ${glib_LIBRARIES} ${json_LIBRARIES} ${uuid_LIBRARY} -L${CMAKE_CURRENT_BINARY_DIR}/lib) +set(include_dirs ${libtool_INCLUDE_DIR} ${glib_INCLUDE_DIRS} ${gio_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${json_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib) +set(link_libraries -lamb ${libtool_LIBRARY} ${glib_LIBRARIES} ${json_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib) if(use_qtcore) message(STATUS "using Qt mainloop") diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7359ba0..12d5a38 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,9 +1,20 @@ set(amb_sources abstractpropertytype.cpp abstractroutingengine.cpp listplusplus.cpp abstractsink.cpp vehicleproperty.cpp abstractsource.cpp debugout.cpp timestamp.cpp uuidhelper.cpp mappropertytype.hpp) set(amb_headers_install abstractpropertytype.h nullptr.h abstractroutingengine.h listplusplus.h abstractsink.h vehicleproperty.h debugout.h abstractsource.h timestamp.h uuidhelper.h ) -include_directories( ${include_dirs} ) + add_library(amb SHARED ${amb_sources}) -target_link_libraries(amb ${libtool_LIBRARY} ${glib_LIBRARIES} ${gio_LIBRARIES}) +find_library(uuid_LIBRARY uuid DOC "Uuid libraries") +find_path(uuid_INCLUDE_DIR uuid/uuid.h DOC "Libtool headers") + +if(uuid_LIBRARY) + message(STATUS "uuid found") +else(uuid_LIBRARY) + message(FATAL_ERROR "uuid missing. please install uuid-dev") +endif(uuid_LIBRARY) + +include_directories( ${include_dirs} ${uuid_INCLUDE_DIR}) + +target_link_libraries(amb ${libtool_LIBRARY} ${glib_LIBRARIES} ${gio_LIBRARIES} ${uuid_LIBRARY}) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/automotive-message-broker.pc.in ${CMAKE_CURRENT_BINARY_DIR}/automotive-message-broker.pc @ONLY) diff --git a/lib/automotive-message-broker.pc.in b/lib/automotive-message-broker.pc.in index 3c29429..41d90fd 100644 --- a/lib/automotive-message-broker.pc.in +++ b/lib/automotive-message-broker.pc.in @@ -7,5 +7,5 @@ Name: automotive-message-broker Description: Version: @PROJECT_VERSION@ Requires: gio-2.0 glib-2.0 -Libs: -L${libdir} -lamb -Cflags: -I${includedir} \ No newline at end of file +Libs: -L${libdir} -lamb -luuid +Cflags: -I${includedir} diff --git a/plugins/opencvlux/CMakeLists.txt b/plugins/opencvlux/CMakeLists.txt index 37f306d..10bbfc7 100644 --- a/plugins/opencvlux/CMakeLists.txt +++ b/plugins/opencvlux/CMakeLists.txt @@ -1,9 +1,5 @@ if(opencvlux_plugin) -FIND_PACKAGE(Qt4 COMPONENTS QtCore REQUIRED) -include(${QT_USE_FILE}) -ADD_DEFINITIONS(${QT_DEFINITIONS}) - find_package(OpenCV REQUIRED) if(OpenCV_LIBS) @@ -27,11 +23,9 @@ include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${OpenCV_INCLUDE_DIR set(opencvluxplugin_headers opencvluxplugin.h) set(opencvluxplugin_sources opencvluxplugin.cpp) -QT4_WRAP_CPP(opencvluxplugin_headers_moc ${opencvluxplugin_headers}) - add_library(opencvluxplugin MODULE ${opencvluxplugin_sources} ${opencvluxplugin_headers_moc}) set_target_properties(opencvluxplugin PROPERTIES PREFIX "") -target_link_libraries(opencvluxplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${QT_LIBRARIES} ${OpenCV_LIBS}) +target_link_libraries(opencvluxplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${OpenCV_LIBS}) install(TARGETS opencvluxplugin LIBRARY DESTINATION lib/automotive-message-broker) diff --git a/plugins/opencvlux/opencvluxplugin.cpp b/plugins/opencvlux/opencvluxplugin.cpp index 0012db8..d522a8d 100644 --- a/plugins/opencvlux/opencvluxplugin.cpp +++ b/plugins/opencvlux/opencvluxplugin.cpp @@ -21,9 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#include -#include -#include #ifdef OPENCL #include @@ -34,34 +31,38 @@ using namespace std; #include "debugout.h" OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map config) - :QObject(),AbstractSource(re, config), m_capture(0),lastLux(0) + :AbstractSource(re, config), lastLux(0) { re->setSupported(supported(), this); - threaded = false; - kinect = false; - useOpenCl = false; - timer = new QTimer(this); - fps=30; + shared = new Shared; + shared->parent = this; + + shared->m_capture = NULL; + + shared->threaded = false; + shared->kinect = false; + shared->useOpenCl = false; + + shared->fps=30; device="0"; - pixelLowerBound = 0; - pixelUpperBound = 255; + shared->pixelLowerBound = 0; + shared->pixelUpperBound = 255; - connect(timer,SIGNAL(timeout()),this,SLOT(grabImage())); if(config.find("threaded") != config.end()) { - threaded = config["threaded"] == "true"; + shared->threaded = config["threaded"] == "true"; } if(config.find("kinect") != config.end()) { - kinect = config["kinect"] == "true"; + shared->kinect = config["kinect"] == "true"; } if(config.find("fps") != config.end()) { - fps = boost::lexical_cast(config["fps"]); + shared->fps = boost::lexical_cast(config["fps"]); } if(config.find("device") != config.end()) @@ -71,26 +72,26 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map if(config.find("pixelLowerBound") != config.end()) { - pixelLowerBound = boost::lexical_cast(config["pixelLowerBound"]); + shared->pixelLowerBound = boost::lexical_cast(config["pixelLowerBound"]); - if(pixelLowerBound < 0) + if(shared->pixelLowerBound < 0) { - pixelLowerBound = 0; + shared->pixelLowerBound = 0; } } if(config.find("pixelUpperBound") != config.end()) { - pixelUpperBound = boost::lexical_cast(config["pixelUpperBound"]); + shared->pixelUpperBound = boost::lexical_cast(config["pixelUpperBound"]); - if(pixelUpperBound > 255) - pixelUpperBound = 255; + if(shared->pixelUpperBound > 255) + shared->pixelUpperBound = 255; } if(config.find("opencl") != config.end()) { - useOpenCl = config["opencl"] == "true"; + shared->useOpenCl = config["opencl"] == "true"; } @@ -120,17 +121,17 @@ string OpenCvLuxPlugin::uuid() void OpenCvLuxPlugin::getPropertyAsync(AsyncPropertyReply *reply) { - if(!timer->isActive()) + if(!shared->m_capture || !shared->m_capture->isOpened()) { /// we want to turn on the camera for one shot to get an image and determine the intensity init(); - timer->singleShot(1,this,SLOT(grabImage())); + g_timeout_add(1,grabImage,shared); } if(reply->property == VehicleProperty::ExteriorBrightness) { - replyQueue.append(reply); + replyQueue.push_back(reply); } else ///We don't support what you are asking for. Reply false @@ -153,23 +154,18 @@ AsyncPropertyReply *OpenCvLuxPlugin::setProperty(AsyncSetPropertyRequest request void OpenCvLuxPlugin::subscribeToPropertyChanges(VehicleProperty::Property property) { - if(!timer->isActive()) + if(!shared->mRequests.size()) { init(); - timer->start(1000 / fps); + g_timeout_add(1000 / shared->fps, grabImage, shared); } - mRequests.push_back(property); + shared->mRequests.push_back(property); } void OpenCvLuxPlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property) { - mRequests.remove(property); - - if(!mRequests.size()) - { - timer->stop(); - } + shared->mRequests.remove(property); } PropertyList OpenCvLuxPlugin::supported() @@ -186,37 +182,38 @@ int OpenCvLuxPlugin::supportedOperations() return Get; } -void OpenCvLuxPlugin::grabImage() +static int grabImage(void *data) { + OpenCvLuxPlugin::Shared* shared = static_cast(data); - if(kinect) +/* if(kinect) { m_capture->grab(); m_capture->retrieve( m_image, CV_CAP_OPENNI_GRAY_IMAGE ); } - else + else*/ { - (*m_capture) >> m_image; - } + cv::Mat m_image; - if(threaded) - { - QFutureWatcher *watcher = new QFutureWatcher(); - connect(watcher,SIGNAL(finished()),this,SLOT(imageGrabCompleted())); + *(shared->m_capture) >> m_image; + + uint lux = evalImage(m_image,shared); - QFuture future = QtConcurrent::run(this, &OpenCvLuxPlugin::evalImage, m_image); - watcher->setFuture(future); + shared->parent->updateProperty(lux); } - else - { - uint lux = evalImage(m_image); - updateProperty(lux); + if(shared->mRequests.size()) + { + return true; } + delete shared->m_capture; + shared->m_capture = NULL; + return false; + } -uint OpenCvLuxPlugin::evalImage(cv::Mat qImg) +static uint evalImage(cv::Mat qImg, OpenCvLuxPlugin::Shared *shared) { #ifdef OPENCL cv::Scalar avgPixelIntensity; @@ -229,55 +226,50 @@ uint OpenCvLuxPlugin::evalImage(cv::Mat qImg) double val = avgPixelIntensity.val[0]; - double qualifiedPixel = (val - pixelLowerBound); + double qualifiedPixel = (val - shared->pixelLowerBound); if(qualifiedPixel < 0) qualifiedPixel = 0; - uint lux = qualifiedPixel * (130000.0 / pixelUpperBound); + uint lux = qualifiedPixel * (130000.0 / shared->pixelUpperBound); DebugOut(7)<<"average pixel value: "< * watcher = dynamic_cast* >(sender()); - - uint lux = watcher->result(); - - updateProperty(lux); -} void OpenCvLuxPlugin::init() { - if(m_capture) delete m_capture; + if(shared->m_capture) delete shared->m_capture; - if(kinect) + if(shared->kinect) { - m_capture = new cv::VideoCapture(CV_CAP_OPENNI); + shared->m_capture = new cv::VideoCapture(CV_CAP_OPENNI); } else if(device == "") - m_capture = new cv::VideoCapture(0); - else m_capture = new cv::VideoCapture(device.toInt()); + shared->m_capture = new cv::VideoCapture(0); + else shared->m_capture = new cv::VideoCapture(atoi(device.c_str())); - if(!m_capture->isOpened()) + if(!shared->m_capture->isOpened()) { - qDebug()<<"we failed to open camera device ("<get(CV_CAP_PROP_FRAME_WIDTH)<get(CV_CAP_PROP_FRAME_HEIGHT)<get(CV_CAP_PROP_FPS)<m_capture->get(CV_CAP_PROP_FRAME_WIDTH)<m_capture->get(CV_CAP_PROP_FRAME_HEIGHT)<m_capture->get(CV_CAP_PROP_FPS)<value = &l; reply->success = true; reply->completed(reply); @@ -285,13 +277,7 @@ void OpenCvLuxPlugin::updateProperty(uint lux) replyQueue.clear(); - if(!timer->isActive()) - { - delete m_capture; - m_capture = NULL; - } - - if(lux != lastLux && mRequests.size()) + if(lux != lastLux && shared->mRequests.size()) { lastLux = lux; routingEngine->updateProperty(VehicleProperty::ExteriorBrightness,&l, uuid()); diff --git a/plugins/opencvlux/opencvluxplugin.h b/plugins/opencvlux/opencvluxplugin.h index afd178c..30c84b6 100644 --- a/plugins/opencvlux/opencvluxplugin.h +++ b/plugins/opencvlux/opencvluxplugin.h @@ -22,19 +22,30 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#include -#include #include #include using namespace std; -class OpenCvLuxPlugin: public QObject, public AbstractSource +class OpenCvLuxPlugin: public AbstractSource { - Q_OBJECT public: + struct Shared + { + cv::VideoCapture *m_capture; + PropertyList mRequests; + OpenCvLuxPlugin* parent; + + double fps; + bool threaded; + bool kinect; + bool useOpenCl; + int pixelLowerBound; + int pixelUpperBound; + }; + OpenCvLuxPlugin(AbstractRoutingEngine* re, map config); string uuid(); @@ -50,31 +61,24 @@ public: void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {} void supportedChanged(PropertyList) {} -private Q_SLOTS: - void grabImage(); - uint evalImage(cv::Mat qImg); - void imageGrabCompleted(); + void updateProperty(uint lux); + + + private: /// method s: void init(); - void updateProperty(uint lux); -private: - bool started; - double fps; - bool threaded; - bool kinect; - bool useOpenCl; - int pixelLowerBound; - int pixelUpperBound; +private: uint lastLux; - QString device; - PropertyList mRequests; - QTimer *timer; - QList replyQueue; + std::string device; + std::list replyQueue; - cv::VideoCapture *m_capture; - cv::Mat m_image; + Shared* shared; }; +static int grabImage(void *data); +static uint evalImage(cv::Mat qImg, OpenCvLuxPlugin::Shared *shared); + + #endif // EXAMPLEPLUGIN_H diff --git a/plugins/websocketsourceplugin/websocketsource.cpp b/plugins/websocketsourceplugin/websocketsource.cpp index 5a86321..a755061 100644 --- a/plugins/websocketsourceplugin/websocketsource.cpp +++ b/plugins/websocketsourceplugin/websocketsource.cpp @@ -231,6 +231,13 @@ static int callback_http_only(libwebsocket_context *context,struct libwebsocket } case LWS_CALLBACK_CLIENT_RECEIVE: { + double prejsonparsetime = (amb::currentTime() - oldTimestamp)*1000; + + DebugOut(2)<<"websocket source pre-json parse time: "<updateProperty(VehicleProperty::VehicleSpeed, velocity); //data.front() @@ -487,6 +494,7 @@ static int callback_http_only(libwebsocket_context *context,struct libwebsocket g_object_unref(parser); break; + } } case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: { -- 2.7.4