Commit d4022e856c11809577ff7843302955e89518983a

Authored by DepthDeluxe
1 parent 8a62b8b4

initial commit of repo

* copyto and copyfrom need work
openbr/plugins/cuda/copyfrom.cpp 0 → 100644
  1 +#include <iostream>
  2 +
  3 +#include <opencv2/opencv.hpp>
  4 +#include <opencv2/gpu/gpu.hpp>
  5 +
  6 +#include <openbr/plugins/openbr_internal.h>
  7 +
  8 +using namespace std;
  9 +
  10 +using namespace cv;
  11 +using namespace cv::gpu;
  12 +
  13 +
  14 +namespace br
  15 +{
  16 + class CUDACopyFrom : public UntrainableTransform
  17 + {
  18 + Q_OBJECT
  19 +
  20 +private:
  21 + void project(const Template &src, Template &dst) const
  22 + {
  23 + // reassemble the integer and then build pointer to it
  24 + uint64_t gpuMatInt = (((uint64_t)src.m().at<int>(1,0)) << (uint64_t)32) + ((uint64_t)src.m().at<int>(0,0));
  25 + GpuMat* gpuMat = (GpuMat*)gpuMatInt;
  26 +
  27 + printf("gpuMatInt: %li\n", gpuMatInt);
  28 + printf("m.at(0,0): %i\nm.at(1,0): %i\n", src.m().at<int>(0,0), src.m().at<int>(1,0));
  29 +
  30 + // download the data back into the destination
  31 + Size size = gpuMat->size();
  32 + Mat out = Mat(size.height, size.width, gpuMat->depth());
  33 +
  34 + gpuMat->download(out);
  35 +
  36 + dst = out;
  37 + }
  38 + };
  39 +
  40 + BR_REGISTER(Transform, CUDACopyFrom);
  41 +}
  42 +
  43 +#include "cuda/copyfrom.moc"
... ...
openbr/plugins/cuda/copyto.cpp 0 → 100644
  1 +#include <iostream>
  2 +
  3 +#include <opencv2/opencv.hpp>
  4 +#include <opencv2/gpu/gpu.hpp>
  5 +
  6 +#include <openbr/plugins/openbr_internal.h>
  7 +
  8 +using namespace std;
  9 +
  10 +using namespace cv;
  11 +using namespace cv::gpu;
  12 +
  13 +namespace br
  14 +{
  15 + class CUDACopyTo : public UntrainableTransform
  16 + {
  17 + Q_OBJECT
  18 +
  19 +private:
  20 + void project(const Template &src, Template &dst) const
  21 + {
  22 + // get the mat to send to the GPU
  23 + GpuMat* gpuMat = new GpuMat;
  24 +
  25 + try
  26 + {
  27 + // copy the contents to the GPU
  28 + gpuMat->upload(src.m());
  29 + }
  30 + catch(const cv::Exception& ex)
  31 + {
  32 + cout << "Error: " << ex.what() << endl;
  33 + }
  34 +
  35 + // now create a new Mat that contains the 64-bit pointer
  36 + Mat m = Mat(2, 1, CV_32S);
  37 +
  38 + // pointer magic
  39 + uint64_t gpuMatInt = (uint64_t)gpuMat;
  40 + m.at<int>(0,0) = (int32_t)(gpuMatInt & 0x00000000FFFFFFFF);
  41 + m.at<int>(1,0) = (int32_t)((gpuMatInt & 0xFFFFFFFF00000000) >> (uint64_t)32);
  42 +
  43 + printf("gpuMatInt: %li\n", gpuMatInt);
  44 + printf("m.at(0,0): %i\nm.at(1,0): %i\n", m.at<int>(0,0), m.at<int>(1,0));
  45 +
  46 + // save away in the destination mat
  47 + dst += m;
  48 + }
  49 + };
  50 +
  51 + BR_REGISTER(Transform, CUDACopyTo);
  52 +}
  53 +
  54 +#include "cuda/copyto.moc"
... ...
openbr/plugins/cuda/passthrough.cpp 0 → 100644
  1 +#include <opencv2/imgproc/imgproc.hpp>
  2 +
  3 +#include <openbr/plugins/openbr_internal.h>
  4 +
  5 +using namespace cv;
  6 +
  7 +namespace br
  8 +{
  9 + class CUDAPassthroughTransform : public UntrainableTransform
  10 + {
  11 + Q_OBJECT
  12 +
  13 +private:
  14 + void project(const Template &src, Template &dst) const
  15 + {
  16 + dst = src;
  17 + }
  18 + };
  19 +
  20 + BR_REGISTER(Transform, CUDAPassthroughTransform);
  21 +}
  22 +
  23 +#include "cuda/passthrough.moc"
... ...
openbr/plugins/cuda/threshold.cpp 0 → 100644
  1 +#include <iostream>
  2 +
  3 +#include <opencv2/opencv.hpp>
  4 +#include <opencv2/gpu/gpu.hpp>
  5 +
  6 +#include <openbr/plugins/openbr_internal.h>
  7 +
  8 +using namespace std;
  9 +
  10 +using namespace cv;
  11 +using namespace cv::gpu;
  12 +
  13 +namespace br
  14 +{
  15 + class CUDAThreshold : public UntrainableTransform
  16 + {
  17 + Q_OBJECT
  18 +
  19 +private:
  20 + void project(const Template &src, Template &dst) const
  21 + {
  22 + // get the mat to send to the GPU
  23 + GpuMat gpuMat_src, gpuMat_dst;
  24 +
  25 + try
  26 + {
  27 + // copy the contents to the GPU
  28 + gpuMat_src.upload(src.m());
  29 +
  30 + threshold(gpuMat_src, gpuMat_dst, 128.0, 255.0, CV_THRESH_BINARY);
  31 +
  32 + gpuMat_dst.download(dst.m());
  33 + }
  34 + catch(const cv::Exception& ex)
  35 + {
  36 + cout << "Error: " << ex.what() << endl;
  37 + }
  38 + }
  39 + };
  40 +
  41 + BR_REGISTER(Transform, CUDAThreshold);
  42 +}
  43 +
  44 +#include "cuda/threshold.moc"
... ...