From 2874af233cdd5aa8e30ca3b3af00764e795dfb90 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Mon, 18 Mar 2013 16:47:13 -0700 Subject: [PATCH] do not run opencv plugin if fail to open camera --- plugins/opencvlux/opencvluxplugin.cpp | 14 ++++++++------ plugins/opencvlux/opencvluxplugin.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/opencvlux/opencvluxplugin.cpp b/plugins/opencvlux/opencvluxplugin.cpp index e5ee9fc..9bfcc70 100644 --- a/plugins/opencvlux/opencvluxplugin.cpp +++ b/plugins/opencvlux/opencvluxplugin.cpp @@ -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 ("<m_capture->get(CV_CAP_PROP_FRAME_WIDTH)<m_capture->get(CV_CAP_PROP_FRAME_HEIGHT)<m_capture->get(CV_CAP_PROP_FPS)<