Trying to wrap Calib3d with SWIG.

This commit is contained in:
Chih-Wei Chang 2015-02-13 16:47:55 +08:00
parent b491ec3c93
commit 2d7cc41b9c
7 changed files with 74 additions and 47 deletions

View file

@ -1,38 +0,0 @@
// Copyright 2014 <me@cwchang.me>. 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
}

View file

@ -1,9 +0,0 @@
package calib3d
import (
"testing"
)
func TestInitIntrinsicParams2D(t *testing.T) {
}

View file

@ -0,0 +1,29 @@
#include <opencv2/opencv.hpp>
#include "go_calib3d.hpp"
#include "iostream"
#include "vector"
using namespace std;
void
GoCalib3d::foo() {
cout << "Hello there" << endl;
vector< vector<cv::Point3f>> objPts;
vector< vector<cv::Point2f>> imgPts;
objPts.push_back(vector<cv::Point3f>());
imgPts.push_back(vector<cv::Point2f>());
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;
}

View file

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

View file

@ -0,0 +1,9 @@
class GoCalib3d
{
public:
GoCalib3d () {};
virtual ~GoCalib3d () {};
void foo();
private:
/* data */
};

View file

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

View file

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