Move all code to gocv package.

This commit is contained in:
Chih-Wei Chang 2015-02-16 12:44:44 +08:00
parent c9330d1782
commit 1f479722a3
13 changed files with 32 additions and 135 deletions

View file

@ -3,7 +3,7 @@ Go OpenCV binding
A Golang binding for [OpenCV](http://opencv.org/). 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) [**DISCLAIMER**](https://github.com/lazywei/go-opencv#disclaimer)
@ -36,11 +36,11 @@ cd ${GoOpenCVRoot}/trunk/samples && go run hellocv.go
## [WIP] OpenCV2 ## [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 ## Example

View file

@ -1,5 +1,5 @@
Gcv Core Go OpenCV (GOlang openCV)
======== =======================
Wrap the core types in OpenCV. Wrap the core types in OpenCV.

View file

@ -3,7 +3,7 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "gcv_core.hpp" #include "gocv.hpp"
cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) { cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) {
cv::Mat cameraMatrix; cv::Mat cameraMatrix;

View file

@ -1,4 +1,4 @@
package gcv_core package gocv
// #cgo CXXFLAGS: -std=c++11 // #cgo CXXFLAGS: -std=c++11
// #cgo darwin pkg-config: opencv // #cgo darwin pkg-config: opencv

View file

@ -1,14 +1,14 @@
%module gcv_core %module gocv
%include "std_vector.i" %include "std_vector.i"
%{ %{
#include "opencv2/core/types_c.h" #include "opencv2/core/types_c.h"
#include "opencv2/core/version.hpp" #include "opencv2/core/version.hpp"
#include "opencv2/core/core.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 */ /* Classes defined in core.hpp */
namespace cv { namespace cv {

View file

@ -1,4 +1,4 @@
package gcv_core package gocv
import ( import (
"testing" "testing"
@ -46,3 +46,23 @@ func TestGcvInitCameraMatrix2D(t *testing.T) {
spew.Dump(camMat.GcvAtd(NewGcvSize2i(1, 2))) spew.Dump(camMat.GcvAtd(NewGcvSize2i(1, 2)))
spew.Dump(camMat.GcvAtd(NewGcvSize2i(2, 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)
}

View file

@ -1,43 +0,0 @@
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include <vector>
#include "gcv_calib3d.hpp"
cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) {
cv::Mat cameraMatrix;
std::vector<VecPoint3f> objPtsArr;
std::vector<VecPoint2f> 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<VecPoint3f> objPtsArr;
std::vector<VecPoint2f> imgPtsArr;
std::vector<cv::Mat> 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;
}

View file

@ -1,5 +0,0 @@
package gcv_calib3d
// #cgo CXXFLAGS: -std=c++11
// #cgo darwin pkg-config: opencv
import "C"

View file

@ -1,7 +0,0 @@
%module gcv_calib3d
%{
#include "gcv_calib3d.hpp"
%}
%include "gcv_calib3d.hpp"

View file

@ -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)
}

View file

@ -1,11 +0,0 @@
#include <opencv2/opencv.hpp>
#include <vector>
#include <iostream>
typedef std::vector<cv::Point3f> VecPoint3f;
typedef std::vector<cv::Point2f> VecPoint2f;
cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts);
double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts,
cv::Size2i imgSize, cv::Mat cameraMatrix);

View file

@ -1 +0,0 @@
package opencv2