ContinuousGpuMat.hpp
1.28 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
#pragma once
#include <cuda_runtime.h>
#include <opencv2/core/cuda.hpp>
class ContinuousGpuMat {
public:
ContinuousGpuMat(const ContinuousGpuMat &) = delete;
ContinuousGpuMat &operator=(const ContinuousGpuMat &) = delete;
ContinuousGpuMat &operator=(ContinuousGpuMat &&) noexcept = delete;
ContinuousGpuMat(ContinuousGpuMat &&) noexcept = delete;
ContinuousGpuMat(const int rows, const int cols, const int type) {
allocate(rows, cols, type);
}
ContinuousGpuMat(const cv::Size &size, const int type)
: ContinuousGpuMat(size.height, size.width, type) {}
explicit ContinuousGpuMat(cv::InputArray host)
: ContinuousGpuMat(host.rows(), host.cols(), host.type()) {
continuousMat.upload(host);
}
void create(const cv::Size &size, const int type) {
allocate(size.height, size.width, type);
}
cv::Size size() const { return continuousMat.size(); }
int type() const { return continuousMat.type(); }
cv::cuda::GpuMat &device() { return continuousMat; }
~ContinuousGpuMat() { cudaFree(deviceMemory); }
private:
void *deviceMemory{nullptr};
cv::cuda::GpuMat continuousMat;
void allocate(const int rows, const int cols, const int type) {
cudaMalloc(&deviceMemory, rows * cols * cv::getElemSize(type));
continuousMat = cv::cuda::GpuMat(rows, cols, type, deviceMemory);
}
};