From b491ec3c933ae1e1b8b3c24e115d29f617d70dce Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Fri, 6 Feb 2015 23:08:22 +0800 Subject: [PATCH 1/9] Implement basic calib3d --- AUTHORS | 18 ++++++++-------- README.md | 20 +++++++++++++++++- opencv/calib3d/calib3d.go | 38 ++++++++++++++++++++++++++++++++++ opencv/calib3d/calib3d_test.go | 9 ++++++++ opencv/imgproc.go | 2 +- 5 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 opencv/calib3d/calib3d.go create mode 100644 opencv/calib3d/calib3d_test.go diff --git a/AUTHORS b/AUTHORS index fcb511b..810f970 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,12 +7,12 @@ ChaiShushan # Forked version authors: Chih-Wei Chang MohamedHelala -Adrian Zankich <> -vanillahsu <> -Alexander Kirillov <> -Aditya Bhargava <> -Bradley Griffiths <> -Ashkan Kiani <> -Peter Bui <> -satojkovic <> -TEE JIA HEN <> +Adrian Zankich +vanillahsu +Alexander Kirillov +Aditya Bhargava +Bradley Griffiths +Ashkan Kiani +Peter Bui +satojkovic +TEE JIA HEN diff --git a/README.md b/README.md index c8ef54f..8074be0 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,29 @@ go get code.google.com/p/go-opencv/trunk/opencv cd ${GoOpenCVRoot}/trunk/samples && go run hellocv.go ``` +## Usage + +Currently there are no too many readily instruction for usage. At this point, you can always refers to OpenCV's documentation. I'll try to keep all the bindings have the same signature as in OpenCV's C interface. However, please do note that sometimes the signature might slightly differ from the C interface due to Golang's type declaration conventions, for example: + +``` +# The original signature in C interface. +void cvInitIntrinsicParams2D( +const CvMat* object_points, const CvMat* image_points, +const CvMat* npoints, CvSize image_size, CvMat* camera_matrix, +double aspect_ratio=1. ) + +# We might put all *Mat types together, however +func InitIntrinsicParams2D(objectPoints, imagePoints, nPoints, cameraMatrix *Mat ... + +# Or we might use "explicitly return" instead of C-style's pointer +func InitIntrinsicParams2D(objectPoints, imagePoints, nPoints, *Mat ...) (cameraMatrix *Mat) +``` + ## TODOs - [ ] Better documents - [ ] Split the big package into sub-packages corresponding to the modules described in [OpenCV API Reference](http://docs.opencv.org/modules/core/doc/intro.html) -- [ ] Clean up the codes +- [ ] Clean up the codes with better coding style ## Example diff --git a/opencv/calib3d/calib3d.go b/opencv/calib3d/calib3d.go new file mode 100644 index 0000000..ee02884 --- /dev/null +++ b/opencv/calib3d/calib3d.go @@ -0,0 +1,38 @@ +// Copyright 2014 . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Bindings for OpenCV's Calib3d (Camera Calibration +// and 3D Reconstruction) module +package calib3d + +//#include "../opencv.h" +//#cgo linux pkg-config: opencv +//#cgo darwin pkg-config: opencv +//#cgo freebsd pkg-config: opencv +//#cgo windows LDFLAGS: -lopencv_core242.dll -lopencv_imgproc242.dll -lopencv_photo242.dll -lopencv_highgui242.dll -lstdc++ +import "C" +import "unsafe" + +/* +void cvInitIntrinsicParams2D( +const CvMat* object_points, const CvMat* image_points, +const CvMat* npoints, CvSize image_size, CvMat* camera_matrix, +double aspect_ratio=1. ) +*/ + +func InitIntrinsicParams2D(objPoints, imgPoints, nPoints *Mat, imgWidth, imgHeight int, aspectRatio float64) (cameraMatrix *Mat) { + cameraMatrix = CreateMat(3, 3, CV_64F) + + size := C.cvSize(C.int(imgWidth), C.int(imgHeight)) + + C.cvInitIntrinsicParams2D( + unsafe.Pointer(objPoints), + unsafe.Pointer(imgPoints), + unsafe.Pointer(nPoints), + size, + unsafe.Pointer(cameraMatrix), + aspectRatio) + + return cameraMatrix +} diff --git a/opencv/calib3d/calib3d_test.go b/opencv/calib3d/calib3d_test.go new file mode 100644 index 0000000..34bfa8c --- /dev/null +++ b/opencv/calib3d/calib3d_test.go @@ -0,0 +1,9 @@ +package calib3d + +import ( + "testing" +) + +func TestInitIntrinsicParams2D(t *testing.T) { + +} diff --git a/opencv/imgproc.go b/opencv/imgproc.go index 90ebb5c..93b8070 100644 --- a/opencv/imgproc.go +++ b/opencv/imgproc.go @@ -1,4 +1,4 @@ -// Copyright 2013 jrweizhang AT gmail.com. All rights reserved. +// Copyright 2013 . All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. From 2d7cc41b9ce02e5b4440f77c86c3f3cc008fe35a Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Fri, 13 Feb 2015 16:47:55 +0800 Subject: [PATCH 2/9] Trying to wrap Calib3d with SWIG. --- opencv/calib3d/calib3d.go | 38 ------------------------------- opencv/calib3d/calib3d_test.go | 9 -------- opencv/calib3d/go_calib3d.cpp | 29 +++++++++++++++++++++++ opencv/calib3d/go_calib3d.go | 5 ++++ opencv/calib3d/go_calib3d.hpp | 9 ++++++++ opencv/calib3d/go_calib3d.swigcxx | 7 ++++++ opencv/calib3d/go_calib3d_test.go | 24 +++++++++++++++++++ 7 files changed, 74 insertions(+), 47 deletions(-) delete mode 100644 opencv/calib3d/calib3d.go delete mode 100644 opencv/calib3d/calib3d_test.go create mode 100644 opencv/calib3d/go_calib3d.cpp create mode 100644 opencv/calib3d/go_calib3d.go create mode 100644 opencv/calib3d/go_calib3d.hpp create mode 100644 opencv/calib3d/go_calib3d.swigcxx create mode 100644 opencv/calib3d/go_calib3d_test.go diff --git a/opencv/calib3d/calib3d.go b/opencv/calib3d/calib3d.go deleted file mode 100644 index ee02884..0000000 --- a/opencv/calib3d/calib3d.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2014 . All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Bindings for OpenCV's Calib3d (Camera Calibration -// and 3D Reconstruction) module -package calib3d - -//#include "../opencv.h" -//#cgo linux pkg-config: opencv -//#cgo darwin pkg-config: opencv -//#cgo freebsd pkg-config: opencv -//#cgo windows LDFLAGS: -lopencv_core242.dll -lopencv_imgproc242.dll -lopencv_photo242.dll -lopencv_highgui242.dll -lstdc++ -import "C" -import "unsafe" - -/* -void cvInitIntrinsicParams2D( -const CvMat* object_points, const CvMat* image_points, -const CvMat* npoints, CvSize image_size, CvMat* camera_matrix, -double aspect_ratio=1. ) -*/ - -func InitIntrinsicParams2D(objPoints, imgPoints, nPoints *Mat, imgWidth, imgHeight int, aspectRatio float64) (cameraMatrix *Mat) { - cameraMatrix = CreateMat(3, 3, CV_64F) - - size := C.cvSize(C.int(imgWidth), C.int(imgHeight)) - - C.cvInitIntrinsicParams2D( - unsafe.Pointer(objPoints), - unsafe.Pointer(imgPoints), - unsafe.Pointer(nPoints), - size, - unsafe.Pointer(cameraMatrix), - aspectRatio) - - return cameraMatrix -} diff --git a/opencv/calib3d/calib3d_test.go b/opencv/calib3d/calib3d_test.go deleted file mode 100644 index 34bfa8c..0000000 --- a/opencv/calib3d/calib3d_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package calib3d - -import ( - "testing" -) - -func TestInitIntrinsicParams2D(t *testing.T) { - -} diff --git a/opencv/calib3d/go_calib3d.cpp b/opencv/calib3d/go_calib3d.cpp new file mode 100644 index 0000000..1910eec --- /dev/null +++ b/opencv/calib3d/go_calib3d.cpp @@ -0,0 +1,29 @@ +#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/opencv/calib3d/go_calib3d.go b/opencv/calib3d/go_calib3d.go new file mode 100644 index 0000000..4aa2eae --- /dev/null +++ b/opencv/calib3d/go_calib3d.go @@ -0,0 +1,5 @@ +package go_calib3d + +// #cgo CXXFLAGS: -std=c++11 +// #cgo darwin pkg-config: opencv +import "C" diff --git a/opencv/calib3d/go_calib3d.hpp b/opencv/calib3d/go_calib3d.hpp new file mode 100644 index 0000000..b78be85 --- /dev/null +++ b/opencv/calib3d/go_calib3d.hpp @@ -0,0 +1,9 @@ +class GoCalib3d +{ +public: + GoCalib3d () {}; + virtual ~GoCalib3d () {}; + void foo(); +private: + /* data */ +}; diff --git a/opencv/calib3d/go_calib3d.swigcxx b/opencv/calib3d/go_calib3d.swigcxx new file mode 100644 index 0000000..98d6160 --- /dev/null +++ b/opencv/calib3d/go_calib3d.swigcxx @@ -0,0 +1,7 @@ +%module go_calib3d + +%{ +#include "go_calib3d.hpp" +%} + +%include "go_calib3d.hpp" diff --git a/opencv/calib3d/go_calib3d_test.go b/opencv/calib3d/go_calib3d_test.go new file mode 100644 index 0000000..ff1546d --- /dev/null +++ b/opencv/calib3d/go_calib3d_test.go @@ -0,0 +1,24 @@ +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() +} From 8f9e5b89d98a4d95740c4c0d7ceeb34cf4ebf80a Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Fri, 13 Feb 2015 17:12:29 +0800 Subject: [PATCH 3/9] Re-organize --- {opencv/calib3d => opencv2/go_calib3d}/go_calib3d.cpp | 0 {opencv/calib3d => opencv2/go_calib3d}/go_calib3d.go | 0 {opencv/calib3d => opencv2/go_calib3d}/go_calib3d.hpp | 0 {opencv/calib3d => opencv2/go_calib3d}/go_calib3d.swigcxx | 0 {opencv/calib3d => opencv2/go_calib3d}/go_calib3d_test.go | 0 opencv2/opencv2.go | 1 + 6 files changed, 1 insertion(+) rename {opencv/calib3d => opencv2/go_calib3d}/go_calib3d.cpp (100%) rename {opencv/calib3d => opencv2/go_calib3d}/go_calib3d.go (100%) rename {opencv/calib3d => opencv2/go_calib3d}/go_calib3d.hpp (100%) rename {opencv/calib3d => opencv2/go_calib3d}/go_calib3d.swigcxx (100%) rename {opencv/calib3d => opencv2/go_calib3d}/go_calib3d_test.go (100%) create mode 100644 opencv2/opencv2.go diff --git a/opencv/calib3d/go_calib3d.cpp b/opencv2/go_calib3d/go_calib3d.cpp similarity index 100% rename from opencv/calib3d/go_calib3d.cpp rename to opencv2/go_calib3d/go_calib3d.cpp diff --git a/opencv/calib3d/go_calib3d.go b/opencv2/go_calib3d/go_calib3d.go similarity index 100% rename from opencv/calib3d/go_calib3d.go rename to opencv2/go_calib3d/go_calib3d.go diff --git a/opencv/calib3d/go_calib3d.hpp b/opencv2/go_calib3d/go_calib3d.hpp similarity index 100% rename from opencv/calib3d/go_calib3d.hpp rename to opencv2/go_calib3d/go_calib3d.hpp diff --git a/opencv/calib3d/go_calib3d.swigcxx b/opencv2/go_calib3d/go_calib3d.swigcxx similarity index 100% rename from opencv/calib3d/go_calib3d.swigcxx rename to opencv2/go_calib3d/go_calib3d.swigcxx diff --git a/opencv/calib3d/go_calib3d_test.go b/opencv2/go_calib3d/go_calib3d_test.go similarity index 100% rename from opencv/calib3d/go_calib3d_test.go rename to opencv2/go_calib3d/go_calib3d_test.go diff --git a/opencv2/opencv2.go b/opencv2/opencv2.go new file mode 100644 index 0000000..68e5860 --- /dev/null +++ b/opencv2/opencv2.go @@ -0,0 +1 @@ +package opencv2 From 49c0f9831b4a3a03449da47117eb5917377c9a99 Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Sat, 14 Feb 2015 14:41:23 +0800 Subject: [PATCH 4/9] Draft for cv::initCameraMatrix2D --- opencv2/gcv_calib3d/gcv_calib3d.cpp | 20 ++++++ .../gcv_calib3d.go} | 2 +- opencv2/gcv_calib3d/gcv_calib3d.hpp | 8 +++ opencv2/gcv_calib3d/gcv_calib3d.swigcxx | 15 ++++ opencv2/gcv_calib3d/gcv_calib3d_test.go | 32 +++++++++ opencv2/gcv_calib3d/gcv_core.hpp | 72 +++++++++++++++++++ opencv2/go_calib3d/go_calib3d.cpp | 29 -------- opencv2/go_calib3d/go_calib3d.hpp | 9 --- opencv2/go_calib3d/go_calib3d.swigcxx | 7 -- opencv2/go_calib3d/go_calib3d_test.go | 24 ------- 10 files changed, 148 insertions(+), 70 deletions(-) create mode 100644 opencv2/gcv_calib3d/gcv_calib3d.cpp rename opencv2/{go_calib3d/go_calib3d.go => gcv_calib3d/gcv_calib3d.go} (78%) create mode 100644 opencv2/gcv_calib3d/gcv_calib3d.hpp create mode 100644 opencv2/gcv_calib3d/gcv_calib3d.swigcxx create mode 100644 opencv2/gcv_calib3d/gcv_calib3d_test.go create mode 100644 opencv2/gcv_calib3d/gcv_core.hpp delete mode 100644 opencv2/go_calib3d/go_calib3d.cpp delete mode 100644 opencv2/go_calib3d/go_calib3d.hpp delete mode 100644 opencv2/go_calib3d/go_calib3d.swigcxx delete mode 100644 opencv2/go_calib3d/go_calib3d_test.go 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() -} From 9dbdf34f32fbfbd10438b64f822af87e4f8070ba Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Sat, 14 Feb 2015 22:31:03 +0800 Subject: [PATCH 5/9] Use std_vector instead of wrapping ourself. --- opencv2/gcv_calib3d/gcv_calib3d.swigcxx | 4 +-- opencv2/gcv_calib3d/gcv_calib3d_test.go | 22 +++++++------- opencv2/gcv_calib3d/gcv_core.hpp | 38 ------------------------- 3 files changed, 13 insertions(+), 51 deletions(-) diff --git a/opencv2/gcv_calib3d/gcv_calib3d.swigcxx b/opencv2/gcv_calib3d/gcv_calib3d.swigcxx index ecdf7ce..f918e4e 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d.swigcxx +++ b/opencv2/gcv_calib3d/gcv_calib3d.swigcxx @@ -10,6 +10,6 @@ %include "gcv_core.hpp" namespace std { - %template(IntVector) vector; - %template(DoubleVector) vector; + %template(GcvPoint3fVector) vector; + %template(GcvPoint2fVector) vector; }; diff --git a/opencv2/gcv_calib3d/gcv_calib3d_test.go b/opencv2/gcv_calib3d/gcv_calib3d_test.go index 2317482..62a897d 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d_test.go +++ b/opencv2/gcv_calib3d/gcv_calib3d_test.go @@ -16,17 +16,17 @@ import "testing" // [ 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()) + objPts := NewGcvPoint3fVector(int64(4)) + objPts.Set(0, NewGcvPoint3f(0, 25, 0).Get()) + objPts.Set(1, NewGcvPoint3f(0, -25, 0).Get()) + objPts.Set(2, NewGcvPoint3f(-47, 25, 0).Get()) + objPts.Set(3, 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()) + imgPts := NewGcvPoint2fVector(int64(4)) + imgPts.Set(0, NewGcvPoint2f(1136.4140625, 1041.89208984).Get()) + imgPts.Set(1, NewGcvPoint2f(1845.33190918, 671.39581299).Get()) + imgPts.Set(2, NewGcvPoint2f(302.73373413, 634.79998779).Get()) + imgPts.Set(3, NewGcvPoint2f(1051.46154785, 352.76107788).Get()) - GcvInitCameraMatrix2D(objPts.Get(), imgPts.Get()) + GcvInitCameraMatrix2D(objPts, imgPts) } diff --git a/opencv2/gcv_calib3d/gcv_core.hpp b/opencv2/gcv_calib3d/gcv_core.hpp index 613cc03..c1efb45 100644 --- a/opencv2/gcv_calib3d/gcv_core.hpp +++ b/opencv2/gcv_calib3d/gcv_core.hpp @@ -18,25 +18,6 @@ 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: @@ -51,22 +32,3 @@ public: 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; -}; From 8d629cd3847094ddc71bf7ae07cdb30b6ead174b Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Sat, 14 Feb 2015 22:36:28 +0800 Subject: [PATCH 6/9] Use simple function instead of class. --- opencv2/gcv_calib3d/gcv_calib3d_test.go | 16 ++++++------ opencv2/gcv_calib3d/gcv_core.hpp | 34 +++++-------------------- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/opencv2/gcv_calib3d/gcv_calib3d_test.go b/opencv2/gcv_calib3d/gcv_calib3d_test.go index 62a897d..bdfb142 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d_test.go +++ b/opencv2/gcv_calib3d/gcv_calib3d_test.go @@ -17,16 +17,16 @@ import "testing" func TestGcvInitCameraMatrix2D(t *testing.T) { objPts := NewGcvPoint3fVector(int64(4)) - objPts.Set(0, NewGcvPoint3f(0, 25, 0).Get()) - objPts.Set(1, NewGcvPoint3f(0, -25, 0).Get()) - objPts.Set(2, NewGcvPoint3f(-47, 25, 0).Get()) - objPts.Set(3, NewGcvPoint3f(-47, -25, 0).Get()) + objPts.Set(0, GetPoint3f(0, 25, 0)) + objPts.Set(1, GetPoint3f(0, -25, 0)) + objPts.Set(2, GetPoint3f(-47, 25, 0)) + objPts.Set(3, GetPoint3f(-47, -25, 0)) imgPts := NewGcvPoint2fVector(int64(4)) - imgPts.Set(0, NewGcvPoint2f(1136.4140625, 1041.89208984).Get()) - imgPts.Set(1, NewGcvPoint2f(1845.33190918, 671.39581299).Get()) - imgPts.Set(2, NewGcvPoint2f(302.73373413, 634.79998779).Get()) - imgPts.Set(3, NewGcvPoint2f(1051.46154785, 352.76107788).Get()) + imgPts.Set(0, GetPoint2f(1136.4140625, 1041.89208984)) + imgPts.Set(1, GetPoint2f(1845.33190918, 671.39581299)) + imgPts.Set(2, GetPoint2f(302.73373413, 634.79998779)) + imgPts.Set(3, GetPoint2f(1051.46154785, 352.76107788)) GcvInitCameraMatrix2D(objPts, imgPts) } diff --git a/opencv2/gcv_calib3d/gcv_core.hpp b/opencv2/gcv_calib3d/gcv_core.hpp index c1efb45..b7814d5 100644 --- a/opencv2/gcv_calib3d/gcv_core.hpp +++ b/opencv2/gcv_calib3d/gcv_core.hpp @@ -3,32 +3,10 @@ using namespace std; -class GcvPoint3f -{ -public: - GcvPoint3f (float x, float y, float z) - : _data(x, y, z) {}; - ~GcvPoint3f () {}; +cv::Point3f GetPoint3f(float x, float y, float z) { + return cv::Point3f(x, y, z); +} - cv::Point3f Get() { return _data; } - void Set(float x, float y, float z) { - _data = cv::Point3f(x, y, z); - } -private: - cv::Point3f _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; -}; +cv::Point2f GetPoint2f(float x, float y) { + return cv::Point2f(x, y); +} From 8aad62212a74b3a83dc7d5e4ee6963f55f8859c9 Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Sat, 14 Feb 2015 22:41:24 +0800 Subject: [PATCH 7/9] Extract core related code to gcv_utils. --- opencv2/gcv_calib3d/gcv_calib3d.swigcxx | 8 ------- opencv2/gcv_calib3d/gcv_calib3d_test.go | 22 ++++++++++--------- opencv2/gcv_utils/gcv_utils.go | 5 +++++ .../gcv_core.hpp => gcv_utils/gcv_utils.hpp} | 0 opencv2/gcv_utils/gcv_utils.swigcxx | 13 +++++++++++ 5 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 opencv2/gcv_utils/gcv_utils.go rename opencv2/{gcv_calib3d/gcv_core.hpp => gcv_utils/gcv_utils.hpp} (100%) create mode 100644 opencv2/gcv_utils/gcv_utils.swigcxx diff --git a/opencv2/gcv_calib3d/gcv_calib3d.swigcxx b/opencv2/gcv_calib3d/gcv_calib3d.swigcxx index f918e4e..64edfa2 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d.swigcxx +++ b/opencv2/gcv_calib3d/gcv_calib3d.swigcxx @@ -1,15 +1,7 @@ %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(GcvPoint3fVector) vector; - %template(GcvPoint2fVector) vector; -}; diff --git a/opencv2/gcv_calib3d/gcv_calib3d_test.go b/opencv2/gcv_calib3d/gcv_calib3d_test.go index bdfb142..23d8b36 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d_test.go +++ b/opencv2/gcv_calib3d/gcv_calib3d_test.go @@ -2,6 +2,8 @@ package gcv_calib3d import "testing" +import "github.com/lazywei/go-opencv/opencv2/gcv_utils" + // [[[ 0. 25. 0.] // [ 0. -25. 0.] // [-47. 25. 0.] @@ -16,17 +18,17 @@ import "testing" // [ 0.00000000e+00 0.00000000e+00 1.00000000e+00]] func TestGcvInitCameraMatrix2D(t *testing.T) { - objPts := NewGcvPoint3fVector(int64(4)) - objPts.Set(0, GetPoint3f(0, 25, 0)) - objPts.Set(1, GetPoint3f(0, -25, 0)) - objPts.Set(2, GetPoint3f(-47, 25, 0)) - objPts.Set(3, GetPoint3f(-47, -25, 0)) + 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 := NewGcvPoint2fVector(int64(4)) - imgPts.Set(0, GetPoint2f(1136.4140625, 1041.89208984)) - imgPts.Set(1, GetPoint2f(1845.33190918, 671.39581299)) - imgPts.Set(2, GetPoint2f(302.73373413, 634.79998779)) - imgPts.Set(3, GetPoint2f(1051.46154785, 352.76107788)) + 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) } diff --git a/opencv2/gcv_utils/gcv_utils.go b/opencv2/gcv_utils/gcv_utils.go new file mode 100644 index 0000000..45b5f12 --- /dev/null +++ b/opencv2/gcv_utils/gcv_utils.go @@ -0,0 +1,5 @@ +package gcv_utils + +// #cgo CXXFLAGS: -std=c++11 +// #cgo darwin pkg-config: opencv +import "C" diff --git a/opencv2/gcv_calib3d/gcv_core.hpp b/opencv2/gcv_utils/gcv_utils.hpp similarity index 100% rename from opencv2/gcv_calib3d/gcv_core.hpp rename to opencv2/gcv_utils/gcv_utils.hpp diff --git a/opencv2/gcv_utils/gcv_utils.swigcxx b/opencv2/gcv_utils/gcv_utils.swigcxx new file mode 100644 index 0000000..4cbba2e --- /dev/null +++ b/opencv2/gcv_utils/gcv_utils.swigcxx @@ -0,0 +1,13 @@ +%module gcv_utils +%include "std_vector.i" + +%{ +#include "gcv_utils.hpp" +%} + +%include "gcv_utils.hpp" + +namespace std { + %template(GcvPoint3fVector) vector; + %template(GcvPoint2fVector) vector; +}; From 7a789473628b1dd3ec725524c2878fa7a41c7ccb Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Sun, 15 Feb 2015 13:59:32 +0800 Subject: [PATCH 8/9] Wrap CalibrateCamera --- opencv2/gcv_calib3d/gcv_calib3d.cpp | 38 ++++++++++++++++++++----- opencv2/gcv_calib3d/gcv_calib3d.hpp | 5 +++- opencv2/gcv_calib3d/gcv_calib3d_test.go | 22 ++++++++++++++ opencv2/gcv_utils/gcv_utils.swigcxx | 3 ++ 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/opencv2/gcv_calib3d/gcv_calib3d.cpp b/opencv2/gcv_calib3d/gcv_calib3d.cpp index d9dc858..19fbafb 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d.cpp +++ b/opencv2/gcv_calib3d/gcv_calib3d.cpp @@ -5,16 +5,40 @@ #include "gcv_calib3d.hpp" -cv::Mat gcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { +cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { cv::Mat cameraMatrix; - std::vector *objPtsArr = new std::vector(); - std::vector *imgPtsArr = new std::vector(); + std::vector objPtsArr; + std::vector imgPtsArr; - objPtsArr->push_back(objPts); - imgPtsArr->push_back(imgPts); + objPtsArr.push_back(objPts); + imgPtsArr.push_back(imgPts); - cameraMatrix = cv::initCameraMatrix2D(*objPtsArr, *imgPtsArr, cv::Size(1920, 1080), 1); - std::cout << cameraMatrix << std::endl; + cameraMatrix = cv::initCameraMatrix2D(objPtsArr, imgPtsArr, cv::Size(1920, 1080), 1); return cameraMatrix; } + +double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts, + std::vector imgSize, cv::Mat cameraMatrix) { + std::vector objPtsArr; + std::vector imgPtsArr; + std::vector rvecs, tvecs; + cv::Mat distCoeffs; + + double rtn; + + objPtsArr.push_back(objPts); + imgPtsArr.push_back(imgPts); + + std::cout << "init Camera" << cameraMatrix << std::endl; + + rtn = cv::calibrateCamera(objPtsArr, imgPtsArr, + cv::Size2i(imgSize[0], imgSize[1]), + cameraMatrix, distCoeffs, rvecs, tvecs); + + std::cout << "final Camera" << cameraMatrix << std::endl; + std::cout << "final rvecs" << rvecs[0] << std::endl; + std::cout << "final tvecs" << tvecs[0] << std::endl; + + return rtn; +} diff --git a/opencv2/gcv_calib3d/gcv_calib3d.hpp b/opencv2/gcv_calib3d/gcv_calib3d.hpp index 9f88a00..15d2295 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d.hpp +++ b/opencv2/gcv_calib3d/gcv_calib3d.hpp @@ -5,4 +5,7 @@ typedef std::vector VecPoint3f; typedef std::vector VecPoint2f; -cv::Mat gcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts); +cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts); + +double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts, + std::vector imgSize, cv::Mat cameraMatrix); diff --git a/opencv2/gcv_calib3d/gcv_calib3d_test.go b/opencv2/gcv_calib3d/gcv_calib3d_test.go index 23d8b36..abd3e94 100644 --- a/opencv2/gcv_calib3d/gcv_calib3d_test.go +++ b/opencv2/gcv_calib3d/gcv_calib3d_test.go @@ -32,3 +32,25 @@ func TestGcvInitCameraMatrix2D(t *testing.T) { 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.swigcxx b/opencv2/gcv_utils/gcv_utils.swigcxx index 4cbba2e..abfbf7f 100644 --- a/opencv2/gcv_utils/gcv_utils.swigcxx +++ b/opencv2/gcv_utils/gcv_utils.swigcxx @@ -10,4 +10,7 @@ namespace std { %template(GcvPoint3fVector) vector; %template(GcvPoint2fVector) vector; + + %template(GcvIntVector) vector; + %template(GcvFloatVector) vector; }; From 165a4b1f4fd2bf74e62d26733f0d4a8016cf09a0 Mon Sep 17 00:00:00 2001 From: Chih-Wei Chang Date: Sun, 15 Feb 2015 14:20:20 +0800 Subject: [PATCH 9/9] Update README --- README.md | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8074be0..1018df8 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ 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. + [**DISCLAIMER**](https://github.com/lazywei/go-opencv#disclaimer) ## Install @@ -31,32 +33,42 @@ go get code.google.com/p/go-opencv/trunk/opencv cd ${GoOpenCVRoot}/trunk/samples && go run hellocv.go ``` -## Usage +## [WIP] OpenCV2 -Currently there are no too many readily instruction for usage. At this point, you can always refers to OpenCV's documentation. I'll try to keep all the bindings have the same signature as in OpenCV's C interface. However, please do note that sometimes the signature might slightly differ from the C interface due to Golang's type declaration conventions, for example: +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. -``` -# The original signature in C interface. -void cvInitIntrinsicParams2D( -const CvMat* object_points, const CvMat* image_points, -const CvMat* npoints, CvSize image_size, CvMat* camera_matrix, -double aspect_ratio=1. ) +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`. -# We might put all *Mat types together, however -func InitIntrinsicParams2D(objectPoints, imagePoints, nPoints, cameraMatrix *Mat ... - -# Or we might use "explicitly return" instead of C-style's pointer -func InitIntrinsicParams2D(objectPoints, imagePoints, nPoints, *Mat ...) (cameraMatrix *Mat) -``` - -## TODOs - -- [ ] Better documents -- [ ] Split the big package into sub-packages corresponding to the modules described in [OpenCV API Reference](http://docs.opencv.org/modules/core/doc/intro.html) -- [ ] Clean up the codes with better coding style +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. ## Example +### OpenCV2's initCameraMatrix2D + +```go +package main + +import "github.com/lazywei/go-opencv/opencv2/gcv_utils" +import "github.com/lazywei/go-opencv/opencv2/gcv_calib3d" + +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)) + + 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)) + + cameraMatrix := GcvInitCameraMatrix2D(objPts, imgPts) +} +``` + + ### Resizing ```go @@ -124,5 +136,5 @@ You can find more samples at: https://github.com/lazywei/go-opencv/tree/master/s ## Disclaimer -This is a fork of [chai's go-opencv](https://github.com/chai2010/opencv). At the time of the fork (Dec 9, 2013) the original project was inactive, and hence I decide to host a fork on Github so people can contribute to this project easily. However, now it seems to be active again starting from Aug 25, 2014. Efforts to merge the two projects are very welcome. +This is a fork of [chai's go-opencv](https://github.com/chai2010/opencv), which has only OpenCV1 support through CGO. At the time of the fork (Dec 9, 2013) the original project was inactive, and hence I decide to host a fork on Github so people can contribute to this project easily. However, now it seems to be active again starting from Aug 25, 2014. Efforts to merge the two projects are very welcome.