Wrap CalibrateCamera
This commit is contained in:
parent
8aad62212a
commit
7a78947362
4 changed files with 60 additions and 8 deletions
|
|
@ -5,16 +5,40 @@
|
|||
|
||||
#include "gcv_calib3d.hpp"
|
||||
|
||||
cv::Mat gcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts) {
|
||||
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>();
|
||||
std::vector<VecPoint3f> objPtsArr;
|
||||
std::vector<VecPoint2f> imgPtsArr;
|
||||
|
||||
objPtsArr->push_back(objPts);
|
||||
imgPtsArr->push_back(imgPts);
|
||||
objPtsArr.push_back(objPts);
|
||||
imgPtsArr.push_back(imgPts);
|
||||
|
||||
cameraMatrix = cv::initCameraMatrix2D(*objPtsArr, *imgPtsArr, cv::Size(1920, 1080), 1);
|
||||
std::cout << cameraMatrix << std::endl;
|
||||
cameraMatrix = cv::initCameraMatrix2D(objPtsArr, imgPtsArr, cv::Size(1920, 1080), 1);
|
||||
return cameraMatrix;
|
||||
}
|
||||
|
||||
double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts,
|
||||
std::vector<int> 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,
|
||||
cv::Size2i(imgSize[0], imgSize[1]),
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,7 @@
|
|||
typedef std::vector<cv::Point3f> VecPoint3f;
|
||||
typedef std::vector<cv::Point2f> VecPoint2f;
|
||||
|
||||
cv::Mat gcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts);
|
||||
cv::Mat GcvInitCameraMatrix2D(VecPoint3f objPts, VecPoint2f imgPts);
|
||||
|
||||
double GcvCalibrateCamera(VecPoint3f objPts, VecPoint2f imgPts,
|
||||
std::vector<int> imgSize, cv::Mat cameraMatrix);
|
||||
|
|
|
|||
|
|
@ -32,3 +32,25 @@ func TestGcvInitCameraMatrix2D(t *testing.T) {
|
|||
|
||||
GcvInitCameraMatrix2D(objPts, imgPts)
|
||||
}
|
||||
|
||||
func TestGcvCalibrateCamera(t *testing.T) {
|
||||
objPts := gcv_utils.NewGcvPoint3fVector(int64(4))
|
||||
objPts.Set(0, gcv_utils.GetPoint3f(0, 25, 0))
|
||||
objPts.Set(1, gcv_utils.GetPoint3f(0, -25, 0))
|
||||
objPts.Set(2, gcv_utils.GetPoint3f(-47, 25, 0))
|
||||
objPts.Set(3, gcv_utils.GetPoint3f(-47, -25, 0))
|
||||
|
||||
imgPts := gcv_utils.NewGcvPoint2fVector(int64(4))
|
||||
imgPts.Set(0, gcv_utils.GetPoint2f(1136.4140625, 1041.89208984))
|
||||
imgPts.Set(1, gcv_utils.GetPoint2f(1845.33190918, 671.39581299))
|
||||
imgPts.Set(2, gcv_utils.GetPoint2f(302.73373413, 634.79998779))
|
||||
imgPts.Set(3, gcv_utils.GetPoint2f(1051.46154785, 352.76107788))
|
||||
|
||||
imgSize := gcv_utils.NewGcvIntVector(int64(2))
|
||||
imgSize.Set(0, 1920)
|
||||
imgSize.Set(1, 1080)
|
||||
|
||||
camMat := GcvInitCameraMatrix2D(objPts, imgPts)
|
||||
|
||||
GcvCalibrateCamera(objPts, imgPts, imgSize, camMat)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,7 @@
|
|||
namespace std {
|
||||
%template(GcvPoint3fVector) vector<cv::Point3f>;
|
||||
%template(GcvPoint2fVector) vector<cv::Point2f>;
|
||||
|
||||
%template(GcvIntVector) vector<int>;
|
||||
%template(GcvFloatVector) vector<float>;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue