opencv3.0的源码,之前很苦恼投影仪的标定,opencv提供了一个demo,上传源码:
#include <opencv2/highgui.hpp>
#include
#include
#include
#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 &patternCorners, Size patternSize, float squareSize,
int patternType);
void createProjectorObjectPoints(vector &patternCorners, Size patternSize, float squareSize,
int patternType);
double calibrate(vector< vector > objPoints, vector< vector > imgPoints,
Mat &cameraMatrix, Mat &distCoeffs, vector &r, vector &t, Size imgSize);
void fromCamToWorld(Mat cameraMatrix, vector rV, vector tV,
vector< vector > imgPoints, vector< vector > &worldPoints);
void saveCalibrationResults(String path, Mat camK, Mat camDistCoeffs, Mat projK, Mat projDistCoeffs,
Mat fundamental);
void saveCalibrationData(String path, vector T1, vector T2, vector ptsProjCam, vector ptsProjProj, vector ptsProjCamN, vector ptsProjProjN);
void normalize(const Mat &pts, const int& dim, Mat& normpts, Mat &T);
void fromVectorToMat(vector v, Mat &pts);
void fromMatToVector(Mat pts, vector &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> T1, T2;
vector<Mat> pro