7.结构光:投影仪的标定(OpenCV)

最近看了一下opencv3.0的源码,之前很苦恼投影仪的标定,opencv提供了一个demo,上传源码:

#include <opencv2/highgui.hpp>
#include <vector>
#include <iostream>
#include <fstream>

#include <opencv2/core.hpp>
#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>

using namespace std;
using namespace cv;

static const char* keys =
{
	"{@camSettingsPath | | Path of camera calibration file}"
	"{@projSettingsPath | | Path of projector settings}"
	"{@patternPath | | Path to checkerboard pattern}"
	"{@outputName | | Base name for the calibration data}"
};

static void help()
{
	cout << "\nThis example calibrates a camera and a projector" << endl;
	cout << "To call: ./example_structured_light_projectorcalibration <cam_settings_path> "
		" <proj_settings_path> <chessboard_path> <calibration_basename>"
		" cam settings are parameters about the chessboard that needs to be detected to"
		" calibrate the camera and proj setting are the same kind of parameters about the chessboard"
		" that needs to be detected to calibrate the projector" << endl;
}
enum calibrationPattern
{	
	CHESSBOARD, 
	CIRCLES_GRID,
	ASYMETRIC_CIRCLES_GRID 
};

struct Settings
{
	Settings();
	int patternType;
	Size patternSize;
	Size subpixelSize;
	Size imageSize;
	float squareSize;
	int nbrOfFrames;
};

void loadSettings(String path, Settings &sttngs);
void createObjectPoints(vector<Point3f> &patternCorners, Size patternSize, float squareSize,
	int patternType);
void createProjectorObjectPoints(vector<Point2f> &patternCorners, Size patternSize, float squareSize,
	int patternType);
double calibrate(vector< vector<Point3f> > objPoints, vector< vector<Point2f> > imgPoints,
	Mat &cameraMatrix, Mat &distCoeffs, vector<Mat> &r, vector<Mat> &t, Size imgSize);
void fromCamToWorld(Mat cameraMatrix, vector<Mat> rV, vector<Mat> tV,
	vector< vector<Point2f> > imgPoints, vector< vector<Point3f> > &worldPoints);
void saveCalibrationResults(String path, Mat camK, Mat camDistCoeffs, Mat projK, Mat projDistCoeffs,
	Mat fundamental);
void saveCalibrationData(String path, vector<Mat> T1, vector<Mat> T2, vector<Mat> ptsProjCam, vector<Mat> ptsProjProj, vector<Mat> ptsProjCamN, vector<Mat> ptsProjProjN);
void normalize(const Mat &pts, const int& dim, Mat& normpts, Mat &T);
void fromVectorToMat(vector<Point2f> v, Mat &pts);
void fromMatToVector(Mat pts, vector<Point2f> &v);

int main(int argc, char **argv)
{
	VideoCapture cap(CAP_PVAPI);
	Mat frame;

	int nbrOfValidFrames = 0;

	vector< vector<Point2f> > imagePointsCam, imagePointsProj, PointsInProj, imagePointsProjN, pointsInProjN;
	vector< vector<Point3f> > objectPointsCam, worldPointsProj;
	vector<Point3f> tempCam;
	vector<Point2f> tempProj;
	vector<Mat&
  • 3
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值