removed qt from opencv plugin
authorKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 6 Mar 2013 22:14:10 +0000 (14:14 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 6 Mar 2013 22:14:10 +0000 (14:14 -0800)
CMakeLists.txt
lib/CMakeLists.txt
lib/automotive-message-broker.pc.in
plugins/opencvlux/CMakeLists.txt
plugins/opencvlux/opencvluxplugin.cpp
plugins/opencvlux/opencvluxplugin.h
plugins/websocketsourceplugin/websocketsource.cpp

index 9123046..1d38fd4 100644 (file)
@@ -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")
index 7359ba0..12d5a38 100644 (file)
@@ -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)
 
index 3c29429..41d90fd 100644 (file)
@@ -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}
index 37f306d..10bbfc7 100644 (file)
@@ -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)
 
index 0012db8..d522a8d 100644 (file)
@@ -21,9 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <iostream>
 #include <boost/assert.hpp>
-#include <QFuture>
-#include <QFutureWatcher>
-#include <QtConcurrentRun>
 
 #ifdef OPENCL
 #include <opencv/ocl/ocl.hpp>
@@ -34,34 +31,38 @@ using namespace std;
 #include "debugout.h"
 
 OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> 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<int>(config["fps"]);
+               shared->fps = boost::lexical_cast<int>(config["fps"]);
        }
 
        if(config.find("device") != config.end())
@@ -71,26 +72,26 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string>
 
        if(config.find("pixelLowerBound") != config.end())
        {
-               pixelLowerBound = boost::lexical_cast<int>(config["pixelLowerBound"]);
+               shared->pixelLowerBound = boost::lexical_cast<int>(config["pixelLowerBound"]);
 
-               if(pixelLowerBound < 0)
+               if(shared->pixelLowerBound < 0)
                {
-                       pixelLowerBound = 0;
+                       shared->pixelLowerBound = 0;
                }
        }
 
 
        if(config.find("pixelUpperBound") != config.end())
        {
-               pixelUpperBound = boost::lexical_cast<int>(config["pixelUpperBound"]);
+               shared->pixelUpperBound = boost::lexical_cast<int>(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<OpenCvLuxPlugin::Shared*>(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<uint> *watcher = new QFutureWatcher<uint>();
-               connect(watcher,SIGNAL(finished()),this,SLOT(imageGrabCompleted()));
+               *(shared->m_capture) >> m_image;
+
+               uint lux = evalImage(m_image,shared);
 
-               QFuture<uint> 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: "<<qualifiedPixel<<" lux: "<<lux<<endl;
 
        return lux;
 }
 
-void OpenCvLuxPlugin::imageGrabCompleted()
-{
-       QFutureWatcher<uint> * watcher = dynamic_cast<QFutureWatcher<uint>* >(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 ("<<device<<") or no camera found";
+               DebugOut()<<"we failed to open camera device ("<<device<<") or no camera found"<<endl;
                return;
        }
 
-       DebugOut()<<"camera frame width: "<<m_capture->get(CV_CAP_PROP_FRAME_WIDTH)<<endl;
-       DebugOut()<<"camera frame height: "<<m_capture->get(CV_CAP_PROP_FRAME_HEIGHT)<<endl;
-       DebugOut()<<"camera frame fps: "<<m_capture->get(CV_CAP_PROP_FPS)<<endl;
+
+
+       DebugOut()<<"camera frame width: "<<shared->m_capture->get(CV_CAP_PROP_FRAME_WIDTH)<<endl;
+       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;
 }
 
 void OpenCvLuxPlugin::updateProperty(uint lux)
 {
        VehicleProperty::ExteriorBrightnessType l(lux);
 
-       Q_FOREACH(AsyncPropertyReply* reply, replyQueue)
+       for(auto itr = replyQueue.begin(); itr != replyQueue.end(); itr++)
        {
+               AsyncPropertyReply* reply = *itr;
                reply->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());
index afd178c..30c84b6 100644 (file)
@@ -22,19 +22,30 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 #include <abstractsource.h>
 #include <string>
 
-#include <QTimer>
-#include <QList>
 #include <opencv/cv.h>
 #include <opencv/highgui.h>
 
 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<string, string> 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<AsyncPropertyReply*> replyQueue;
+       std::string device;
+       std::list<AsyncPropertyReply*> 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
index 5a86321..a755061 100644 (file)
@@ -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: "<<prejsonparsetime<<endl;
+
+                       for(int i=0;i<1000;i++)
+                       {
+
                        //Incoming JSON reqest.
                        GError* error = nullptr;
                        JsonParser* parser = json_parser_new();
@@ -308,7 +315,7 @@ static int callback_http_only(libwebsocket_context *context,struct libwebsocket
                                        std::string sequence= json_reader_get_string_value(reader);
                                        json_reader_end_member(reader);
                                        //printf("Value changed: %s, %s\n",name.c_str(),data.front().c_str());
-                                       DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Value changed:" << name << value << "\n";
+                                       DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Value changed:" << name << value << endl;
                                        //Name should be a valid property
                                        //      routingEngine->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:
                {