just do it

与其苟延残喘,不如纵情燃烧

相机标定

相机标定&读取摄像头


(因为用到的摄像头是红外线摄像头(监控摄像头),有必要了解其原理)从光谱来讲,和普通摄像头感可见光原理类似。红外摄像头工作原理是红外灯发出红外线照射物体,红外线漫反射,被监控摄像头接收,形成视频图像。

calibrate.h() ``` class CameraCalibrator { vector> objectPoints; vector> imagePoints;

Mat cameraMatrix;
Mat distCoeffs;

int flag;

Mat map1, map2;
bool mustInitUndistort;

public:
CameraCalibrator() : flag(0), mustInitUndistort(true) {};

int addChessboardPoints(const std::vectorstd::string& filelist, cv::Size & boardSize);
// Add scene points and corresponding image points
void addPoints(const std::vectorcv::Point2f& imageCorners, const std::vectorcv::Point3f& objectCorners);
// Calibrate the camera
double calibrate(cv::Size &imageSize);
// Set the calibration flag
void setCalibrationFlag(bool radial8CoeffEnabled = false, bool tangentialParamEnabled = false);
// Remove distortion in an image (after calibration)
cv::Mat CameraCalibrator::remap(const cv::Mat &image);

// Getters
cv::Mat getCameraMatrix() { return cameraMatrix; }
cv::Mat getDistCoeffs() { return distCoeffs; }
};

</details>

<details>
<summary><mark><font color=red>CameraCalibrator.cpp</font></mark></summary>

include "CameraCalibrator.h"

using namespace cv;
cv::Mat CameraCalibrator::remap(const cv::Mat &image) {

cv::Mat undistorted;

if (mustInitUndistort) { // called once per calibration

cv::initUndistortRectifyMap(
cameraMatrix, // computed camera matrix
distCoeffs, // computed distortion matrix
cv::Mat(), // optional rectification (none)
cv::Mat(), // camera matrix to generate undistorted
cv::Size(720, 540),
// image.size(), // size of undistorted
CV_32FC1, // type of output map
map1, map2); // the x and y mapping functions

mustInitUndistort = false;
}

// Apply mapping functions
cv::remap(image, undistorted, map1, map2,
cv::INTER_LINEAR); // interpolation type

return undistorted;
}

</details>
posted @ 2019-05-16 22:42  elong1995  阅读(217)  评论(0)    收藏  举报