From af3c33e58e961ea006841c2ae83d3d1594a49b7f Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Tue, 17 Feb 2015 00:33:46 +0800 Subject: [PATCH] Cleanup swig files. --- gocv/gocv.go | 64 ---------------------- gocv/gocv.swigcxx | 6 +-- gocv/gocv_calib3d.i | 5 ++ gocv/gocv_core.go | 69 ++++++++++++++++++++++++ gocv/{gocv_test.go => gocv_core_test.go} | 0 5 files changed, 75 insertions(+), 69 deletions(-) create mode 100644 gocv/gocv_calib3d.i create mode 100644 gocv/gocv_core.go rename gocv/{gocv_test.go => gocv_core_test.go} (100%) diff --git a/gocv/gocv.go b/gocv/gocv.go index 05ab78c..772b236 100644 --- a/gocv/gocv.go +++ b/gocv/gocv.go @@ -3,67 +3,3 @@ package gocv // #cgo CXXFLAGS: -std=c++11 // #cgo darwin pkg-config: opencv import "C" -import "github.com/gonum/matrix/mat64" - -func NewGcvPoint3f32(x, y, z float64) GcvPoint3f32_ { - return NewGcvPoint3f32_(float32(x), float32(y), float32(z)) -} - -func NewGcvPoint3f64(x, y, z float64) GcvPoint3f64_ { - return NewGcvPoint3f64_(float64(x), float64(y), float64(z)) -} - -func NewGcvPoint2f32(x, y float64) GcvPoint2f32_ { - return NewGcvPoint2f32_(float32(x), float32(y)) -} - -func NewGcvPoint2f64(x, y float64) GcvPoint2f64_ { - return NewGcvPoint2f64_(float64(x), float64(y)) -} - -func NewGcvSize2f32(x, y float64) GcvSize2f32_ { - return NewGcvSize2f32_(float32(x), float32(y)) -} - -func NewGcvSize2f64(x, y float64) GcvSize2f64_ { - return NewGcvSize2f64_(float64(x), float64(y)) -} - -// Convert Mat, which defined by SWIG, to *mat64.Dense. -// The reason is the latter is much easier to handle -// in Go. -// GcvMat is assumed to be 2-dimensional matrix. -func MatToMat64(mat Mat) *mat64.Dense { - col := mat.GetCols() - row := mat.GetRows() - - data := []float64{} - - for i := 0; i < row; i++ { - for j := 0; j < col; j++ { - if fltPtr, ok := mat.GcvAtf64(i, j).(*float64); ok { - data = append(data, *fltPtr) - } else { - panic("Non *float64 passed to MatToMat64") - } - - } - } - - return mat64.NewDense(row, col, data) -} - -// Convert *mat64.Dense to Mat -func ToMat(mat *mat64.Dense) Mat { - row, col := mat.Dims() - - rawData := NewGcvFloat64Vector(int64(row * col)) - - for i := 0; i < row; i++ { - for j := 0; j < col; j++ { - rawData.Set(i*col+j, mat.At(i, j)) - } - } - - return ToMat_(row, col, rawData) -} diff --git a/gocv/gocv.swigcxx b/gocv/gocv.swigcxx index b56bc86..4b5151f 100644 --- a/gocv/gocv.swigcxx +++ b/gocv/gocv.swigcxx @@ -1,8 +1,4 @@ %module gocv -%{ -#include "gocv_calib3d.hpp" -%} - %include "gocv_core.i" -%include "gocv_calib3d.hpp" +%include "gocv_calib3d.i" diff --git a/gocv/gocv_calib3d.i b/gocv/gocv_calib3d.i new file mode 100644 index 0000000..9ca1bc3 --- /dev/null +++ b/gocv/gocv_calib3d.i @@ -0,0 +1,5 @@ +%{ +#include "gocv_calib3d.hpp" +%} + +%include "gocv_calib3d.hpp" diff --git a/gocv/gocv_core.go b/gocv/gocv_core.go new file mode 100644 index 0000000..05ab78c --- /dev/null +++ b/gocv/gocv_core.go @@ -0,0 +1,69 @@ +package gocv + +// #cgo CXXFLAGS: -std=c++11 +// #cgo darwin pkg-config: opencv +import "C" +import "github.com/gonum/matrix/mat64" + +func NewGcvPoint3f32(x, y, z float64) GcvPoint3f32_ { + return NewGcvPoint3f32_(float32(x), float32(y), float32(z)) +} + +func NewGcvPoint3f64(x, y, z float64) GcvPoint3f64_ { + return NewGcvPoint3f64_(float64(x), float64(y), float64(z)) +} + +func NewGcvPoint2f32(x, y float64) GcvPoint2f32_ { + return NewGcvPoint2f32_(float32(x), float32(y)) +} + +func NewGcvPoint2f64(x, y float64) GcvPoint2f64_ { + return NewGcvPoint2f64_(float64(x), float64(y)) +} + +func NewGcvSize2f32(x, y float64) GcvSize2f32_ { + return NewGcvSize2f32_(float32(x), float32(y)) +} + +func NewGcvSize2f64(x, y float64) GcvSize2f64_ { + return NewGcvSize2f64_(float64(x), float64(y)) +} + +// Convert Mat, which defined by SWIG, to *mat64.Dense. +// The reason is the latter is much easier to handle +// in Go. +// GcvMat is assumed to be 2-dimensional matrix. +func MatToMat64(mat Mat) *mat64.Dense { + col := mat.GetCols() + row := mat.GetRows() + + data := []float64{} + + for i := 0; i < row; i++ { + for j := 0; j < col; j++ { + if fltPtr, ok := mat.GcvAtf64(i, j).(*float64); ok { + data = append(data, *fltPtr) + } else { + panic("Non *float64 passed to MatToMat64") + } + + } + } + + return mat64.NewDense(row, col, data) +} + +// Convert *mat64.Dense to Mat +func ToMat(mat *mat64.Dense) Mat { + row, col := mat.Dims() + + rawData := NewGcvFloat64Vector(int64(row * col)) + + for i := 0; i < row; i++ { + for j := 0; j < col; j++ { + rawData.Set(i*col+j, mat.At(i, j)) + } + } + + return ToMat_(row, col, rawData) +} diff --git a/gocv/gocv_test.go b/gocv/gocv_core_test.go similarity index 100% rename from gocv/gocv_test.go rename to gocv/gocv_core_test.go