diff --git a/README.md b/README.md index 1018df8..cec9831 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Go OpenCV binding A Golang binding for [OpenCV](http://opencv.org/). -OpenCV 1.x C API bindings through CGO, and OpenCV 2+ C++ API through SWIG. +OpenCV 1.x C API bindings through CGO, and OpenCV 2+ C++ API ([`GoCV`](gocv/)) through SWIG. [**DISCLAIMER**](https://github.com/lazywei/go-opencv#disclaimer) @@ -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 -cd ${GoOpenCVRoot}/samples && go run hellocv.go +cd $GOPATH/src/github.com/lazywei/go-opencv/samples +go run hellocv.go ``` ### Windows @@ -29,17 +30,17 @@ cd ${GoOpenCVRoot}/samples && go run hellocv.go # include\opencv --> ${MinGWRoot}\include\opencv # 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 ``` -## [WIP] OpenCV2 +## [WIP] OpenCV2 (GoCV) -After OpenCV 2.x+, the core team no longer develop and maintain C API. Therefore, CGO will not be used in CV2 binding. Instead, we are using SWIG for wrapping. The support for OpenCV2 is currently under development. +After OpenCV 2.x+, the core team no longer develop and maintain C API. Therefore, CGO will not be used in CV2 binding. Instead, we are using SWIG for wrapping. The support for OpenCV2 is currently under development, and whole code will be placed under `gocv` package. -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 `gocv/` directory. There is no too many documents for CV2 wrapper yet, but you can still find the example usages 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. +Please also 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 [GoCV's README](gocv/README.md). ## Example @@ -48,23 +49,22 @@ Note that the basic data structures in OpenCV (e.g., `cv::Mat`, `cv::Point3f`) h ```go package main -import "github.com/lazywei/go-opencv/opencv2/gcv_utils" -import "github.com/lazywei/go-opencv/opencv2/gcv_calib3d" +import "github.com/lazywei/go-opencv/gocv" func main() { - objPts := gcv_utils.NewGcvPoint3fVector(int64(4)) - objPts.Set(0, gcv_utils.GetPoint3f(0, 25, 0)) - objPts.Set(1, gcv_utils.GetPoint3f(0, -25, 0)) - objPts.Set(2, gcv_utils.GetPoint3f(-47, 25, 0)) - objPts.Set(3, gcv_utils.GetPoint3f(-47, -25, 0)) + objPts := gocv.NewGcvPoint3fVector(int64(4)) + objPts.Set(0, gocv.NewGcvPoint3f(0, 25, 0)) + objPts.Set(1, gocv.NewGcvPoint3f(0, -25, 0)) + objPts.Set(2, gocv.NewGcvPoint3f(-47, 25, 0)) + objPts.Set(3, gocv.NewGcvPoint3f(-47, -25, 0)) - imgPts := gcv_utils.NewGcvPoint2fVector(int64(4)) - imgPts.Set(0, gcv_utils.GetPoint2f(1136.4140625, 1041.89208984)) - imgPts.Set(1, gcv_utils.GetPoint2f(1845.33190918, 671.39581299)) - imgPts.Set(2, gcv_utils.GetPoint2f(302.73373413, 634.79998779)) - imgPts.Set(3, gcv_utils.GetPoint2f(1051.46154785, 352.76107788)) + imgPts := gocv.NewGcvPoint2fVector(int64(4)) + imgPts.Set(0, gocv.NewGcvPoint2f(1136.4140625, 1041.89208984)) + imgPts.Set(1, gocv.NewGcvPoint2f(1845.33190918, 671.39581299)) + imgPts.Set(2, gocv.NewGcvPoint2f(302.73373413, 634.79998779)) + imgPts.Set(3, gocv.NewGcvPoint2f(1051.46154785, 352.76107788)) - cameraMatrix := GcvInitCameraMatrix2D(objPts, imgPts) + gocv.GcvInitCameraMatrix2D(objPts, imgPts) } ``` diff --git a/gocv/README.md b/gocv/README.md new file mode 100644 index 0000000..898e4d5 --- /dev/null +++ b/gocv/README.md @@ -0,0 +1,27 @@ +Go OpenCV (GOlang openCV) +======================= + +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. diff --git a/opencv2/gcv_calib3d/gcv_calib3d.cpp b/gocv/gocv.cpp similarity index 83% rename from opencv2/gcv_calib3d/gcv_calib3d.cpp rename to gocv/gocv.cpp index 19fbafb..3458147 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d.cpp +++ b/gocv/gocv.cpp @@ -3,7 +3,7 @@ #include #include -#include "gcv_calib3d.hpp" +#include "gocv.hpp" cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { cv::Mat cameraMatrix; @@ -15,11 +15,12 @@ cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { imgPtsArr.push_back(imgPts); cameraMatrix = cv::initCameraMatrix2D(objPtsArr, imgPtsArr, cv::Size(1920, 1080), 1); + std::cout << cameraMatrix.type() << std::endl; return cameraMatrix; } double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts, - std::vector imgSize, cv::Mat cameraMatrix) { + cv::Size imgSize, cv::Mat cameraMatrix) { std::vector objPtsArr; std::vector imgPtsArr; std::vector rvecs, tvecs; @@ -32,8 +33,7 @@ double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts, std::cout << "init Camera" << cameraMatrix << std::endl; - rtn = cv::calibrateCamera(objPtsArr, imgPtsArr, - cv::Size2i(imgSize[0], imgSize[1]), + rtn = cv::calibrateCamera(objPtsArr, imgPtsArr, imgSize, cameraMatrix, distCoeffs, rvecs, tvecs); std::cout << "final Camera" << cameraMatrix << std::endl; diff --git a/gocv/gocv.go b/gocv/gocv.go new file mode 100644 index 0000000..4f2e5f9 --- /dev/null +++ b/gocv/gocv.go @@ -0,0 +1,29 @@ +package gocv + +// #cgo CXXFLAGS: -std=c++11 +// #cgo darwin pkg-config: opencv +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)) +} diff --git a/opencv2/gcv_calib3d/gcv_calib3d.hpp b/gocv/gocv.hpp similarity index 79% rename from opencv2/gcv_calib3d/gcv_calib3d.hpp rename to gocv/gocv.hpp index 15d2295..3710c3c 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d.hpp +++ b/gocv/gocv.hpp @@ -8,4 +8,4 @@ typedef std::vector VecPoint2f; cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts); double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts, - std::vector imgSize, cv::Mat cameraMatrix); + cv::Size2i imgSize, cv::Mat cameraMatrix); diff --git a/gocv/gocv.swigcxx b/gocv/gocv.swigcxx new file mode 100644 index 0000000..be86413 --- /dev/null +++ b/gocv/gocv.swigcxx @@ -0,0 +1,278 @@ +%module gocv +%include "std_vector.i" + +%{ +#include "opencv2/core/types_c.h" +#include "opencv2/core/version.hpp" +#include "opencv2/core/core.hpp" +#include "gocv.hpp" +%} + +%include "gocv.hpp" + +/* Classes defined in core.hpp */ +namespace cv { + + template class Size_; + template class Point_; + template class Rect_; + template class Vec; + + //////////////////////////////// Point_ //////////////////////////////// + + /*! + template 2D point class. + + The class defines a point in 2D space. Data type of the point coordinates is specified + as a template parameter. There are a few shorter aliases available for user convenience. + See cv::Point, cv::Point2i, cv::Point2f and cv::Point2d. + */ + template class Point_ + { + public: + typedef _Tp value_type; + + // various constructors + Point_(); + Point_(_Tp _x, _Tp _y); + Point_(const Point_& pt); + Point_(const CvPoint& pt); + Point_(const CvPoint2D32f& pt); + Point_(const Size_<_Tp>& sz); + Point_(const Vec<_Tp, 2>& v); + + Point_& operator = (const Point_& pt); + //! conversion to another data type + template operator Point_<_Tp2>() const; + + //! conversion to the old-style C structures + operator CvPoint() const; + operator CvPoint2D32f() const; + operator Vec<_Tp, 2>() const; + + //! dot product + _Tp dot(const Point_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point_& pt) const; + //! cross-product + double cross(const Point_& pt) const; + //! checks whether the point is inside the specified rectangle + bool inside(const Rect_<_Tp>& r) const; + + _Tp x, y; //< the point coordinates + }; + + /*! + template 3D point class. + + The class defines a point in 3D space. Data type of the point coordinates is specified + as a template parameter. + + \see cv::Point3i, cv::Point3f and cv::Point3d + */ + template class Point3_ + { + public: + typedef _Tp value_type; + + // various constructors + Point3_(); + Point3_(_Tp _x, _Tp _y, _Tp _z); + Point3_(const Point3_& pt); + explicit Point3_(const Point_<_Tp>& pt); + Point3_(const CvPoint3D32f& pt); + Point3_(const Vec<_Tp, 3>& v); + + Point3_& operator = (const Point3_& pt); + //! conversion to another data type + template operator Point3_<_Tp2>() const; + //! conversion to the old-style CvPoint... + operator CvPoint3D32f() const; + //! conversion to cv::Vec<> + operator Vec<_Tp, 3>() const; + + //! dot product + _Tp dot(const Point3_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point3_& pt) const; + //! cross product of the 2 3D points + Point3_ cross(const Point3_& pt) const; + + _Tp x, y, z; //< the point coordinates + }; + + //////////////////////////////// Size_ //////////////////////////////// + + /*! + The 2D size class + + The class represents the size of a 2D rectangle, image size, matrix size etc. + Normally, cv::Size ~ cv::Size_ is used. + */ + template class Size_ + { + public: + typedef _Tp value_type; + + //! various constructors + Size_(); + Size_(_Tp _width, _Tp _height); + Size_(const Size_& sz); + Size_(const CvSize& sz); + Size_(const CvSize2D32f& sz); + Size_(const Point_<_Tp>& pt); + + Size_& operator = (const Size_& sz); + //! the area (width*height) + _Tp area() const; + + //! conversion of another data type. + template operator Size_<_Tp2>() const; + + //! conversion to the old-style OpenCV types + operator CvSize() const; + operator CvSize2D32f() const; + + _Tp width, height; // the width and the height + }; + + //////////////////////////////// Rect_ //////////////////////////////// + + /*! + The 2D up-right rectangle class + + The class represents a 2D rectangle with coordinates of the specified data type. + Normally, cv::Rect ~ cv::Rect_ is used. + */ + template class Rect_ + { + public: + typedef _Tp value_type; + + //! various constructors + Rect_(); + Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); + Rect_(const Rect_& r); + Rect_(const CvRect& r); + Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz); + Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); + + Rect_& operator = ( const Rect_& r ); + //! the top-left corner + Point_<_Tp> tl() const; + //! the bottom-right corner + Point_<_Tp> br() const; + + //! size (width, height) of the rectangle + Size_<_Tp> size() const; + //! area (width*height) of the rectangle + _Tp area() const; + + //! conversion to another data type + template operator Rect_<_Tp2>() const; + //! conversion to the old-style CvRect + operator CvRect() const; + + //! checks whether the rectangle contains the point + bool contains(const Point_<_Tp>& pt) const; + + _Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle + }; + + + %template(GcvSize2i) Size_; + %template(GcvSize2d_) Size_; + %template(GcvSize2f_) Size_; + + %template(GcvRect) Rect_; + + %template(GcvPoint2i) Point_; + %template(GcvPoint2f_) Point_; + %template(GcvPoint2d_) Point_; + + %template(GcvPoint3i) Point3_; + %template(GcvPoint3f_) Point3_; + %template(GcvPoint3d_) Point3_; + + + /* ----------------- Mat ----------------- */ + class Mat + { + public: + //! default constructor + Mat(); + //! constructs 2D matrix of the specified size and type + // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.) + Mat(int rows, int cols, int type); + Mat(cv::Size size, int type); + //! constucts 2D matrix and fills it with the specified value _s. + Mat(int rows, int cols, int type, const cv::Scalar& s); + Mat(cv::Size size, int type, const cv::Scalar& s); + + //! copy constructor + Mat(const Mat& m); + + //! builds matrix from std::vector with or without copying the data + template explicit Mat(const vector<_Tp>& vec, bool copyData=false); + //! builds matrix from cv::Vec; the data is copied by default + template explicit Mat(const Vec<_Tp, n>& vec, bool copyData=true); + //! builds matrix from cv::Matx; the data is copied by default + template explicit Mat(const Matx<_Tp, m, n>& mtx, bool copyData=true); + //! builds matrix from a 2D point + template explicit Mat(const Point_<_Tp>& pt, bool copyData=true); + //! builds matrix from a 3D point + template explicit Mat(const Point3_<_Tp>& pt, bool copyData=true); + + //! destructor - calls release() + ~Mat(); + + //! returns a new matrix header for the specified row + Mat row(int y) const; + //! returns a new matrix header for the specified column + Mat col(int x) const; + //! ... for the specified row span + Mat rowRange(int startrow, int endrow) const; + //! ... for the specified column span + Mat colRange(int startcol, int endcol) const; + //! ... for the specified diagonal + // (d=0 - the main diagonal, + // >0 - a diagonal from the lower half, + // <0 - a diagonal from the upper half) + Mat diag(int d=0) const; + //! constructs a square diagonal matrix which main diagonal is vector "d" + static Mat diag(const Mat& d); + + //! returns deep copy of the matrix, i.e. the data is copied + Mat clone() const; + + void assignTo( Mat& m, int type=-1 ) const; + + //! creates alternative matrix header for the same data, with different + // number of channels and/or different number of rows. see cvReshape. + Mat reshape(int cn, int rows=0) const; + Mat reshape(int cn, int newndims, const int* newsz) const; + + //! adds element to the end of 1d matrix (or possibly multiple elements when _Tp=Mat) + template void push_back(const _Tp& elem); + template void push_back(const Mat_<_Tp>& elem); + void push_back(const Mat& m); + //! removes several hyper-planes from bottom of the matrix + void pop_back(size_t nelems=1); + + //! special versions for 2D arrays (especially convenient for referencing image pixels) + template _Tp& at(cv::Point pt); + template const _Tp& at(cv::Point pt) const; + %template(gcvAtd) at; + %template(gcvAtf) at; + }; + +} + +/* Additional STL types */ +namespace std { + %template(GcvPoint3fVector) vector; + %template(GcvPoint2fVector) vector; + + %template(GcvIntVector) vector; + %template(GcvFloatVector) vector; +}; diff --git a/gocv/gocv_test.go b/gocv/gocv_test.go new file mode 100644 index 0000000..f1a52e8 --- /dev/null +++ b/gocv/gocv_test.go @@ -0,0 +1,69 @@ +package gocv + +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) +} + +func TestMat(t *testing.T) { + mat := NewMat() + mat2 := NewMat(mat) + spew.Dump(mat2) +} + +func TestGcvInitCameraMatrix2D(t *testing.T) { + objPts := NewGcvPoint3fVector(int64(4)) + objPts.Set(0, NewGcvPoint3f(0, 25, 0)) + objPts.Set(1, NewGcvPoint3f(0, -25, 0)) + objPts.Set(2, NewGcvPoint3f(-47, 25, 0)) + objPts.Set(3, NewGcvPoint3f(-47, -25, 0)) + + imgPts := NewGcvPoint2fVector(int64(4)) + imgPts.Set(0, NewGcvPoint2f(1136.4140625, 1041.89208984)) + imgPts.Set(1, NewGcvPoint2f(1845.33190918, 671.39581299)) + imgPts.Set(2, NewGcvPoint2f(302.73373413, 634.79998779)) + imgPts.Set(3, NewGcvPoint2f(1051.46154785, 352.76107788)) + + camMat := GcvInitCameraMatrix2D(objPts, imgPts) + spew.Dump(camMat.GcvAtd(NewGcvSize2i(0, 0))) + spew.Dump(camMat.GcvAtd(NewGcvSize2i(0, 1))) + spew.Dump(camMat.GcvAtd(NewGcvSize2i(1, 1))) + spew.Dump(camMat.GcvAtd(NewGcvSize2i(1, 2))) + spew.Dump(camMat.GcvAtd(NewGcvSize2i(2, 2))) +} + +func TestGcvCalibrateCamera(t *testing.T) { + objPts := NewGcvPoint3fVector(int64(4)) + objPts.Set(0, NewGcvPoint3f(0, 25, 0)) + objPts.Set(1, NewGcvPoint3f(0, -25, 0)) + objPts.Set(2, NewGcvPoint3f(-47, 25, 0)) + objPts.Set(3, NewGcvPoint3f(-47, -25, 0)) + + imgPts := NewGcvPoint2fVector(int64(4)) + imgPts.Set(0, NewGcvPoint2f(1136.4140625, 1041.89208984)) + imgPts.Set(1, NewGcvPoint2f(1845.33190918, 671.39581299)) + imgPts.Set(2, NewGcvPoint2f(302.73373413, 634.79998779)) + imgPts.Set(3, NewGcvPoint2f(1051.46154785, 352.76107788)) + + imgSize := NewGcvSize2i(1920, 1080) + + camMat := GcvInitCameraMatrix2D(objPts, imgPts) + + GcvCalibrateCamera(objPts, imgPts, imgSize, camMat) +} diff --git a/opencv2/gcv_calib3d/gcv_calib3d.go b/opencv2/gcv_calib3d/gcv_calib3d.go deleted file mode 100644 index b8f39df..0000000 --- a/opencv2/gcv_calib3d/gcv_calib3d.go +++ /dev/null @@ -1,5 +0,0 @@ -package gcv_calib3d - -// #cgo CXXFLAGS: -std=c++11 -// #cgo darwin pkg-config: opencv -import "C" diff --git a/opencv2/gcv_calib3d/gcv_calib3d.swigcxx b/opencv2/gcv_calib3d/gcv_calib3d.swigcxx deleted file mode 100644 index 64edfa2..0000000 --- a/opencv2/gcv_calib3d/gcv_calib3d.swigcxx +++ /dev/null @@ -1,7 +0,0 @@ -%module gcv_calib3d - -%{ -#include "gcv_calib3d.hpp" -%} - -%include "gcv_calib3d.hpp" diff --git a/opencv2/gcv_calib3d/gcv_calib3d_test.go b/opencv2/gcv_calib3d/gcv_calib3d_test.go deleted file mode 100644 index abd3e94..0000000 --- a/opencv2/gcv_calib3d/gcv_calib3d_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package gcv_calib3d - -import "testing" - -import "github.com/lazywei/go-opencv/opencv2/gcv_utils" - -// [[[ 0. 25. 0.] -// [ 0. -25. 0.] -// [-47. 25. 0.] -// [-47. -25. 0.]]] -// [[[ 1136.4140625 1041.89208984] -// [ 1845.33190918 671.39581299] -// [ 302.73373413 634.79998779] -// [ 1051.46154785 352.76107788]]] -// (1920, 1080) -// [[ 4.82812906e+03 0.00000000e+00 9.59500000e+02] -// [ 0.00000000e+00 4.82812906e+03 5.39500000e+02] -// [ 0.00000000e+00 0.00000000e+00 1.00000000e+00]] - -func TestGcvInitCameraMatrix2D(t *testing.T) { - objPts := gcv_utils.NewGcvPoint3fVector(int64(4)) - objPts.Set(0, gcv_utils.GetPoint3f(0, 25, 0)) - objPts.Set(1, gcv_utils.GetPoint3f(0, -25, 0)) - objPts.Set(2, gcv_utils.GetPoint3f(-47, 25, 0)) - objPts.Set(3, gcv_utils.GetPoint3f(-47, -25, 0)) - - imgPts := gcv_utils.NewGcvPoint2fVector(int64(4)) - imgPts.Set(0, gcv_utils.GetPoint2f(1136.4140625, 1041.89208984)) - imgPts.Set(1, gcv_utils.GetPoint2f(1845.33190918, 671.39581299)) - imgPts.Set(2, gcv_utils.GetPoint2f(302.73373413, 634.79998779)) - imgPts.Set(3, gcv_utils.GetPoint2f(1051.46154785, 352.76107788)) - - GcvInitCameraMatrix2D(objPts, imgPts) -} - -func TestGcvCalibrateCamera(t *testing.T) { - objPts := gcv_utils.NewGcvPoint3fVector(int64(4)) - objPts.Set(0, gcv_utils.GetPoint3f(0, 25, 0)) - objPts.Set(1, gcv_utils.GetPoint3f(0, -25, 0)) - objPts.Set(2, gcv_utils.GetPoint3f(-47, 25, 0)) - objPts.Set(3, gcv_utils.GetPoint3f(-47, -25, 0)) - - imgPts := gcv_utils.NewGcvPoint2fVector(int64(4)) - imgPts.Set(0, gcv_utils.GetPoint2f(1136.4140625, 1041.89208984)) - imgPts.Set(1, gcv_utils.GetPoint2f(1845.33190918, 671.39581299)) - imgPts.Set(2, gcv_utils.GetPoint2f(302.73373413, 634.79998779)) - imgPts.Set(3, gcv_utils.GetPoint2f(1051.46154785, 352.76107788)) - - imgSize := gcv_utils.NewGcvIntVector(int64(2)) - imgSize.Set(0, 1920) - imgSize.Set(1, 1080) - - camMat := GcvInitCameraMatrix2D(objPts, imgPts) - - GcvCalibrateCamera(objPts, imgPts, imgSize, camMat) -} diff --git a/opencv2/gcv_utils/gcv_utils.go b/opencv2/gcv_utils/gcv_utils.go deleted file mode 100644 index 45b5f12..0000000 --- a/opencv2/gcv_utils/gcv_utils.go +++ /dev/null @@ -1,5 +0,0 @@ -package gcv_utils - -// #cgo CXXFLAGS: -std=c++11 -// #cgo darwin pkg-config: opencv -import "C" diff --git a/opencv2/gcv_utils/gcv_utils.hpp b/opencv2/gcv_utils/gcv_utils.hpp deleted file mode 100644 index b7814d5..0000000 --- a/opencv2/gcv_utils/gcv_utils.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -using namespace std; - -cv::Point3f GetPoint3f(float x, float y, float z) { - return cv::Point3f(x, y, z); -} - -cv::Point2f GetPoint2f(float x, float y) { - return cv::Point2f(x, y); -} diff --git a/opencv2/gcv_utils/gcv_utils.swigcxx b/opencv2/gcv_utils/gcv_utils.swigcxx deleted file mode 100644 index abfbf7f..0000000 --- a/opencv2/gcv_utils/gcv_utils.swigcxx +++ /dev/null @@ -1,16 +0,0 @@ -%module gcv_utils -%include "std_vector.i" - -%{ -#include "gcv_utils.hpp" -%} - -%include "gcv_utils.hpp" - -namespace std { - %template(GcvPoint3fVector) vector; - %template(GcvPoint2fVector) vector; - - %template(GcvIntVector) vector; - %template(GcvFloatVector) vector; -}; diff --git a/opencv2/opencv2.go b/opencv2/opencv2.go deleted file mode 100644 index 68e5860..0000000 --- a/opencv2/opencv2.go +++ /dev/null @@ -1 +0,0 @@ -package opencv2