Trying to wrap Calib3d with SWIG.
This commit is contained in:
parent
b491ec3c93
commit
2d7cc41b9c
7 changed files with 74 additions and 47 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package calib3d
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInitIntrinsicParams2D(t *testing.T) {
|
||||
|
||||
}
|
||||
29
opencv/calib3d/go_calib3d.cpp
Normal file
29
opencv/calib3d/go_calib3d.cpp
Normal 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;
|
||||
}
|
||||
5
opencv/calib3d/go_calib3d.go
Normal file
5
opencv/calib3d/go_calib3d.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package go_calib3d
|
||||
|
||||
// #cgo CXXFLAGS: -std=c++11
|
||||
// #cgo darwin pkg-config: opencv
|
||||
import "C"
|
||||
9
opencv/calib3d/go_calib3d.hpp
Normal file
9
opencv/calib3d/go_calib3d.hpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class GoCalib3d
|
||||
{
|
||||
public:
|
||||
GoCalib3d () {};
|
||||
virtual ~GoCalib3d () {};
|
||||
void foo();
|
||||
private:
|
||||
/* data */
|
||||
};
|
||||
7
opencv/calib3d/go_calib3d.swigcxx
Normal file
7
opencv/calib3d/go_calib3d.swigcxx
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%module go_calib3d
|
||||
|
||||
%{
|
||||
#include "go_calib3d.hpp"
|
||||
%}
|
||||
|
||||
%include "go_calib3d.hpp"
|
||||
24
opencv/calib3d/go_calib3d_test.go
Normal file
24
opencv/calib3d/go_calib3d_test.go
Normal 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()
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue