forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.go
109 lines (95 loc) · 3.23 KB
/
filters.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package cuda
/*
#include <stdlib.h>
#include "../core.h"
#include "core.h"
#include "filters.h"
*/
import "C"
import (
"image"
"unsafe"
"gocv.io/x/gocv"
)
// GaussianFilter
//
// For further details, please see:
// https://docs.opencv.org/master/dc/d66/group__cudafilters.html#gaa4df286369114cfd4b144ae211f6a6c8
//
type GaussianFilter struct {
p unsafe.Pointer
}
// NewGaussianFilter returns a new GaussianFilter.
func NewGaussianFilter(srcType gocv.MatType, dstType gocv.MatType, ksize image.Point, sigma1 float64) GaussianFilter {
pSize := C.struct_Size{
width: C.int(ksize.X),
height: C.int(ksize.Y),
}
return GaussianFilter{p: unsafe.Pointer(C.CreateGaussianFilter(C.int(srcType), C.int(dstType), pSize, C.double(sigma1)))}
}
// Close GaussianFilter
func (gf *GaussianFilter) Close() error {
C.GaussianFilter_Close((C.GaussianFilter)(gf.p))
gf.p = nil
return nil
}
// Apply applies the Gaussian filter.
//
// For further details, please see:
// https://docs.opencv.org/master/dc/d2b/classcv_1_1cuda_1_1Filter.html#a20b58d13871027473b4c39cc698cf80f
//
func (gf *GaussianFilter) Apply(img GpuMat, dst *GpuMat) {
C.GaussianFilter_Apply(C.GaussianFilter(gf.p), img.p, dst.p, nil)
return
}
// ApplyWithStream applies the Gaussian filter
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/dc/d2b/classcv_1_1cuda_1_1Filter.html#a20b58d13871027473b4c39cc698cf80f
//
func (gf *GaussianFilter) ApplyWithStream(img GpuMat, dst *GpuMat, s Stream) {
C.GaussianFilter_Apply(C.GaussianFilter(gf.p), img.p, dst.p, s.p)
return
}
// SobelFilter
//
// For further details, please see:
// https://docs.opencv.org/master/dc/d66/group__cudafilters.html#gabf85fe61958bb21e93211a6fcc7c5c3b
//
type SobelFilter struct {
p unsafe.Pointer
}
// NewSobelFilter returns a new SobelFilter.
func NewSobelFilter(srcType gocv.MatType, dstType gocv.MatType, dx int, dy int) SobelFilter {
return SobelFilter{p: unsafe.Pointer(C.CreateSobelFilter(C.int(srcType), C.int(dstType), C.int(dx), C.int(dy)))}
}
// NewSobelFilterWithParams returns a new SobelFilter.
func NewSobelFilterWithParams(srcType gocv.MatType, dstType gocv.MatType, dx int, dy int, ksize int, scale float64, rowBorderMode int, columnBorderMode int) SobelFilter {
return SobelFilter{p: unsafe.Pointer(C.CreateSobelFilterWithParams(C.int(srcType), C.int(dstType), C.int(dx), C.int(dy), C.int(ksize), C.double(scale), C.int(rowBorderMode), C.int(columnBorderMode)))}
}
// Close SobelFilter
func (sf *SobelFilter) Close() error {
C.SobelFilter_Close((C.SobelFilter)(sf.p))
sf.p = nil
return nil
}
// Apply applies the Sobel filter.
//
// For further details, please see:
// https://docs.opencv.org/master/dc/d2b/classcv_1_1cuda_1_1Filter.html#a20b58d13871027473b4c39cc698cf80f
//
func (sf *SobelFilter) Apply(img GpuMat, dst *GpuMat) {
C.SobelFilter_Apply(C.SobelFilter(sf.p), img.p, dst.p, nil)
return
}
// ApplyWithStream applies the Sobel filter
// using a Stream for concurrency.
//
// For further details, please see:
// https://docs.opencv.org/master/dc/d2b/classcv_1_1cuda_1_1Filter.html#a20b58d13871027473b4c39cc698cf80f
//
func (sf *SobelFilter) ApplyWithStream(img GpuMat, dst *GpuMat, s Stream) {
C.SobelFilter_Apply(C.SobelFilter(sf.p), img.p, dst.p, s.p)
return
}