do not run opencv plugin if fail to open camera
authorKevron Rees <kevron_m_rees@linux.intel.com>
Mon, 18 Mar 2013 23:47:13 +0000 (16:47 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Mon, 18 Mar 2013 23:47:30 +0000 (16:47 -0700)
plugins/opencvlux/opencvluxplugin.cpp
plugins/opencvlux/opencvluxplugin.h

index e5ee9fc..9bfcc70 100644 (file)
@@ -125,8 +125,8 @@ void OpenCvLuxPlugin::getPropertyAsync(AsyncPropertyReply *reply)
        {
                /// we want to turn on the camera for one shot to get an image and determine the intensity
 
-               init();
-               g_timeout_add(1,grabImage,shared);
+               if(init())
+                       g_timeout_add(1,grabImage,shared);
        }
 
        if(reply->property == VehicleProperty::ExteriorBrightness)
@@ -156,8 +156,8 @@ void OpenCvLuxPlugin::subscribeToPropertyChanges(VehicleProperty::Property prope
 {
        if(!shared->mRequests.size())
        {
-               init();
-               g_timeout_add(1000 / shared->fps, grabImage, shared);
+               if(init())
+                       g_timeout_add(1000 / shared->fps, grabImage, shared);
        }
 
        shared->mRequests.push_back(property);
@@ -245,7 +245,7 @@ static uint evalImage(cv::Mat qImg, OpenCvLuxPlugin::Shared *shared)
 }
 
 
-void OpenCvLuxPlugin::init()
+bool OpenCvLuxPlugin::init()
 {
        if(shared->m_capture) delete shared->m_capture;
 
@@ -260,7 +260,7 @@ void OpenCvLuxPlugin::init()
        if(!shared->m_capture->isOpened())
        {
                DebugOut()<<"we failed to open camera device ("<<device<<") or no camera found"<<endl;
-               return;
+               return false;
        }
 
 
@@ -268,6 +268,8 @@ void OpenCvLuxPlugin::init()
        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;
+
+       return true;
 }
 
 void OpenCvLuxPlugin::updateProperty(uint lux)
index 0955ad9..ea5634f 100644 (file)
@@ -66,8 +66,8 @@ public:
 
 
        
-private: /// method s:
-       void init();
+private: /// methods:
+       bool init();
 
 private:       
        uint lastLux;