copyto.cpp
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <opencv2/opencv.hpp>
#include <openbr/plugins/openbr_internal.h>
using namespace std;
using namespace cv;
extern string type2str(int type);
namespace br { namespace cuda { namespace cudacopyto {
//template<typename T>
//void wrapper(const T* in, void** out, const int rows, const int cols);
void wrapper(const unsigned char* in, void** out, const int rows, const int cols);
}}}
namespace br
{
class CUDACopyTo : public UntrainableTransform
{
Q_OBJECT
private:
void project(const Template &src, Template &dst) const
{
const Mat& srcMat = src.m();
const int rows = srcMat.rows;
const int cols = srcMat.cols;
void* cudaMemPtr;
switch(srcMat.type()) {
//case CV_32FC1:
// br::cuda::cudacopyfrom::wrapper<float>(srcMat.ptr<float>(), &cudaMemPtr, rows, cols);
// break;
case CV_8UC1:
//br::cuda::cudacopyfrom::wrapper<unsigned char>(srcMat.ptr<unsigned char>(), &cudaMemPtr, rows, cols);
br::cuda::cudacopyto::wrapper(srcMat.ptr<unsigned char>(), &cudaMemPtr, rows, cols);
break;
default:
cout << "ERR: Invalid image type! " << type2str(srcMat.type()) << endl;
return;
}
// output will be a single pointer to graphics card memory
Mat dstMat = Mat(4, 1, DataType<void*>::type);
void** dstMatData = dstMat.ptr<void*>();
// save cuda ptr, rows, cols, then type
dstMatData[0] = cudaMemPtr;
dstMatData[1] = new int; *((int*)dstMatData[1]) = rows;
dstMatData[2] = new int; *((int*)dstMatData[2]) = cols;
dstMatData[3] = new int; *((int*)dstMatData[3]) = srcMat.type();
dst = dstMat;
}
};
BR_REGISTER(Transform, CUDACopyTo);
}
#include "cuda/copyto.moc"