Draft for cv::initCameraMatrix2D
This commit is contained in:
parent
8f9e5b89d9
commit
49c0f9831b
10 changed files with 148 additions and 70 deletions
20
opencv2/gcv_calib3d/gcv_calib3d.cpp
Normal file
20
opencv2/gcv_calib3d/gcv_calib3d.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#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 = new std::vector<VecPoint3f>();
|
||||||
|
std::vector<VecPoint2f> *imgPtsArr = new std::vector<VecPoint2f>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package go_calib3d
|
package gcv_calib3d
|
||||||
|
|
||||||
// #cgo CXXFLAGS: -std=c++11
|
// #cgo CXXFLAGS: -std=c++11
|
||||||
// #cgo darwin pkg-config: opencv
|
// #cgo darwin pkg-config: opencv
|
||||||
8
opencv2/gcv_calib3d/gcv_calib3d.hpp
Normal file
8
opencv2/gcv_calib3d/gcv_calib3d.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#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);
|
||||||
15
opencv2/gcv_calib3d/gcv_calib3d.swigcxx
Normal file
15
opencv2/gcv_calib3d/gcv_calib3d.swigcxx
Normal file
|
|
@ -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<int>;
|
||||||
|
%template(DoubleVector) vector<double>;
|
||||||
|
};
|
||||||
32
opencv2/gcv_calib3d/gcv_calib3d_test.go
Normal file
32
opencv2/gcv_calib3d/gcv_calib3d_test.go
Normal file
|
|
@ -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())
|
||||||
|
}
|
||||||
72
opencv2/gcv_calib3d/gcv_core.hpp
Normal file
72
opencv2/gcv_calib3d/gcv_core.hpp
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<cv::Point3f> Get() { return _data; }
|
||||||
|
private:
|
||||||
|
std::vector<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;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GcvVecPoint2f
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GcvVecPoint2f () {};
|
||||||
|
~GcvVecPoint2f () {};
|
||||||
|
|
||||||
|
void PushBack(cv::Point2f pt) {
|
||||||
|
_data.push_back(pt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
_data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<cv::Point2f> Get() { return _data; }
|
||||||
|
private:
|
||||||
|
std::vector<cv::Point2f> _data;
|
||||||
|
};
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
class GoCalib3d
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GoCalib3d () {};
|
|
||||||
virtual ~GoCalib3d () {};
|
|
||||||
void foo();
|
|
||||||
private:
|
|
||||||
/* data */
|
|
||||||
};
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
%module go_calib3d
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "go_calib3d.hpp"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "go_calib3d.hpp"
|
|
||||||
|
|
@ -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()
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue