diff --git a/opencv2/gcv_calib3d/gcv_calib3d.cpp b/opencv2/gcv_calib3d/gcv_calib3d.cpp new file mode 100644 index 0000000..d9dc858 --- /dev/null +++ b/opencv2/gcv_calib3d/gcv_calib3d.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +#include "gcv_calib3d.hpp" + +cv::Mat gcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { + cv::Mat cameraMatrix; + + std::vector *objPtsArr = new std::vector(); + std::vector *imgPtsArr = new std::vector(); + + objPtsArr->push_back(objPts); + imgPtsArr->push_back(imgPts); + + cameraMatrix = cv::initCameraMatrix2D(*objPtsArr, *imgPtsArr, cv::Size(1920, 1080), 1); + std::cout << cameraMatrix << std::endl; + return cameraMatrix; +} diff --git a/opencv2/go_calib3d/go_calib3d.go b/opencv2/gcv_calib3d/gcv_calib3d.go similarity index 78% rename from opencv2/go_calib3d/go_calib3d.go rename to opencv2/gcv_calib3d/gcv_calib3d.go index 4aa2eae..b8f39df 100644 --- a/opencv2/go_calib3d/go_calib3d.go +++ b/opencv2/gcv_calib3d/gcv_calib3d.go @@ -1,4 +1,4 @@ -package go_calib3d +package gcv_calib3d // #cgo CXXFLAGS: -std=c++11 // #cgo darwin pkg-config: opencv diff --git a/opencv2/gcv_calib3d/gcv_calib3d.hpp b/opencv2/gcv_calib3d/gcv_calib3d.hpp new file mode 100644 index 0000000..9f88a00 --- /dev/null +++ b/opencv2/gcv_calib3d/gcv_calib3d.hpp @@ -0,0 +1,8 @@ +#include +#include +#include + +typedef std::vector VecPoint3f; +typedef std::vector VecPoint2f; + +cv::Mat gcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts); diff --git a/opencv2/gcv_calib3d/gcv_calib3d.swigcxx b/opencv2/gcv_calib3d/gcv_calib3d.swigcxx new file mode 100644 index 0000000..ecdf7ce --- /dev/null +++ b/opencv2/gcv_calib3d/gcv_calib3d.swigcxx @@ -0,0 +1,15 @@ +%module gcv_calib3d +%include "std_vector.i" + +%{ +#include "gcv_calib3d.hpp" +#include "gcv_core.hpp" +%} + +%include "gcv_calib3d.hpp" +%include "gcv_core.hpp" + +namespace std { + %template(IntVector) vector; + %template(DoubleVector) vector; +}; diff --git a/opencv2/gcv_calib3d/gcv_calib3d_test.go b/opencv2/gcv_calib3d/gcv_calib3d_test.go new file mode 100644 index 0000000..2317482 --- /dev/null +++ b/opencv2/gcv_calib3d/gcv_calib3d_test.go @@ -0,0 +1,32 @@ +package gcv_calib3d + +import "testing" + +// [[[ 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 := NewGcvVecPoint3f() + objPts.PushBack(NewGcvPoint3f(0, 25, 0).Get()) + objPts.PushBack(NewGcvPoint3f(0, -25, 0).Get()) + objPts.PushBack(NewGcvPoint3f(-47, 25, 0).Get()) + objPts.PushBack(NewGcvPoint3f(-47, -25, 0).Get()) + + imgPts := NewGcvVecPoint2f() + imgPts.PushBack(NewGcvPoint2f(1136.4140625, 1041.89208984).Get()) + imgPts.PushBack(NewGcvPoint2f(1845.33190918, 671.39581299).Get()) + imgPts.PushBack(NewGcvPoint2f(302.73373413, 634.79998779).Get()) + imgPts.PushBack(NewGcvPoint2f(1051.46154785, 352.76107788).Get()) + + GcvInitCameraMatrix2D(objPts.Get(), imgPts.Get()) +} diff --git a/opencv2/gcv_calib3d/gcv_core.hpp b/opencv2/gcv_calib3d/gcv_core.hpp new file mode 100644 index 0000000..613cc03 --- /dev/null +++ b/opencv2/gcv_calib3d/gcv_core.hpp @@ -0,0 +1,72 @@ +#include +#include + +using namespace std; + +class GcvPoint3f +{ +public: + GcvPoint3f (float x, float y, float z) + : _data(x, y, z) {}; + ~GcvPoint3f () {}; + + cv::Point3f Get() { return _data; } + void Set(float x, float y, float z) { + _data = cv::Point3f(x, y, z); + } +private: + cv::Point3f _data; +}; + +class GcvVecPoint3f +{ +public: + GcvVecPoint3f () {}; + ~GcvVecPoint3f () {}; + + void PushBack(cv::Point3f pt) { + _data.push_back(pt); + } + + void Clear() { + _data.clear(); + } + + std::vector Get() { return _data; } +private: + std::vector _data; +}; + +class GcvPoint2f +{ +public: + GcvPoint2f (float x, float y) + : _data(x, y) {}; + ~GcvPoint2f () {}; + + cv::Point2f Get() { return _data; } + void Set(float x, float y) { + _data = cv::Point2f(x, y); + } +private: + cv::Point2f _data; +}; + +class GcvVecPoint2f +{ +public: + GcvVecPoint2f () {}; + ~GcvVecPoint2f () {}; + + void PushBack(cv::Point2f pt) { + _data.push_back(pt); + } + + void Clear() { + _data.clear(); + } + + std::vector Get() { return _data; } +private: + std::vector _data; +}; diff --git a/opencv2/go_calib3d/go_calib3d.cpp b/opencv2/go_calib3d/go_calib3d.cpp deleted file mode 100644 index 1910eec..0000000 --- a/opencv2/go_calib3d/go_calib3d.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include "go_calib3d.hpp" -#include "iostream" -#include "vector" - -using namespace std; - -void -GoCalib3d::foo() { - cout << "Hello there" << endl; - vector< vector> objPts; - vector< vector> imgPts; - - objPts.push_back(vector()); - imgPts.push_back(vector()); - - objPts[0].push_back(cv::Point3f(0, 25, 0)); - objPts[0].push_back(cv::Point3f(0, -25, 0)); - objPts[0].push_back(cv::Point3f(-47, 25, 0)); - objPts[0].push_back(cv::Point3f(-47, -25, 0)); - - imgPts[0].push_back(cv::Point2f(1136.4140625, 1041.89208984)); - imgPts[0].push_back(cv::Point2f(1845.33190918, 671.39581299)); - imgPts[0].push_back(cv::Point2f(302.73373413, 634.79998779)); - imgPts[0].push_back(cv::Point2f(1051.46154785, 352.76107788)); - - cv::Mat cameraMatrix = cv::initCameraMatrix2D(objPts, imgPts, cv::Size(1920, 1080), 1); - std::cout << cameraMatrix << std::endl; -} diff --git a/opencv2/go_calib3d/go_calib3d.hpp b/opencv2/go_calib3d/go_calib3d.hpp deleted file mode 100644 index b78be85..0000000 --- a/opencv2/go_calib3d/go_calib3d.hpp +++ /dev/null @@ -1,9 +0,0 @@ -class GoCalib3d -{ -public: - GoCalib3d () {}; - virtual ~GoCalib3d () {}; - void foo(); -private: - /* data */ -}; diff --git a/opencv2/go_calib3d/go_calib3d.swigcxx b/opencv2/go_calib3d/go_calib3d.swigcxx deleted file mode 100644 index 98d6160..0000000 --- a/opencv2/go_calib3d/go_calib3d.swigcxx +++ /dev/null @@ -1,7 +0,0 @@ -%module go_calib3d - -%{ -#include "go_calib3d.hpp" -%} - -%include "go_calib3d.hpp" diff --git a/opencv2/go_calib3d/go_calib3d_test.go b/opencv2/go_calib3d/go_calib3d_test.go deleted file mode 100644 index ff1546d..0000000 --- a/opencv2/go_calib3d/go_calib3d_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package go_calib3d - -import "testing" - -// [[[ 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 TestMain(t *testing.T) { - // objPoints := opencv.CreateMat(4, 3, opencv.CV_64F) - // spew.Dump(objPoints.Get(0, 0)) - // InitIntrinsicParams2D(objPoints) - xxx := NewGoCalib3d() - xxx.Foo() -}