Better wrapping and documentation.
This commit is contained in:
parent
a2e19543f7
commit
b7a619ff90
7 changed files with 113 additions and 53 deletions
31
README.md
31
README.md
|
|
@ -15,7 +15,8 @@ Install Go and OpenCV, you might want to install both of them via `apt-get` or `
|
||||||
|
|
||||||
```
|
```
|
||||||
go get github.com/lazywei/go-opencv
|
go get github.com/lazywei/go-opencv
|
||||||
cd ${GoOpenCVRoot}/samples && go run hellocv.go
|
cd $GOPATH/src/github.com/lazywei/go-opencv/samples
|
||||||
|
go run hellocv.go
|
||||||
```
|
```
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
@ -29,7 +30,7 @@ cd ${GoOpenCVRoot}/samples && go run hellocv.go
|
||||||
# include\opencv --> ${MinGWRoot}\include\opencv
|
# include\opencv --> ${MinGWRoot}\include\opencv
|
||||||
# include\opencv2 --> ${MinGWRoot}\include\opencv2
|
# include\opencv2 --> ${MinGWRoot}\include\opencv2
|
||||||
|
|
||||||
go get code.google.com/p/go-opencv/trunk/opencv
|
go get github.com/lazywei/go-opencv
|
||||||
cd ${GoOpenCVRoot}/trunk/samples && go run hellocv.go
|
cd ${GoOpenCVRoot}/trunk/samples && go run hellocv.go
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -39,7 +40,7 @@ After OpenCV 2.x+, the core team no longer develop and maintain C API. Therefore
|
||||||
|
|
||||||
If you want to use CV2's API, please refer to the code under `opencv2/` directory. There has no too much document for CV2 wrapper yet, but you can still find the usage example in `*_test.go`.
|
If you want to use CV2's API, please refer to the code under `opencv2/` directory. There has no too much document for CV2 wrapper yet, but you can still find the usage example in `*_test.go`.
|
||||||
|
|
||||||
Note that the basic data structures in OpenCV (e.g., `cv::Mat`, `cv::Point3f`) hasn't been wrapped fully yet. For now, we have some specific wrappers. We will try to wrapped those data structures fully as soon as possible.
|
Note that the basic data structures in OpenCV (e.g., `cv::Mat`, `cv::Point3f`) are wrapped partially for now. For more detail on how to use these types, please refer to [GcvCore's README](opencv2/gcv_core/README.md).
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|
@ -48,23 +49,23 @@ Note that the basic data structures in OpenCV (e.g., `cv::Mat`, `cv::Point3f`) h
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/lazywei/go-opencv/opencv2/gcv_utils"
|
import "github.com/lazywei/go-opencv/opencv2/gcv_core"
|
||||||
import "github.com/lazywei/go-opencv/opencv2/gcv_calib3d"
|
import "github.com/lazywei/go-opencv/opencv2/gcv_calib3d"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
objPts := gcv_utils.NewGcvPoint3fVector(int64(4))
|
objPts := gcv_core.NewGcvPoint3fVector(int64(4))
|
||||||
objPts.Set(0, gcv_utils.GetPoint3f(0, 25, 0))
|
objPts.Set(0, gcv_core.NewGcvPoint3f(0, 25, 0))
|
||||||
objPts.Set(1, gcv_utils.GetPoint3f(0, -25, 0))
|
objPts.Set(1, gcv_core.NewGcvPoint3f(0, -25, 0))
|
||||||
objPts.Set(2, gcv_utils.GetPoint3f(-47, 25, 0))
|
objPts.Set(2, gcv_core.NewGcvPoint3f(-47, 25, 0))
|
||||||
objPts.Set(3, gcv_utils.GetPoint3f(-47, -25, 0))
|
objPts.Set(3, gcv_core.NewGcvPoint3f(-47, -25, 0))
|
||||||
|
|
||||||
imgPts := gcv_utils.NewGcvPoint2fVector(int64(4))
|
imgPts := gcv_core.NewGcvPoint2fVector(int64(4))
|
||||||
imgPts.Set(0, gcv_utils.GetPoint2f(1136.4140625, 1041.89208984))
|
imgPts.Set(0, gcv_core.NewGcvPoint2f(1136.4140625, 1041.89208984))
|
||||||
imgPts.Set(1, gcv_utils.GetPoint2f(1845.33190918, 671.39581299))
|
imgPts.Set(1, gcv_core.NewGcvPoint2f(1845.33190918, 671.39581299))
|
||||||
imgPts.Set(2, gcv_utils.GetPoint2f(302.73373413, 634.79998779))
|
imgPts.Set(2, gcv_core.NewGcvPoint2f(302.73373413, 634.79998779))
|
||||||
imgPts.Set(3, gcv_utils.GetPoint2f(1051.46154785, 352.76107788))
|
imgPts.Set(3, gcv_core.NewGcvPoint2f(1051.46154785, 352.76107788))
|
||||||
|
|
||||||
cameraMatrix := GcvInitCameraMatrix2D(objPts, imgPts)
|
GcvInitCameraMatrix2D(objPts, imgPts)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,48 +19,34 @@ import "github.com/lazywei/go-opencv/opencv2/gcv_core"
|
||||||
|
|
||||||
func TestGcvInitCameraMatrix2D(t *testing.T) {
|
func TestGcvInitCameraMatrix2D(t *testing.T) {
|
||||||
objPts := gcv_core.NewGcvPoint3fVector(int64(4))
|
objPts := gcv_core.NewGcvPoint3fVector(int64(4))
|
||||||
objPts.Set(0, gcv_core.NewGcvPoint3f(
|
objPts.Set(0, gcv_core.NewGcvPoint3f(0, 25, 0))
|
||||||
float32(0), float32(25), float32(0)))
|
objPts.Set(1, gcv_core.NewGcvPoint3f(0, -25, 0))
|
||||||
objPts.Set(1, gcv_core.NewGcvPoint3f(
|
objPts.Set(2, gcv_core.NewGcvPoint3f(-47, 25, 0))
|
||||||
float32(0), float32(-25), float32(0)))
|
objPts.Set(3, gcv_core.NewGcvPoint3f(-47, -25, 0))
|
||||||
objPts.Set(2, gcv_core.NewGcvPoint3f(
|
|
||||||
float32(-47), float32(25), float32(0)))
|
|
||||||
objPts.Set(3, gcv_core.NewGcvPoint3f(
|
|
||||||
float32(-47), float32(-25), float32(0)))
|
|
||||||
|
|
||||||
imgPts := gcv_core.NewGcvPoint2fVector(int64(4))
|
imgPts := gcv_core.NewGcvPoint2fVector(int64(4))
|
||||||
imgPts.Set(0, gcv_core.NewGcvPoint2f(
|
imgPts.Set(0, gcv_core.NewGcvPoint2f(1136.4140625, 1041.89208984))
|
||||||
float32(1136.4140625), float32(1041.89208984)))
|
imgPts.Set(1, gcv_core.NewGcvPoint2f(1845.33190918, 671.39581299))
|
||||||
imgPts.Set(1, gcv_core.NewGcvPoint2f(
|
imgPts.Set(2, gcv_core.NewGcvPoint2f(302.73373413, 634.79998779))
|
||||||
float32(1845.33190918), float32(671.39581299)))
|
imgPts.Set(3, gcv_core.NewGcvPoint2f(1051.46154785, 352.76107788))
|
||||||
imgPts.Set(2, gcv_core.NewGcvPoint2f(
|
|
||||||
float32(302.73373413), float32(634.79998779)))
|
|
||||||
imgPts.Set(3, gcv_core.NewGcvPoint2f(
|
|
||||||
float32(1051.46154785), float32(352.76107788)))
|
|
||||||
|
|
||||||
GcvInitCameraMatrix2D(objPts, imgPts)
|
GcvInitCameraMatrix2D(objPts, imgPts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGcvCalibrateCamera(t *testing.T) {
|
func TestGcvCalibrateCamera(t *testing.T) {
|
||||||
objPts := gcv_core.NewGcvPoint3fVector(int64(4))
|
objPts := gcv_core.NewGcvPoint3fVector(int64(4))
|
||||||
objPts.Set(0, gcv_core.NewGcvPoint3f(
|
objPts.Set(0, gcv_core.NewGcvPoint3f(0, 25, 0))
|
||||||
float32(0), float32(25), float32(0)))
|
objPts.Set(1, gcv_core.NewGcvPoint3f(0, -25, 0))
|
||||||
objPts.Set(1, gcv_core.NewGcvPoint3f(
|
objPts.Set(2, gcv_core.NewGcvPoint3f(-47, 25, 0))
|
||||||
float32(0), float32(-25), float32(0)))
|
objPts.Set(3, gcv_core.NewGcvPoint3f(-47, -25, 0))
|
||||||
objPts.Set(2, gcv_core.NewGcvPoint3f(
|
|
||||||
float32(-47), float32(25), float32(0)))
|
|
||||||
objPts.Set(3, gcv_core.NewGcvPoint3f(
|
|
||||||
float32(-47), float32(-25), float32(0)))
|
|
||||||
|
|
||||||
imgPts := gcv_core.NewGcvPoint2fVector(int64(4))
|
imgPts := gcv_core.NewGcvPoint2fVector(int64(4))
|
||||||
imgPts.Set(0, gcv_core.NewGcvPoint2f(
|
imgPts.Set(0, gcv_core.NewGcvPoint2f(1136.4140625, 1041.89208984))
|
||||||
float32(1136.4140625), float32(1041.89208984)))
|
imgPts.Set(1, gcv_core.NewGcvPoint2f(1845.33190918, 671.39581299))
|
||||||
imgPts.Set(1, gcv_core.NewGcvPoint2f(
|
imgPts.Set(2, gcv_core.NewGcvPoint2f(302.73373413, 634.79998779))
|
||||||
float32(1845.33190918), float32(671.39581299)))
|
imgPts.Set(3, gcv_core.NewGcvPoint2f(1051.46154785, 352.76107788))
|
||||||
imgPts.Set(2, gcv_core.NewGcvPoint2f(
|
|
||||||
float32(302.73373413), float32(634.79998779)))
|
GcvInitCameraMatrix2D(objPts, imgPts)
|
||||||
imgPts.Set(3, gcv_core.NewGcvPoint2f(
|
|
||||||
float32(1051.46154785), float32(352.76107788)))
|
|
||||||
|
|
||||||
imgSize := gcv_core.NewGcvSize2i(1920, 1080)
|
imgSize := gcv_core.NewGcvSize2i(1920, 1080)
|
||||||
|
|
||||||
|
|
|
||||||
27
opencv2/gcv_core/README.md
Normal file
27
opencv2/gcv_core/README.md
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
Gcv Core
|
||||||
|
========
|
||||||
|
|
||||||
|
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)` |
|
||||||
|
|
||||||
|
----------
|
||||||
|
|
||||||
|
### 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.
|
||||||
|
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.
|
||||||
0
opencv2/gcv_core/gcv_core.cpp
Normal file
0
opencv2/gcv_core/gcv_core.cpp
Normal file
|
|
@ -3,3 +3,27 @@ package gcv_core
|
||||||
// #cgo CXXFLAGS: -std=c++11
|
// #cgo CXXFLAGS: -std=c++11
|
||||||
// #cgo darwin pkg-config: opencv
|
// #cgo darwin pkg-config: opencv
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
func NewGcvPoint3f(x, y, z float32) GcvPoint3f_ {
|
||||||
|
return NewGcvPoint3f_(float32(x), float32(y), float32(z))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGcvPoint3d(x, y, z float64) GcvPoint3d_ {
|
||||||
|
return NewGcvPoint3d_(float64(x), float64(y), float64(z))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGcvPoint2f(x, y float32) GcvPoint2f_ {
|
||||||
|
return NewGcvPoint2f_(float32(x), float32(y))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGcvPoint2d(x, y float64) GcvPoint2d_ {
|
||||||
|
return NewGcvPoint2d_(float64(x), float64(y))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGcvSize2f(x, y float32) GcvSize2f_ {
|
||||||
|
return NewGcvSize2f_(float32(x), float32(y))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGcvSize2d(x, y float64) GcvSize2d_ {
|
||||||
|
return NewGcvSize2d_(float64(x), float64(y))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,18 +178,18 @@ namespace cv {
|
||||||
|
|
||||||
|
|
||||||
%template(GcvSize2i) Size_<int>;
|
%template(GcvSize2i) Size_<int>;
|
||||||
%template(GcvSize2d) Size_<double>;
|
%template(GcvSize2d_) Size_<double>;
|
||||||
%template(GcvSize2f) Size_<float>;
|
%template(GcvSize2f_) Size_<float>;
|
||||||
|
|
||||||
%template(GcvRect) Rect_<int>;
|
%template(GcvRect) Rect_<int>;
|
||||||
|
|
||||||
%template(GcvPoint2i) Point_<int>;
|
%template(GcvPoint2i) Point_<int>;
|
||||||
%template(GcvPoint2f) Point_<float>;
|
%template(GcvPoint2f_) Point_<float>;
|
||||||
%template(GcvPoint2d) Point_<double>;
|
%template(GcvPoint2d_) Point_<double>;
|
||||||
|
|
||||||
%template(GcvPoint3i) Point3_<int>;
|
%template(GcvPoint3i) Point3_<int>;
|
||||||
%template(GcvPoint3f) Point3_<float>;
|
%template(GcvPoint3f_) Point3_<float>;
|
||||||
%template(GcvPoint3d) Point3_<double>;
|
%template(GcvPoint3d_) Point3_<double>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Additional STL types */
|
/* Additional STL types */
|
||||||
|
|
|
||||||
22
opencv2/gcv_core/gcv_core_test.go
Normal file
22
opencv2/gcv_core/gcv_core_test.go
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
package gcv_core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewGcvPoint3f(t *testing.T) {
|
||||||
|
pt := NewGcvPoint3f(3, 1, 2)
|
||||||
|
spew.Dump(pt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewGcvPoint2f(t *testing.T) {
|
||||||
|
pt := NewGcvPoint2f(3, 1)
|
||||||
|
spew.Dump(pt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewGcvSize2d(t *testing.T) {
|
||||||
|
size := NewGcvSize2d(3, 1)
|
||||||
|
spew.Dump(size)
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue