First attempt for adding threshold.

This commit is contained in:
Chih-Wei Chang 2015-07-02 22:20:40 +08:00
parent e404f82893
commit 71854e5f60
6 changed files with 66 additions and 0 deletions

View file

@ -2,3 +2,4 @@
%include "gocv_core.i"
%include "gocv_calib3d.i"
%include "gocv_imgproc.i"

16
gocv/gocv_imgproc.cpp Normal file
View file

@ -0,0 +1,16 @@
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#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;
}

17
gocv/gocv_imgproc.go Normal file
View file

@ -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
}

3
gocv/gocv_imgproc.hpp Normal file
View file

@ -0,0 +1,3 @@
#include <opencv2/opencv.hpp>
double GcvThreshold_(cv::Mat src, cv::Mat& dst, double thresh, double maxval, int type);

5
gocv/gocv_imgproc.i Normal file
View file

@ -0,0 +1,5 @@
%{
#include "gocv_imgproc.hpp"
%}
%include "gocv_imgproc.hpp"

24
gocv/gocv_imgproc_test.go Normal file
View file

@ -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)
}