Skip to content

Commit c4a0fde

Browse files
author
Chih-Wei Chang
committed
Rename type names to be more go-like.
1 parent fb12538 commit c4a0fde

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

gocv/README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ Wrap the core types in OpenCV.
55

66
## Supporting Types and Examples
77

8-
| OpenCV C++ | Go OpenCV | Constructor |
9-
|---------------|---------------|-------------------------------|
10-
| `cv::Point2i` | `GcvPoint2i` | `NewGcvPoint2i(x, y int)` |
11-
| `cv::Point2f` | `GcvPoint2f_` | `NewGcvPoint2f(x, y float32)` |
12-
| `cv::Point2d` | `GcvPoint2d_` | `NewGcvPoint2d(x, y float64)` |
13-
| `cv::Point3i` | `GcvPoint3i` | `NewGcvPoint3i(x, y, z int)` |
14-
| `cv::Point3f` | `GcvPoint3f_` | `NewGcvPoint3f(x, y, z float32)` |
15-
| `cv::Point3d` | `GcvPoint3d_` | `NewGcvPoint3d(x, y, z float64)` |
16-
| `cv::Size2i` | `GcvSize2i` | `NewGcvSize2i(x, y int)` |
17-
| `cv::Size2f` | `GcvSize2f_` | `NewGcvSize2f(x, y float32)` |
18-
| `cv::Size2d` | `GcvSize2d_` | `NewGcvSize2d(x, y float64)` |
8+
| OpenCV C++ | Go OpenCV | Constructor |
9+
|---------------|-----------------|-------------------------------|
10+
| `cv::Point2i` | `GcvPoint2i` | `NewGcvPoint2i(x, y int)` |
11+
| `cv::Point2f` | `GcvPoint2f32_` | `NewGcvPoint2f32(x, y float64)` |
12+
| `cv::Point2d` | `GcvPoint2f64_` | `NewGcvPoint2f64(x, y float64)` |
13+
| `cv::Point3i` | `GcvPoint3i` | `NewGcvPoint3i(x, y, z int)` |
14+
| `cv::Point3f` | `GcvPoint3f32_` | `NewGcvPoint3f32(x, y, z float64)` |
15+
| `cv::Point3d` | `GcvPoint3f64_` | `NewGcvPoint3f64(x, y, z float64)` |
16+
| `cv::Size2i` | `GcvSize2i` | `NewGcvSize2i(x, y int)` |
17+
| `cv::Size2f` | `GcvSize2f32_` | `NewGcvSize2f64(x, y float64)` |
18+
| `cv::Size2d` | `GcvSize2f64_` | `NewGcvSize2f64(x, y float64)` |
1919

2020
----------
2121

2222
### Note for Renamed Types
2323

2424
Some of the types are renamed to `*_`. The reason is that we'd like to wrap a better interface for them.
25-
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.
25+
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.
2626
After wrapping an extra level, we are now able to pass `int`, `float32`, and `float64` to these methods.
2727
Also note that **renaming doesn't affect any usage**, except you are manipulating the types yourself.

gocv/gocv.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ package gocv
55
import "C"
66
import "github.com/gonum/matrix/mat64"
77

8-
func NewGcvPoint3f(x, y, z float64) GcvPoint3f_ {
9-
return NewGcvPoint3f_(float32(x), float32(y), float32(z))
8+
func NewGcvPoint3f32(x, y, z float64) GcvPoint3f32_ {
9+
return NewGcvPoint3f32_(float32(x), float32(y), float32(z))
1010
}
1111

12-
func NewGcvPoint3d(x, y, z float64) GcvPoint3d_ {
13-
return NewGcvPoint3d_(float64(x), float64(y), float64(z))
12+
func NewGcvPoint3f64(x, y, z float64) GcvPoint3f64_ {
13+
return NewGcvPoint3f64_(float64(x), float64(y), float64(z))
1414
}
1515

16-
func NewGcvPoint2f(x, y float64) GcvPoint2f_ {
17-
return NewGcvPoint2f_(float32(x), float32(y))
16+
func NewGcvPoint2f32(x, y float64) GcvPoint2f32_ {
17+
return NewGcvPoint2f32_(float32(x), float32(y))
1818
}
1919

20-
func NewGcvPoint2d(x, y float64) GcvPoint2d_ {
21-
return NewGcvPoint2d_(float64(x), float64(y))
20+
func NewGcvPoint2f64(x, y float64) GcvPoint2f64_ {
21+
return NewGcvPoint2f64_(float64(x), float64(y))
2222
}
2323

24-
func NewGcvSize2f(x, y float64) GcvSize2f_ {
25-
return NewGcvSize2f_(float32(x), float32(y))
24+
func NewGcvSize2f32(x, y float64) GcvSize2f32_ {
25+
return NewGcvSize2f32_(float32(x), float32(y))
2626
}
2727

28-
func NewGcvSize2d(x, y float64) GcvSize2d_ {
29-
return NewGcvSize2d_(float64(x), float64(y))
28+
func NewGcvSize2f64(x, y float64) GcvSize2f64_ {
29+
return NewGcvSize2f64_(float64(x), float64(y))
3030
}
3131

3232
// Convert Mat, which defined by SWIG, to mat64.Dense.
@@ -41,7 +41,7 @@ func MatToMat64(mat Mat) *mat64.Dense {
4141

4242
for i := 0; i < row; i++ {
4343
for j := 0; j < col; j++ {
44-
if fltPtr, ok := mat.GcvAtd(i, j).(*float64); ok {
44+
if fltPtr, ok := mat.GcvAtf64(i, j).(*float64); ok {
4545
data = append(data, *fltPtr)
4646
} else {
4747
panic("Non *float64 passed to MatToMat64")

gocv/gocv_calib3d.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ func GcvInitCameraMatrix2D(objPts, imgPts *mat64.Dense) (camMat *mat64.Dense) {
1818
panic("Invalid dimensions for objPts and imgPts")
1919
}
2020

21-
objPtsVec := NewGcvPoint3fVector(int64(nObjPts))
22-
imgPtsVec := NewGcvPoint2fVector(int64(nObjPts))
21+
objPtsVec := NewGcvPoint3f32Vector(int64(nObjPts))
22+
imgPtsVec := NewGcvPoint2f32Vector(int64(nObjPts))
2323

2424
for i := 0; i < nObjPts; i++ {
25-
objPtsVec.Set(i, NewGcvPoint3f(
25+
objPtsVec.Set(i, NewGcvPoint3f32(
2626
objPts.At(i, 0), objPts.At(i, 1), objPts.At(i, 2)))
2727
}
2828

2929
for i := 0; i < nObjPts; i++ {
30-
imgPtsVec.Set(i, NewGcvPoint2f(
30+
imgPtsVec.Set(i, NewGcvPoint2f32(
3131
imgPts.At(i, 0), imgPts.At(i, 1)))
3232
}
3333

gocv/gocv_core.i

+10-10
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,18 @@ namespace cv {
175175

176176

177177
%template(GcvSize2i) Size_<int>;
178-
%template(GcvSize2d_) Size_<double>;
179-
%template(GcvSize2f_) Size_<float>;
178+
%template(GcvSize2f32_) Size_<float>;
179+
%template(GcvSize2f64_) Size_<double>;
180180

181181
%template(GcvRect) Rect_<int>;
182182

183183
%template(GcvPoint2i) Point_<int>;
184-
%template(GcvPoint2f_) Point_<float>;
185-
%template(GcvPoint2d_) Point_<double>;
184+
%template(GcvPoint2f32_) Point_<float>;
185+
%template(GcvPoint2f64_) Point_<double>;
186186

187187
%template(GcvPoint3i) Point3_<int>;
188-
%template(GcvPoint3f_) Point3_<float>;
189-
%template(GcvPoint3d_) Point3_<double>;
188+
%template(GcvPoint3f32_) Point3_<float>;
189+
%template(GcvPoint3f64_) Point3_<double>;
190190

191191

192192
/* ----------------- Mat ----------------- */
@@ -272,8 +272,8 @@ namespace cv {
272272
template<typename _Tp> _Tp& at(cv::Point pt);
273273
template<typename _Tp> const _Tp& at(cv::Point pt) const;
274274

275-
%template(gcvAtf) at<float>;
276-
%template(gcvAtd) at<double>;
275+
%template(gcvAtf32) at<float>;
276+
%template(gcvAtf64) at<double>;
277277

278278
/*! includes several bit-fields:
279279
- the magic signature
@@ -291,8 +291,8 @@ namespace cv {
291291

292292
/* Additional STL types */
293293
namespace std {
294-
%template(GcvPoint3fVector) vector<cv::Point3f>;
295-
%template(GcvPoint2fVector) vector<cv::Point2f>;
294+
%template(GcvPoint3f32Vector) vector<cv::Point3f>;
295+
%template(GcvPoint2f32Vector) vector<cv::Point2f>;
296296

297297
%template(GcvIntVector) vector<int>;
298298
%template(GcvFloatVector) vector<float>;

gocv/gocv_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import (
77
"github.com/gonum/matrix/mat64"
88
)
99

10-
func TestNewGcvPoint3f(t *testing.T) {
11-
pt := NewGcvPoint3f(3, 1, 2)
10+
func TestNewGcvPoint3f32(t *testing.T) {
11+
pt := NewGcvPoint3f32(3, 1, 2)
1212
spew.Dump(pt)
1313
}
1414

15-
func TestNewGcvPoint2f(t *testing.T) {
16-
pt := NewGcvPoint2f(3, 1)
15+
func TestNewGcvPoint2f32(t *testing.T) {
16+
pt := NewGcvPoint2f32(3, 1)
1717
spew.Dump(pt)
1818
}
1919

20-
func TestNewGcvSize2d(t *testing.T) {
21-
size := NewGcvSize2d(3, 1)
20+
func TestNewGcvSize2f64(t *testing.T) {
21+
size := NewGcvSize2f64(3, 1)
2222
spew.Dump(size)
2323
}
2424

0 commit comments

Comments
 (0)