Rename type names to be more go-like.
This commit is contained in:
parent
fb12538882
commit
c4a0fdeeab
5 changed files with 45 additions and 45 deletions
|
|
@ -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.
|
||||
|
|
|
|||
26
gocv/gocv.go
26
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")
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,18 +175,18 @@ namespace cv {
|
|||
|
||||
|
||||
%template(GcvSize2i) Size_<int>;
|
||||
%template(GcvSize2d_) Size_<double>;
|
||||
%template(GcvSize2f_) Size_<float>;
|
||||
%template(GcvSize2f32_) Size_<float>;
|
||||
%template(GcvSize2f64_) Size_<double>;
|
||||
|
||||
%template(GcvRect) Rect_<int>;
|
||||
|
||||
%template(GcvPoint2i) Point_<int>;
|
||||
%template(GcvPoint2f_) Point_<float>;
|
||||
%template(GcvPoint2d_) Point_<double>;
|
||||
%template(GcvPoint2f32_) Point_<float>;
|
||||
%template(GcvPoint2f64_) Point_<double>;
|
||||
|
||||
%template(GcvPoint3i) Point3_<int>;
|
||||
%template(GcvPoint3f_) Point3_<float>;
|
||||
%template(GcvPoint3d_) Point3_<double>;
|
||||
%template(GcvPoint3f32_) Point3_<float>;
|
||||
%template(GcvPoint3f64_) Point3_<double>;
|
||||
|
||||
|
||||
/* ----------------- Mat ----------------- */
|
||||
|
|
@ -272,8 +272,8 @@ namespace cv {
|
|||
template<typename _Tp> _Tp& at(cv::Point pt);
|
||||
template<typename _Tp> const _Tp& at(cv::Point pt) const;
|
||||
|
||||
%template(gcvAtf) at<float>;
|
||||
%template(gcvAtd) at<double>;
|
||||
%template(gcvAtf32) at<float>;
|
||||
%template(gcvAtf64) at<double>;
|
||||
|
||||
/*! includes several bit-fields:
|
||||
- the magic signature
|
||||
|
|
@ -291,8 +291,8 @@ namespace cv {
|
|||
|
||||
/* Additional STL types */
|
||||
namespace std {
|
||||
%template(GcvPoint3fVector) vector<cv::Point3f>;
|
||||
%template(GcvPoint2fVector) vector<cv::Point2f>;
|
||||
%template(GcvPoint3f32Vector) vector<cv::Point3f>;
|
||||
%template(GcvPoint2f32Vector) vector<cv::Point2f>;
|
||||
|
||||
%template(GcvIntVector) vector<int>;
|
||||
%template(GcvFloatVector) vector<float>;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue