-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhaseDiffAndAmp.hpp
60 lines (47 loc) · 1.65 KB
/
PhaseDiffAndAmp.hpp
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
#pragma once
//#include "precomp.hpp"
//#include <fstream>
//#include <sstream>
//#include <iostream>
#include <opencv2/core/ocl.hpp>
namespace cv
{
class PhaseDiffAndAmp {
public:
PhaseDiffAndAmp() {
initialise();
}
bool apply(InputArray _laplacian, InputArray _laplacian_prev,
InputArray _riesz, InputArray _riesz_prev,
OutputArray _amp, OutputArray _phase_diff) {
UMat laplacian = _laplacian.getUMat();
UMat laplacian_prev = _laplacian_prev.getUMat();
UMat riesz = _riesz.getUMat();
UMat riesz_prev = _riesz_prev.getUMat();
UMat amp = _amp.getUMat();
UMat phase_diff = _phase_diff.getUMat();
int idxArg = 0;
idxArg = kernel_apply.set(idxArg, ocl::KernelArg::ReadOnly(laplacian));
idxArg = kernel_apply.set(idxArg, ocl::KernelArg::PtrReadOnly(laplacian_prev));
idxArg = kernel_apply.set(idxArg, ocl::KernelArg::ReadOnlyNoSize(riesz));
idxArg = kernel_apply.set(idxArg, ocl::KernelArg::PtrReadOnly(riesz_prev));
idxArg = kernel_apply.set(idxArg, ocl::KernelArg::PtrWriteOnly(amp));
idxArg = kernel_apply.set(idxArg, ocl::KernelArg::PtrWriteOnly(phase_diff));
size_t globalsize[] = { (size_t)laplacian.cols, (size_t)laplacian.rows, 1 };
return kernel_apply.run(2, globalsize, NULL, true);
}
private:
cv::ocl::ProgramSource oclsrc;
ocl::Kernel kernel_apply;
void initialise() {
std::ifstream t("../../../opencl/phase_diff_and_amp.cl");
if (t.fail()) {
std::cout << "Failed to read phase_diff_and_amp.cl" << std::endl;
}
std::stringstream buffer;
buffer << t.rdbuf();
oclsrc = cv::ocl::ProgramSource(buffer.str());
kernel_apply.create("pdaa_kernel", oclsrc, "");
}
};
}