copyfrom.cpp
1.29 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
#include <iostream>
#include <opencv2/opencv.hpp>
#include <openbr/plugins/openbr_internal.h>
using namespace std;
using namespace cv;
// extern CUDA declaration
namespace br { namespace cuda { namespace cudacopyfrom {
template <typename T> void wrapper(void* src, T* out, int rows, int cols);
}}}
namespace br
{
class CUDACopyFrom : public UntrainableTransform
{
Q_OBJECT
private:
void project(const Template &src, Template &dst) const
{
cout << "CUDACopyFrom Start" << endl << endl << endl;
// pull the data back out of the Mat
void* const* dataPtr = src.m().ptr<void*>();
void* cudaMemPtr = dataPtr[0];
int rows = *((int*)dataPtr[1]);
int cols = *((int*)dataPtr[2]);
int type = *((int*)dataPtr[3]);
Mat dstMat = Mat(rows, cols, type);
switch(type) {
case CV_32FC1:
br::cuda::cudacopyfrom::wrapper(cudaMemPtr, dstMat.ptr<float>(), rows, cols);
break;
case CV_8UC1:
br::cuda::cudacopyfrom::wrapper(cudaMemPtr, dstMat.ptr<unsigned char>(), rows, cols);
break;
default:
cout << "ERR: Invalid image format" << endl;
break;
}
dst = dstMat;
cout << "CUDACopyFrom End" << endl;
}
};
BR_REGISTER(Transform, CUDACopyFrom);
}
#include "cuda/copyfrom.moc"