summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevron Rees <tripzero.kev@gmail.com>2013-09-06 00:00:38 -0700
committerKevron Rees <tripzero.kev@gmail.com>2013-09-06 00:01:27 -0700
commit5f00a1ba9075f3bc8d41f233c77226c856dc3db5 (patch)
tree4bd55453d559c69988f3333e688f1844c8795a22
parentfeedfe40da9a1be58f1dcbb55c298a42c668c478 (diff)
downloadautomotive-message-broker-5f00a1ba9075f3bc8d41f233c77226c856dc3db5.tar.gz
added cuda support for opencv plugin
-rw-r--r--examples/opencvdbusconfig1
-rw-r--r--examples/opencvluxconfig1
-rw-r--r--plugins/examplesink.cpp1
-rw-r--r--plugins/opencvlux/CMakeLists.txt9
-rw-r--r--plugins/opencvlux/README9
-rw-r--r--plugins/opencvlux/opencvluxplugin.cpp53
-rw-r--r--plugins/opencvlux/opencvluxplugin.h1
7 files changed, 73 insertions, 2 deletions
diff --git a/examples/opencvdbusconfig b/examples/opencvdbusconfig
index 4cc9e4fc..9b326b61 100644
--- a/examples/opencvdbusconfig
+++ b/examples/opencvdbusconfig
@@ -4,6 +4,7 @@
"name" : "OpenCV LUX",
"path" : "/usr/lib/automotive-message-broker/opencvluxplugin.so",
"threaded" : "true",
+ "cuda" : "true",
"fps" : "30",
"pixelLowerBound" : "18",
"pixelUpperBound" : "255",
diff --git a/examples/opencvluxconfig b/examples/opencvluxconfig
index d0c01b1f..27b6cd78 100644
--- a/examples/opencvluxconfig
+++ b/examples/opencvluxconfig
@@ -7,6 +7,7 @@
"threaded" : "true",
"kinect" : "false",
"opencl" : "false",
+ "cuda" : "false",
"pixelLowerBound" : "0",
"pixelUpperBound" : "255",
"fps" : "30",
diff --git a/plugins/examplesink.cpp b/plugins/examplesink.cpp
index 5c1fb0ad..ef05d160 100644
--- a/plugins/examplesink.cpp
+++ b/plugins/examplesink.cpp
@@ -36,6 +36,7 @@ ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map<string, string> conf
routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
+ routingEngine->subscribeToProperty(VehicleProperty::ExteriorBrightness, this);
supportedChanged(engine->supported());
}
diff --git a/plugins/opencvlux/CMakeLists.txt b/plugins/opencvlux/CMakeLists.txt
index c965c62f..17ebedbd 100644
--- a/plugins/opencvlux/CMakeLists.txt
+++ b/plugins/opencvlux/CMakeLists.txt
@@ -18,6 +18,15 @@ else(ocl)
message(STATUS "no opencv ocl headers found (ocl.hpp). no opencl support")
endif(ocl)
+find_path(cuda gpu.hpp PATH_SUFFIXES opencv/gpu opencv2/gpu DOC "opencv cuda headers")
+
+if(cuda)
+ message(STATUS "found opencv cuda headers. enabling cuda support. ${cuda}")
+ add_definitions(-DCUDA)
+else(cuda)
+ message(STATUS "no opencv cuda headers found. no cuda support")
+endif(cuda)
+
include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${OpenCV_INCLUDE_DIRS})
set(opencvluxplugin_headers opencvluxplugin.h)
diff --git a/plugins/opencvlux/README b/plugins/opencvlux/README
index 76cad19d..47222137 100644
--- a/plugins/opencvlux/README
+++ b/plugins/opencvlux/README
@@ -74,3 +74,12 @@ NOTE: This option has not been tested because at implementation, OpenCL 1.2 was
on-hand.
Default: "false"
+
+"cuda"
+Use nvidia cuda gpu processing to process image data. This will only work if OpenCV was compiled with
+cuda support.
+
+NOTE: this does not appear to have a noticable impact on processing given the way we are using it.
+this does however make memory usage explode.
+
+Default: "false"
diff --git a/plugins/opencvlux/opencvluxplugin.cpp b/plugins/opencvlux/opencvluxplugin.cpp
index 142ced4e..d2181f05 100644
--- a/plugins/opencvlux/opencvluxplugin.cpp
+++ b/plugins/opencvlux/opencvluxplugin.cpp
@@ -26,6 +26,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <opencv/ocl/ocl.hpp>
#endif
+#ifdef CUDA
+#include <opencv2/gpu/gpu.hpp>
+#endif
+
using namespace std;
#include "debugout.h"
@@ -43,6 +47,7 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string>
shared->threaded = false;
shared->kinect = false;
shared->useOpenCl = false;
+ shared->useCuda = false;
shared->fps=30;
device="0";
@@ -94,15 +99,42 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string>
shared->useOpenCl = config["opencl"] == "true";
}
+ if(config.find("cuda") != config.end())
+ {
+ shared->useCuda = config["cuda"] == "true";
+ }
+
#ifdef OPENCL
- if(useOpenCl)
+ if(shared->useOpenCl)
{
std::vector<cv::ocl::Info> info;
cv::ocl::getDevice(info);
}
#endif
+#ifdef CUDA
+ if(shared->useCuda)
+ {
+ int devices = cv::gpu::getCudaEnabledDeviceCount();
+ DebugOut()<<"There are "<<devices<<" CUDA devices on this system"<<endl;
+ if(devices)
+ {
+ DebugOut()<<"We will use 0 as the default device"<<endl;
+ cv::gpu::DeviceInfo info(0);
+ DebugOut()<<"Cuda Device Name: "<<info.name()<<endl;
+ DebugOut()<<"Version: "<<info.majorVersion()<<"major"<<info.minorVersion()<<"minor"<<endl;
+ DebugOut()<<"Streaming processor count: "<<info.multiProcessorCount()<<endl;
+ cv::gpu::setDevice(0);
+ }
+ else
+ {
+ DebugOut(DebugOut::Warning)<<"No CUDA device found. Disabling CUDA."<<endl;
+ shared->useCuda = false;
+ }
+ }
+#endif
+
}
@@ -172,7 +204,6 @@ PropertyList OpenCvLuxPlugin::supported()
{
PropertyList props;
props.push_back(VehicleProperty::ExteriorBrightness);
-
return props;
}
@@ -225,6 +256,24 @@ static uint evalImage(cv::Mat qImg, OpenCvLuxPlugin::Shared *shared)
cv::ocl::meanStdDev(qImg, avgPixelIntensity, stdDev);
#endif
}
+ else if(shared->useCuda)
+ {
+#ifdef CUDA
+ cv::gpu::GpuMat src(qImg), dest;
+ cv::gpu::cvtColor(src, dest, CV_BGR2GRAY);
+ cv::Scalar stdDev;
+ try
+ {
+
+ cv::gpu::meanStdDev(dest, avgPixelIntensity, stdDev);
+ }
+ catch(...)
+ {
+ DebugOut(DebugOut::Error)<<"CUDA pixel intensity calculation failed."<<endl;
+ }
+
+#endif
+ }
else
{
avgPixelIntensity = cv::mean(qImg);
diff --git a/plugins/opencvlux/opencvluxplugin.h b/plugins/opencvlux/opencvluxplugin.h
index f59a2a4d..2d0af7bc 100644
--- a/plugins/opencvlux/opencvluxplugin.h
+++ b/plugins/opencvlux/opencvluxplugin.h
@@ -42,6 +42,7 @@ public:
bool threaded;
bool kinect;
bool useOpenCl;
+ bool useCuda;
int pixelLowerBound;
int pixelUpperBound;
};