From b434835c52b1c12ba8cfc855e10bd4e551dbab7f Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Mon, 16 Feb 2015 14:06:45 +0800 Subject: [PATCH] Split files. --- gocv/gocv.swigcxx | 276 +--------------------------- gocv/{gocv.cpp => gocv_calib3d.cpp} | 2 +- gocv/{gocv.hpp => gocv_calib3d.hpp} | 0 gocv/gocv_core.i | 274 +++++++++++++++++++++++++++ gocv/gocv_test.go | 10 + 5 files changed, 288 insertions(+), 274 deletions(-) rename gocv/{gocv.cpp => gocv_calib3d.cpp} (97%) rename gocv/{gocv.hpp => gocv_calib3d.hpp} (100%) create mode 100644 gocv/gocv_core.i diff --git a/gocv/gocv.swigcxx b/gocv/gocv.swigcxx index be86413..b56bc86 100644 --- a/gocv/gocv.swigcxx +++ b/gocv/gocv.swigcxx @@ -1,278 +1,8 @@ %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_calib3d.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; -}; +%include "gocv_core.i" +%include "gocv_calib3d.hpp" diff --git a/gocv/gocv.cpp b/gocv/gocv_calib3d.cpp similarity index 97% rename from gocv/gocv.cpp rename to gocv/gocv_calib3d.cpp index 3458147..5732e28 100644 --- a/gocv/gocv.cpp +++ b/gocv/gocv_calib3d.cpp @@ -3,7 +3,7 @@ #include #include -#include "gocv.hpp" +#include "gocv_calib3d.hpp" cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { cv::Mat cameraMatrix; diff --git a/gocv/gocv.hpp b/gocv/gocv_calib3d.hpp similarity index 100% rename from gocv/gocv.hpp rename to gocv/gocv_calib3d.hpp diff --git a/gocv/gocv_core.i b/gocv/gocv_core.i new file mode 100644 index 0000000..924c98b --- /dev/null +++ b/gocv/gocv_core.i @@ -0,0 +1,274 @@ +%include "std_vector.i" + +%{ +#include "opencv2/core/types_c.h" +#include "opencv2/core/version.hpp" +#include "opencv2/core/core.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 index f1a52e8..5b1dbd1 100644 --- a/gocv/gocv_test.go +++ b/gocv/gocv_test.go @@ -64,6 +64,16 @@ func TestGcvCalibrateCamera(t *testing.T) { imgSize := NewGcvSize2i(1920, 1080) 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))) GcvCalibrateCamera(objPts, imgPts, imgSize, camMat) + 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))) }