diff --git a/gocv/gocv.swigcxx b/gocv/gocv.swigcxx index 4b5151f..c2c44d5 100644 --- a/gocv/gocv.swigcxx +++ b/gocv/gocv.swigcxx @@ -2,3 +2,4 @@ %include "gocv_core.i" %include "gocv_calib3d.i" +%include "gocv_imgproc.i" diff --git a/gocv/gocv_imgproc.cpp b/gocv/gocv_imgproc.cpp new file mode 100644 index 0000000..3e99e29 --- /dev/null +++ b/gocv/gocv_imgproc.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +#include "gocv_imgproc.hpp" + +double GcvThreshold_(cv::Mat src, cv::Mat& dst, double thresh, double maxval, int type) { + std::cout << "src " << std::endl << src << std::endl; + std::cout << "thresh " << std::endl << thresh << std::endl; + std::cout << "maxval " << std::endl << maxval << std::endl; + std::cout << "type " << std::endl << type << std::endl; + + double rtn; + rtn = cv::threshold(src, src, 1.0, 3.0, 0); + return rtn; +} diff --git a/gocv/gocv_imgproc.go b/gocv/gocv_imgproc.go new file mode 100644 index 0000000..63bf698 --- /dev/null +++ b/gocv/gocv_imgproc.go @@ -0,0 +1,17 @@ +package gocv + +// #cgo CXXFLAGS: -std=c++11 +// #cgo darwin pkg-config: opencv +// #cgo linux pkg-config: opencv +import "C" +import "github.com/gonum/matrix/mat64" + +// GcvThreshold takes a 3D column vector, and apply cv::Threshold to it. +func GcvThreshold(src *mat64.Dense) (dst *mat64.Dense, rtn float64) { + gcvSrc := Mat64ToGcvMat(src) + gcvDst := NewGcvMat() + rtn = GcvThreshold_(gcvSrc, gcvDst, 1.0, 2.0, 0) + dst = GcvMatToMat64(gcvDst) + + return dst, rtn +} diff --git a/gocv/gocv_imgproc.hpp b/gocv/gocv_imgproc.hpp new file mode 100644 index 0000000..a463485 --- /dev/null +++ b/gocv/gocv_imgproc.hpp @@ -0,0 +1,3 @@ +#include + +double GcvThreshold_(cv::Mat src, cv::Mat& dst, double thresh, double maxval, int type); diff --git a/gocv/gocv_imgproc.i b/gocv/gocv_imgproc.i new file mode 100644 index 0000000..0ec1e4c --- /dev/null +++ b/gocv/gocv_imgproc.i @@ -0,0 +1,5 @@ +%{ +#include "gocv_imgproc.hpp" +%} + +%include "gocv_imgproc.hpp" diff --git a/gocv/gocv_imgproc_test.go b/gocv/gocv_imgproc_test.go new file mode 100644 index 0000000..a489972 --- /dev/null +++ b/gocv/gocv_imgproc_test.go @@ -0,0 +1,24 @@ +package gocv + +import ( + "testing" + + "github.com/gonum/matrix/mat64" + "github.com/stretchr/testify/assert" +) + +func TestGcvThreshold(t *testing.T) { + rvec := mat64.NewDense(3, 1, []float64{ + 3, + -0.3, + 0.2, + }) + rmat, _ := GcvThreshold(rvec) + + assert.InDeltaSlice(t, []float64{0.59922526, 0.57799222, -0.55394411}, + rmat.Row(nil, 0), 1e-5) + assert.InDeltaSlice(t, []float64{0.20413818, 0.558743, 0.80382452}, + rmat.Row(nil, 1), 1e-5) + assert.InDeltaSlice(t, []float64{0.77411672, -0.5947531, 0.21682264}, + rmat.Row(nil, 2), 1e-5) +}