Skip to content
Permalink
16e941848f
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
101 lines (80 sloc) 3.26 KB
/** \file dab_tracker_optical_calibration.h
*/
#pragma once
#include <iostream>
#include "ofxCVImage.h"
#include "dab_tracker_video_processor.h"
namespace dab
{
namespace tracker
{
class OpticalCalibration : public VideoProcessor
{
public:
enum Pattern { NOT_EXISTING, CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };
enum Mode { CALIBRATING, CALIBRATED };
OpticalCalibration(ofxCvImage* pInputImage);
~OpticalCalibration();
ofxCvImage* outputImage();
Mode calibrationMode() const;
std::array<float, 9> cameraMatrix() const;
std::array<float, 8> distCoefficients() const;
void startCalibration();
void captureCalibationPattern();
void setCameraMatrix(const std::array<float, 9>& pCameraMatrix);
void setDistCoefficients(const std::array<float, 8>& pDistCoefficients);
void setupGui(ofxDatGui* pGui);
void update() throw (dab::Exception);
void display() throw (dab::Exception);
void saveSettings() throw (dab::Exception);
void restoreSettings() throw (dab::Exception);
protected:
static cv::Size sBoardSize;
static Pattern sBoardPattern;
static float sSquareSize;
static Mode sCalibrationMode;
static unsigned int sCalibrationFrameCount;
static double sCaptureInterval;
cv::Size mBoardSize; // The size of the board -> Number of items by width and height
Pattern mBoardPattern; // One of the Chessboard, circles, or asymmetric circle pattern
float mSquareSize; // The size of a square in your defined unit (point, millimeter,etc).
Mode mCalibrationMode;
float mAspectRatio;
float mCaptureInterval;
double mPreviousCaptureTime;
bool mCapturePatternNow;
bool mCalibZeroTangentDist; // Assume zero tangential distortion
bool mCalibFixPrincipalPoint;// Fix the principal point at the center
bool mFlipVertical; // Flip the captured images around the horizontal axis
int mFlag;
ofxCvImage* mInputImage;
ofxCvImage* mOutputImage;
std::array<int, 2> mFrameSize;
std::vector< std::vector<cv::Point2f> > mImagePoints;
unsigned int mCalibrationFrameCount;
cv::Mat mCameraMatrix;
cv::Mat mDistCoeffs;
std::vector<cv::Mat> mCameraRotations;
std::vector<cv::Mat> mCameraTranslations;
bool detectCalibrationPattern(cv::Mat& pInputImage, std::vector<cv::Point2f>& pPatternPoints);
bool runCalibration();
void calcBoardCornerPositions(vector<cv::Point3f>& pCorners);
double computeReprojectionErrors(const vector<vector<cv::Point3f> >& cvObjectPoints,const std::vector<cv::Mat>& pRvecs, const std::vector<cv::Mat>& pTvecs, std::vector<float>& pPerViewErrors);
// gui
ofxDatGuiFolder* mGuiFolder;
ofxDatGuiTextInput* mBoardSizeXControl;
ofxDatGuiTextInput* mBoardSizeYControl;
ofxDatGuiTextInput* mSquareSizeControl;
ofxDatGuiDropdown* mBoardPatternControl;
ofxDatGuiTextInput* mCalibrationFrameCountControl;
ofxDatGuiTextInput* mCaptureIntervalControl;
ofxDatGuiTextInput* mAspectRatioControl;
ofxDatGuiToggle* mFlipVerticalControl;
ofxDatGuiButton* mStartCalibrationControl;
ofxDatGuiToggle* mCapturePatternNowControl;
void onTextInputEvent(ofxDatGuiTextInputEvent e);
void onDropdownEvent(ofxDatGuiDropdownEvent e);
void onButtonEvent(ofxDatGuiButtonEvent e);
};
};
};