Rename type names to be more go-like.

This commit is contained in:
Chih-Wei Chang 2015-02-16 17:00:57 +08:00
parent fb12538882
commit c4a0fdeeab
5 changed files with 45 additions and 45 deletions

View file

@ -6,22 +6,22 @@ Wrap the core types in OpenCV.
## Supporting Types and Examples ## Supporting Types and Examples
| OpenCV C++ | Go OpenCV | Constructor | | OpenCV C++ | Go OpenCV | Constructor |
|---------------|---------------|-------------------------------| |---------------|-----------------|-------------------------------|
| `cv::Point2i` | `GcvPoint2i` | `NewGcvPoint2i(x, y int)` | | `cv::Point2i` | `GcvPoint2i` | `NewGcvPoint2i(x, y int)` |
| `cv::Point2f` | `GcvPoint2f_` | `NewGcvPoint2f(x, y float32)` | | `cv::Point2f` | `GcvPoint2f32_` | `NewGcvPoint2f32(x, y float64)` |
| `cv::Point2d` | `GcvPoint2d_` | `NewGcvPoint2d(x, y float64)` | | `cv::Point2d` | `GcvPoint2f64_` | `NewGcvPoint2f64(x, y float64)` |
| `cv::Point3i` | `GcvPoint3i` | `NewGcvPoint3i(x, y, z int)` | | `cv::Point3i` | `GcvPoint3i` | `NewGcvPoint3i(x, y, z int)` |
| `cv::Point3f` | `GcvPoint3f_` | `NewGcvPoint3f(x, y, z float32)` | | `cv::Point3f` | `GcvPoint3f32_` | `NewGcvPoint3f32(x, y, z float64)` |
| `cv::Point3d` | `GcvPoint3d_` | `NewGcvPoint3d(x, y, z float64)` | | `cv::Point3d` | `GcvPoint3f64_` | `NewGcvPoint3f64(x, y, z float64)` |
| `cv::Size2i` | `GcvSize2i` | `NewGcvSize2i(x, y int)` | | `cv::Size2i` | `GcvSize2i` | `NewGcvSize2i(x, y int)` |
| `cv::Size2f` | `GcvSize2f_` | `NewGcvSize2f(x, y float32)` | | `cv::Size2f` | `GcvSize2f32_` | `NewGcvSize2f64(x, y float64)` |
| `cv::Size2d` | `GcvSize2d_` | `NewGcvSize2d(x, y float64)` | | `cv::Size2d` | `GcvSize2f64_` | `NewGcvSize2f64(x, y float64)` |
---------- ----------
### Note for Renamed Types ### 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. 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. 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. Also note that **renaming doesn't affect any usage**, except you are manipulating the types yourself.

View file

@ -5,28 +5,28 @@ package gocv
import "C" import "C"
import "github.com/gonum/matrix/mat64" import "github.com/gonum/matrix/mat64"
func NewGcvPoint3f(x, y, z float64) GcvPoint3f_ { func NewGcvPoint3f32(x, y, z float64) GcvPoint3f32_ {
return NewGcvPoint3f_(float32(x), float32(y), float32(z)) return NewGcvPoint3f32_(float32(x), float32(y), float32(z))
} }
func NewGcvPoint3d(x, y, z float64) GcvPoint3d_ { func NewGcvPoint3f64(x, y, z float64) GcvPoint3f64_ {
return NewGcvPoint3d_(float64(x), float64(y), float64(z)) return NewGcvPoint3f64_(float64(x), float64(y), float64(z))
} }
func NewGcvPoint2f(x, y float64) GcvPoint2f_ { func NewGcvPoint2f32(x, y float64) GcvPoint2f32_ {
return NewGcvPoint2f_(float32(x), float32(y)) return NewGcvPoint2f32_(float32(x), float32(y))
} }
func NewGcvPoint2d(x, y float64) GcvPoint2d_ { func NewGcvPoint2f64(x, y float64) GcvPoint2f64_ {
return NewGcvPoint2d_(float64(x), float64(y)) return NewGcvPoint2f64_(float64(x), float64(y))
} }
func NewGcvSize2f(x, y float64) GcvSize2f_ { func NewGcvSize2f32(x, y float64) GcvSize2f32_ {
return NewGcvSize2f_(float32(x), float32(y)) return NewGcvSize2f32_(float32(x), float32(y))
} }
func NewGcvSize2d(x, y float64) GcvSize2d_ { func NewGcvSize2f64(x, y float64) GcvSize2f64_ {
return NewGcvSize2d_(float64(x), float64(y)) return NewGcvSize2f64_(float64(x), float64(y))
} }
// Convert Mat, which defined by SWIG, to mat64.Dense. // 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 i := 0; i < row; i++ {
for j := 0; j < col; j++ { 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) data = append(data, *fltPtr)
} else { } else {
panic("Non *float64 passed to MatToMat64") panic("Non *float64 passed to MatToMat64")

View file

@ -18,16 +18,16 @@ func GcvInitCameraMatrix2D(objPts, imgPts *mat64.Dense) (camMat *mat64.Dense) {
panic("Invalid dimensions for objPts and imgPts") panic("Invalid dimensions for objPts and imgPts")
} }
objPtsVec := NewGcvPoint3fVector(int64(nObjPts)) objPtsVec := NewGcvPoint3f32Vector(int64(nObjPts))
imgPtsVec := NewGcvPoint2fVector(int64(nObjPts)) imgPtsVec := NewGcvPoint2f32Vector(int64(nObjPts))
for i := 0; i < nObjPts; i++ { 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))) objPts.At(i, 0), objPts.At(i, 1), objPts.At(i, 2)))
} }
for i := 0; i < nObjPts; i++ { for i := 0; i < nObjPts; i++ {
imgPtsVec.Set(i, NewGcvPoint2f( imgPtsVec.Set(i, NewGcvPoint2f32(
imgPts.At(i, 0), imgPts.At(i, 1))) imgPts.At(i, 0), imgPts.At(i, 1)))
} }

View file

@ -175,18 +175,18 @@ namespace cv {
%template(GcvSize2i) Size_<int>; %template(GcvSize2i) Size_<int>;
%template(GcvSize2d_) Size_<double>; %template(GcvSize2f32_) Size_<float>;
%template(GcvSize2f_) Size_<float>; %template(GcvSize2f64_) Size_<double>;
%template(GcvRect) Rect_<int>; %template(GcvRect) Rect_<int>;
%template(GcvPoint2i) Point_<int>; %template(GcvPoint2i) Point_<int>;
%template(GcvPoint2f_) Point_<float>; %template(GcvPoint2f32_) Point_<float>;
%template(GcvPoint2d_) Point_<double>; %template(GcvPoint2f64_) Point_<double>;
%template(GcvPoint3i) Point3_<int>; %template(GcvPoint3i) Point3_<int>;
%template(GcvPoint3f_) Point3_<float>; %template(GcvPoint3f32_) Point3_<float>;
%template(GcvPoint3d_) Point3_<double>; %template(GcvPoint3f64_) Point3_<double>;
/* ----------------- Mat ----------------- */ /* ----------------- Mat ----------------- */
@ -272,8 +272,8 @@ namespace cv {
template<typename _Tp> _Tp& at(cv::Point pt); template<typename _Tp> _Tp& at(cv::Point pt);
template<typename _Tp> const _Tp& at(cv::Point pt) const; template<typename _Tp> const _Tp& at(cv::Point pt) const;
%template(gcvAtf) at<float>; %template(gcvAtf32) at<float>;
%template(gcvAtd) at<double>; %template(gcvAtf64) at<double>;
/*! includes several bit-fields: /*! includes several bit-fields:
- the magic signature - the magic signature
@ -291,8 +291,8 @@ namespace cv {
/* Additional STL types */ /* Additional STL types */
namespace std { namespace std {
%template(GcvPoint3fVector) vector<cv::Point3f>; %template(GcvPoint3f32Vector) vector<cv::Point3f>;
%template(GcvPoint2fVector) vector<cv::Point2f>; %template(GcvPoint2f32Vector) vector<cv::Point2f>;
%template(GcvIntVector) vector<int>; %template(GcvIntVector) vector<int>;
%template(GcvFloatVector) vector<float>; %template(GcvFloatVector) vector<float>;

View file

@ -7,18 +7,18 @@ import (
"github.com/gonum/matrix/mat64" "github.com/gonum/matrix/mat64"
) )
func TestNewGcvPoint3f(t *testing.T) { func TestNewGcvPoint3f32(t *testing.T) {
pt := NewGcvPoint3f(3, 1, 2) pt := NewGcvPoint3f32(3, 1, 2)
spew.Dump(pt) spew.Dump(pt)
} }
func TestNewGcvPoint2f(t *testing.T) { func TestNewGcvPoint2f32(t *testing.T) {
pt := NewGcvPoint2f(3, 1) pt := NewGcvPoint2f32(3, 1)
spew.Dump(pt) spew.Dump(pt)
} }
func TestNewGcvSize2d(t *testing.T) { func TestNewGcvSize2f64(t *testing.T) {
size := NewGcvSize2d(3, 1) size := NewGcvSize2f64(3, 1)
spew.Dump(size) spew.Dump(size)
} }