From d4022e856c11809577ff7843302955e89518983a Mon Sep 17 00:00:00 2001 From: DepthDeluxe Date: Sat, 5 Dec 2015 14:33:01 -0500 Subject: [PATCH] initial commit of repo * copyto and copyfrom need work --- openbr/plugins/cuda/copyfrom.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ openbr/plugins/cuda/copyto.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ openbr/plugins/cuda/passthrough.cpp | 23 +++++++++++++++++++++++ openbr/plugins/cuda/threshold.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 0 deletions(-) create mode 100644 openbr/plugins/cuda/copyfrom.cpp create mode 100644 openbr/plugins/cuda/copyto.cpp create mode 100644 openbr/plugins/cuda/passthrough.cpp create mode 100644 openbr/plugins/cuda/threshold.cpp diff --git a/openbr/plugins/cuda/copyfrom.cpp b/openbr/plugins/cuda/copyfrom.cpp new file mode 100644 index 0000000..e624aae --- /dev/null +++ b/openbr/plugins/cuda/copyfrom.cpp @@ -0,0 +1,43 @@ +#include + +#include +#include + +#include + +using namespace std; + +using namespace cv; +using namespace cv::gpu; + + +namespace br +{ + class CUDACopyFrom : public UntrainableTransform + { + Q_OBJECT + +private: + void project(const Template &src, Template &dst) const + { + // reassemble the integer and then build pointer to it + uint64_t gpuMatInt = (((uint64_t)src.m().at(1,0)) << (uint64_t)32) + ((uint64_t)src.m().at(0,0)); + GpuMat* gpuMat = (GpuMat*)gpuMatInt; + + printf("gpuMatInt: %li\n", gpuMatInt); + printf("m.at(0,0): %i\nm.at(1,0): %i\n", src.m().at(0,0), src.m().at(1,0)); + + // download the data back into the destination + Size size = gpuMat->size(); + Mat out = Mat(size.height, size.width, gpuMat->depth()); + + gpuMat->download(out); + + dst = out; + } + }; + + BR_REGISTER(Transform, CUDACopyFrom); +} + +#include "cuda/copyfrom.moc" diff --git a/openbr/plugins/cuda/copyto.cpp b/openbr/plugins/cuda/copyto.cpp new file mode 100644 index 0000000..36f683f --- /dev/null +++ b/openbr/plugins/cuda/copyto.cpp @@ -0,0 +1,54 @@ +#include + +#include +#include + +#include + +using namespace std; + +using namespace cv; +using namespace cv::gpu; + +namespace br +{ + class CUDACopyTo : public UntrainableTransform + { + Q_OBJECT + +private: + void project(const Template &src, Template &dst) const + { + // get the mat to send to the GPU + GpuMat* gpuMat = new GpuMat; + + try + { + // copy the contents to the GPU + gpuMat->upload(src.m()); + } + catch(const cv::Exception& ex) + { + cout << "Error: " << ex.what() << endl; + } + + // now create a new Mat that contains the 64-bit pointer + Mat m = Mat(2, 1, CV_32S); + + // pointer magic + uint64_t gpuMatInt = (uint64_t)gpuMat; + m.at(0,0) = (int32_t)(gpuMatInt & 0x00000000FFFFFFFF); + m.at(1,0) = (int32_t)((gpuMatInt & 0xFFFFFFFF00000000) >> (uint64_t)32); + + printf("gpuMatInt: %li\n", gpuMatInt); + printf("m.at(0,0): %i\nm.at(1,0): %i\n", m.at(0,0), m.at(1,0)); + + // save away in the destination mat + dst += m; + } + }; + + BR_REGISTER(Transform, CUDACopyTo); +} + +#include "cuda/copyto.moc" diff --git a/openbr/plugins/cuda/passthrough.cpp b/openbr/plugins/cuda/passthrough.cpp new file mode 100644 index 0000000..5b1044d --- /dev/null +++ b/openbr/plugins/cuda/passthrough.cpp @@ -0,0 +1,23 @@ +#include + +#include + +using namespace cv; + +namespace br +{ + class CUDAPassthroughTransform : public UntrainableTransform + { + Q_OBJECT + +private: + void project(const Template &src, Template &dst) const + { + dst = src; + } + }; + + BR_REGISTER(Transform, CUDAPassthroughTransform); +} + +#include "cuda/passthrough.moc" diff --git a/openbr/plugins/cuda/threshold.cpp b/openbr/plugins/cuda/threshold.cpp new file mode 100644 index 0000000..219dccf --- /dev/null +++ b/openbr/plugins/cuda/threshold.cpp @@ -0,0 +1,44 @@ +#include + +#include +#include + +#include + +using namespace std; + +using namespace cv; +using namespace cv::gpu; + +namespace br +{ + class CUDAThreshold : public UntrainableTransform + { + Q_OBJECT + +private: + void project(const Template &src, Template &dst) const + { + // get the mat to send to the GPU + GpuMat gpuMat_src, gpuMat_dst; + + try + { + // copy the contents to the GPU + gpuMat_src.upload(src.m()); + + threshold(gpuMat_src, gpuMat_dst, 128.0, 255.0, CV_THRESH_BINARY); + + gpuMat_dst.download(dst.m()); + } + catch(const cv::Exception& ex) + { + cout << "Error: " << ex.what() << endl; + } + } + }; + + BR_REGISTER(Transform, CUDAThreshold); +} + +#include "cuda/threshold.moc" -- libgit2 0.21.4