diff --git a/gocv/README.md b/gocv/README.md index 898e4d5..a8cac6b 100644 --- a/gocv/README.md +++ b/gocv/README.md @@ -5,23 +5,23 @@ Wrap the core types in OpenCV. ## Supporting Types and Examples -| OpenCV C++ | Go OpenCV | Constructor | -|---------------|---------------|-------------------------------| -| `cv::Point2i` | `GcvPoint2i` | `NewGcvPoint2i(x, y int)` | -| `cv::Point2f` | `GcvPoint2f_` | `NewGcvPoint2f(x, y float32)` | -| `cv::Point2d` | `GcvPoint2d_` | `NewGcvPoint2d(x, y float64)` | -| `cv::Point3i` | `GcvPoint3i` | `NewGcvPoint3i(x, y, z int)` | -| `cv::Point3f` | `GcvPoint3f_` | `NewGcvPoint3f(x, y, z float32)` | -| `cv::Point3d` | `GcvPoint3d_` | `NewGcvPoint3d(x, y, z float64)` | -| `cv::Size2i` | `GcvSize2i` | `NewGcvSize2i(x, y int)` | -| `cv::Size2f` | `GcvSize2f_` | `NewGcvSize2f(x, y float32)` | -| `cv::Size2d` | `GcvSize2d_` | `NewGcvSize2d(x, y float64)` | +| OpenCV C++ | Go OpenCV | Constructor | +|---------------|-----------------|-------------------------------| +| `cv::Point2i` | `GcvPoint2i` | `NewGcvPoint2i(x, y int)` | +| `cv::Point2f` | `GcvPoint2f32_` | `NewGcvPoint2f32(x, y float64)` | +| `cv::Point2d` | `GcvPoint2f64_` | `NewGcvPoint2f64(x, y float64)` | +| `cv::Point3i` | `GcvPoint3i` | `NewGcvPoint3i(x, y, z int)` | +| `cv::Point3f` | `GcvPoint3f32_` | `NewGcvPoint3f32(x, y, z float64)` | +| `cv::Point3d` | `GcvPoint3f64_` | `NewGcvPoint3f64(x, y, z float64)` | +| `cv::Size2i` | `GcvSize2i` | `NewGcvSize2i(x, y int)` | +| `cv::Size2f` | `GcvSize2f32_` | `NewGcvSize2f64(x, y float64)` | +| `cv::Size2d` | `GcvSize2f64_` | `NewGcvSize2f64(x, y float64)` | ---------- ### Note for Renamed Types Some of the types are renamed to `*_`. The reason is that we'd like to wrap a better interface for them. -For example, the original `NewPoint2f` takes strictly two `float32`, and we are not able to pass `float64` or `int`, which doesn't make too much sense. +For example, the original `NewGcvPoint2f32` takes strictly two `float32`, and we are not able to pass `float64` or `int`, which doesn't make too much sense. After wrapping an extra level, we are now able to pass `int`, `float32`, and `float64` to these methods. Also note that **renaming doesn't affect any usage**, except you are manipulating the types yourself. diff --git a/gocv/gocv.go b/gocv/gocv.go index bfb12f9..82196d6 100644 --- a/gocv/gocv.go +++ b/gocv/gocv.go @@ -5,28 +5,28 @@ package gocv import "C" import "github.com/gonum/matrix/mat64" -func NewGcvPoint3f(x, y, z float64) GcvPoint3f_ { - return NewGcvPoint3f_(float32(x), float32(y), float32(z)) +func NewGcvPoint3f32(x, y, z float64) GcvPoint3f32_ { + return NewGcvPoint3f32_(float32(x), float32(y), float32(z)) } -func NewGcvPoint3d(x, y, z float64) GcvPoint3d_ { - return NewGcvPoint3d_(float64(x), float64(y), float64(z)) +func NewGcvPoint3f64(x, y, z float64) GcvPoint3f64_ { + return NewGcvPoint3f64_(float64(x), float64(y), float64(z)) } -func NewGcvPoint2f(x, y float64) GcvPoint2f_ { - return NewGcvPoint2f_(float32(x), float32(y)) +func NewGcvPoint2f32(x, y float64) GcvPoint2f32_ { + return NewGcvPoint2f32_(float32(x), float32(y)) } -func NewGcvPoint2d(x, y float64) GcvPoint2d_ { - return NewGcvPoint2d_(float64(x), float64(y)) +func NewGcvPoint2f64(x, y float64) GcvPoint2f64_ { + return NewGcvPoint2f64_(float64(x), float64(y)) } -func NewGcvSize2f(x, y float64) GcvSize2f_ { - return NewGcvSize2f_(float32(x), float32(y)) +func NewGcvSize2f32(x, y float64) GcvSize2f32_ { + return NewGcvSize2f32_(float32(x), float32(y)) } -func NewGcvSize2d(x, y float64) GcvSize2d_ { - return NewGcvSize2d_(float64(x), float64(y)) +func NewGcvSize2f64(x, y float64) GcvSize2f64_ { + return NewGcvSize2f64_(float64(x), float64(y)) } // Convert Mat, which defined by SWIG, to mat64.Dense. @@ -41,7 +41,7 @@ func MatToMat64(mat Mat) *mat64.Dense { for i := 0; i < row; i++ { for j := 0; j < col; j++ { - if fltPtr, ok := mat.GcvAtd(i, j).(*float64); ok { + if fltPtr, ok := mat.GcvAtf64(i, j).(*float64); ok { data = append(data, *fltPtr) } else { panic("Non *float64 passed to MatToMat64") diff --git a/gocv/gocv_calib3d.go b/gocv/gocv_calib3d.go index 624b79a..a49ca0e 100644 --- a/gocv/gocv_calib3d.go +++ b/gocv/gocv_calib3d.go @@ -18,16 +18,16 @@ func GcvInitCameraMatrix2D(objPts, imgPts *mat64.Dense) (camMat *mat64.Dense) { panic("Invalid dimensions for objPts and imgPts") } - objPtsVec := NewGcvPoint3fVector(int64(nObjPts)) - imgPtsVec := NewGcvPoint2fVector(int64(nObjPts)) + objPtsVec := NewGcvPoint3f32Vector(int64(nObjPts)) + imgPtsVec := NewGcvPoint2f32Vector(int64(nObjPts)) for i := 0; i < nObjPts; i++ { - objPtsVec.Set(i, NewGcvPoint3f( + objPtsVec.Set(i, NewGcvPoint3f32( objPts.At(i, 0), objPts.At(i, 1), objPts.At(i, 2))) } for i := 0; i < nObjPts; i++ { - imgPtsVec.Set(i, NewGcvPoint2f( + imgPtsVec.Set(i, NewGcvPoint2f32( imgPts.At(i, 0), imgPts.At(i, 1))) } diff --git a/gocv/gocv_core.i b/gocv/gocv_core.i index ee63dc6..f14232c 100644 --- a/gocv/gocv_core.i +++ b/gocv/gocv_core.i @@ -175,18 +175,18 @@ namespace cv { %template(GcvSize2i) Size_; - %template(GcvSize2d_) Size_; - %template(GcvSize2f_) Size_; + %template(GcvSize2f32_) Size_; + %template(GcvSize2f64_) Size_; %template(GcvRect) Rect_; %template(GcvPoint2i) Point_; - %template(GcvPoint2f_) Point_; - %template(GcvPoint2d_) Point_; + %template(GcvPoint2f32_) Point_; + %template(GcvPoint2f64_) Point_; %template(GcvPoint3i) Point3_; - %template(GcvPoint3f_) Point3_; - %template(GcvPoint3d_) Point3_; + %template(GcvPoint3f32_) Point3_; + %template(GcvPoint3f64_) Point3_; /* ----------------- Mat ----------------- */ @@ -272,8 +272,8 @@ namespace cv { template _Tp& at(cv::Point pt); template const _Tp& at(cv::Point pt) const; - %template(gcvAtf) at; - %template(gcvAtd) at; + %template(gcvAtf32) at; + %template(gcvAtf64) at; /*! includes several bit-fields: - the magic signature @@ -291,8 +291,8 @@ namespace cv { /* Additional STL types */ namespace std { - %template(GcvPoint3fVector) vector; - %template(GcvPoint2fVector) vector; + %template(GcvPoint3f32Vector) vector; + %template(GcvPoint2f32Vector) vector; %template(GcvIntVector) vector; %template(GcvFloatVector) vector; diff --git a/gocv/gocv_test.go b/gocv/gocv_test.go index bd0d775..dae57c7 100644 --- a/gocv/gocv_test.go +++ b/gocv/gocv_test.go @@ -7,18 +7,18 @@ import ( "github.com/gonum/matrix/mat64" ) -func TestNewGcvPoint3f(t *testing.T) { - pt := NewGcvPoint3f(3, 1, 2) +func TestNewGcvPoint3f32(t *testing.T) { + pt := NewGcvPoint3f32(3, 1, 2) spew.Dump(pt) } -func TestNewGcvPoint2f(t *testing.T) { - pt := NewGcvPoint2f(3, 1) +func TestNewGcvPoint2f32(t *testing.T) { + pt := NewGcvPoint2f32(3, 1) spew.Dump(pt) } -func TestNewGcvSize2d(t *testing.T) { - size := NewGcvSize2d(3, 1) +func TestNewGcvSize2f64(t *testing.T) { + size := NewGcvSize2f64(3, 1) spew.Dump(size) }