diff --git a/README.md b/README.md index abdee3c..77df34a 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) @@ -36,11 +36,11 @@ cd ${GoOpenCVRoot}/trunk/samples && go run hellocv.go ## [WIP] OpenCV2 -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`) 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). +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 diff --git a/opencv2/gcv_core/README.md b/gocv/README.md similarity index 96% rename from opencv2/gcv_core/README.md rename to gocv/README.md index 0ce0500..898e4d5 100644 --- a/opencv2/gcv_core/README.md +++ b/gocv/README.md @@ -1,5 +1,5 @@ -Gcv Core -======== +Go OpenCV (GOlang openCV) +======================= Wrap the core types in OpenCV. diff --git a/opencv2/gcv_core/gcv_core.cpp b/gocv/gocv.cpp similarity index 98% rename from opencv2/gcv_core/gcv_core.cpp rename to gocv/gocv.cpp index 03cc031..3458147 100644 --- a/opencv2/gcv_core/gcv_core.cpp +++ b/gocv/gocv.cpp @@ -3,7 +3,7 @@ #include #include -#include "gcv_core.hpp" +#include "gocv.hpp" cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { cv::Mat cameraMatrix; diff --git a/opencv2/gcv_core/gcv_core.go b/gocv/gocv.go similarity index 97% rename from opencv2/gcv_core/gcv_core.go rename to gocv/gocv.go index e2c49c7..4f2e5f9 100644 --- a/opencv2/gcv_core/gcv_core.go +++ b/gocv/gocv.go @@ -1,4 +1,4 @@ -package gcv_core +package gocv // #cgo CXXFLAGS: -std=c++11 // #cgo darwin pkg-config: opencv diff --git a/opencv2/gcv_calib3d/gcv_calib3d.hpp b/gocv/gocv.hpp similarity index 100% rename from opencv2/gcv_calib3d/gcv_calib3d.hpp rename to gocv/gocv.hpp diff --git a/opencv2/gcv_core/gcv_core.swigcxx b/gocv/gocv.swigcxx similarity index 99% rename from opencv2/gcv_core/gcv_core.swigcxx rename to gocv/gocv.swigcxx index dd7ea96..be86413 100644 --- a/opencv2/gcv_core/gcv_core.swigcxx +++ b/gocv/gocv.swigcxx @@ -1,14 +1,14 @@ -%module gcv_core +%module gocv %include "std_vector.i" %{ #include "opencv2/core/types_c.h" #include "opencv2/core/version.hpp" #include "opencv2/core/core.hpp" -#include "gcv_core.hpp" +#include "gocv.hpp" %} -%include "gcv_core.hpp" +%include "gocv.hpp" /* Classes defined in core.hpp */ namespace cv { diff --git a/opencv2/gcv_core/gcv_core_test.go b/gocv/gocv_test.go similarity index 63% rename from opencv2/gcv_core/gcv_core_test.go rename to gocv/gocv_test.go index c2dfa4f..4a2771c 100644 --- a/opencv2/gcv_core/gcv_core_test.go +++ b/gocv/gocv_test.go @@ -1,4 +1,4 @@ -package gcv_core +package gocv import ( "testing" @@ -46,3 +46,23 @@ func TestGcvInitCameraMatrix2D(t *testing.T) { 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.cpp b/opencv2/gcv_calib3d/gcv_calib3d.cpp deleted file mode 100644 index 1b3f997..0000000 --- a/opencv2/gcv_calib3d/gcv_calib3d.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include - -#include "gcv_calib3d.hpp" - -cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { - cv::Mat cameraMatrix; - - std::vector objPtsArr; - std::vector imgPtsArr; - - objPtsArr.push_back(objPts); - imgPtsArr.push_back(imgPts); - - cameraMatrix = cv::initCameraMatrix2D(objPtsArr, imgPtsArr, cv::Size(1920, 1080), 1); - return cameraMatrix; -} - -double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts, - cv::Size 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, imgSize, - 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.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 0e9eccd..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_core" - -// [[[ 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_core.NewGcvPoint3fVector(int64(4)) - objPts.Set(0, gcv_core.NewGcvPoint3f(0, 25, 0)) - objPts.Set(1, gcv_core.NewGcvPoint3f(0, -25, 0)) - objPts.Set(2, gcv_core.NewGcvPoint3f(-47, 25, 0)) - objPts.Set(3, gcv_core.NewGcvPoint3f(-47, -25, 0)) - - imgPts := gcv_core.NewGcvPoint2fVector(int64(4)) - imgPts.Set(0, gcv_core.NewGcvPoint2f(1136.4140625, 1041.89208984)) - imgPts.Set(1, gcv_core.NewGcvPoint2f(1845.33190918, 671.39581299)) - imgPts.Set(2, gcv_core.NewGcvPoint2f(302.73373413, 634.79998779)) - imgPts.Set(3, gcv_core.NewGcvPoint2f(1051.46154785, 352.76107788)) - - GcvInitCameraMatrix2D(objPts, imgPts) -} - -func TestGcvCalibrateCamera(t *testing.T) { - objPts := gcv_core.NewGcvPoint3fVector(int64(4)) - objPts.Set(0, gcv_core.NewGcvPoint3f(0, 25, 0)) - objPts.Set(1, gcv_core.NewGcvPoint3f(0, -25, 0)) - objPts.Set(2, gcv_core.NewGcvPoint3f(-47, 25, 0)) - objPts.Set(3, gcv_core.NewGcvPoint3f(-47, -25, 0)) - - imgPts := gcv_core.NewGcvPoint2fVector(int64(4)) - imgPts.Set(0, gcv_core.NewGcvPoint2f(1136.4140625, 1041.89208984)) - imgPts.Set(1, gcv_core.NewGcvPoint2f(1845.33190918, 671.39581299)) - imgPts.Set(2, gcv_core.NewGcvPoint2f(302.73373413, 634.79998779)) - imgPts.Set(3, gcv_core.NewGcvPoint2f(1051.46154785, 352.76107788)) - - GcvInitCameraMatrix2D(objPts, imgPts) - - imgSize := gcv_core.NewGcvSize2i(1920, 1080) - - camMat := GcvInitCameraMatrix2D(objPts, imgPts) - - GcvCalibrateCamera(objPts, imgPts, imgSize, camMat) -} diff --git a/opencv2/gcv_core/gcv_core.hpp b/opencv2/gcv_core/gcv_core.hpp deleted file mode 100644 index 3710c3c..0000000 --- a/opencv2/gcv_core/gcv_core.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include - -typedef std::vector VecPoint3f; -typedef std::vector VecPoint2f; - -cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts); - -double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts, - cv::Size2i imgSize, cv::Mat cameraMatrix); 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