加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
calibrate.cpp 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
user_624340 提交于 2017-11-09 17:50 . new
#include <iostream>
#include <iomanip>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include "CameraCalibrator.h"
cv::Mat applyLookUp(const cv::Mat &image, const cv::MatND &lookup)
{
cv::Mat result(image.rows, image.cols, CV_8U);
cv::Mat_<uchar>::iterator itr = result.begin<uchar>();
cv::Mat_<uchar>::const_iterator it = image.begin<uchar>();
cv::Mat_<uchar>::const_iterator itend = image.end<uchar>();
for (; it != itend; ++it, ++itr)
{
*itr = lookup.at<uchar>(*it);
}
return result;
}
int main()
{
cv::namedWindow("Board Image");
cv::Mat image;
std::vector<std::string> filelist;
for (int i = 1; i <= 9; i++)
{
std::stringstream str;
str << "chessboards/right" << std::setw(2) << std::setfill('0') << i << ".jpg";
std::cout << str.str() << std::endl;
filelist.push_back(str.str());
image = cv::imread(str.str(), 0);
cv::imshow("Board Image", image);
cv::waitKey(100);
}
CameraCalibrator cameraCalibrator;
cv::Size boardSize(9, 6);
cameraCalibrator.addChessboardPoints(
filelist,
boardSize, "Detected points");
cameraCalibrator.calibrate(image.size());
image = cv::imread(filelist[6], 0);
cv::Mat uImage = cameraCalibrator.remap(image);
cv::Mat cameraMatrix = cameraCalibrator.getCameraMatrix();
std::cout << " Camera intrinsic: " << cameraMatrix.rows << "x" << cameraMatrix.cols << std::endl;
std::cout << cameraMatrix.at<double>(0, 0) << " " << cameraMatrix.at<double>(0, 1) << " " << cameraMatrix.at<double>(0, 2) << std::endl;
std::cout << cameraMatrix.at<double>(1, 0) << " " << cameraMatrix.at<double>(1, 1) << " " << cameraMatrix.at<double>(1, 2) << std::endl;
std::cout << cameraMatrix.at<double>(2, 0) << " " << cameraMatrix.at<double>(2, 1) << " " << cameraMatrix.at<double>(2, 2) << std::endl;
cv::namedWindow("Original Image");
cv::imshow("Original Image", image);
cv::namedWindow("Undistorted Image");
cv::imshow("Undistorted Image", uImage);
cv::waitKey();
return 0;
int dim(256);
cv::Mat lut(1,
&dim,
CV_8U);
for (int i = 0; i < 256; i++)
{
lut.at<uchar>(i) = 255 - i;
}
cv::namedWindow("Negative image");
cv::imshow("Negative image", applyLookUp(image, lut));
cv::waitKey();
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化