资源简介
利用opencv图像算法库实现对相机内外参的标定,并利用标定结果对畸变图像进行校正。
代码片段和文件信息
#include “stdio.h“
#include
#include
#include
#include “opencv2/opencv.hpp“
#include
#include “opencv2/calib3d/calib3d.hpp“
#include
using namespace std;
using namespace cv;
void getFiles(string path vector& files)
{
//文件句柄
intptr_t hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append(“\\*“).c_str() &fileinfo)) != -1)
{
do
{
//如果是目录迭代之
//如果不是加入列表
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name “.“) != 0 && strcmp(fileinfo.name “..“) != 0)
getFiles(p.assign(path).append(“\\“).append(fileinfo.name) files);
}
else
{
files.push_back(p.assign(path).append(“\\“).append(fileinfo.name));
}
} while (_findnext(hFile &fileinfo) == 0);
_findclose(hFile);
}
}
int main()
{
string filePath = “D:\\uidq0829\\Desktop\\rgb\\2“;
vector files;
////获取该路径下的所有文件
getFiles(filePath files);
const int board_w = 9;
const int board_h = 9;
const int NPoints = board_w * board_h;//棋盘格内角点总数
const int boardSize = 20; //mm
Mat image grayimage;
Size ChessBoardSize = cv::Size(board_w board_h);
vector tempcorners;
vector object;
for (int j = 0; j < NPoints; j++)
{
object.push_back(Point3f((j % board_w) * boardSize (j / board_w) * boardSize 0));
}
cv::Matx33d intrinsics;//z:相机内参
//cv::Vec4d distortion_coeff;//z:相机畸变系数
cv::Mat distortion_coeff; //z:相机畸变系数
vector > objectv;
vector > imagev;
Size corrected_size(1280 720);
Mat mapx mapy;
Mat corrected;
ofstream intrinsicfile(“intrinsics_front1103.txt“);
ofstream disfile(“dis_coeff_front1103.txt“);
int num = 0;
bool bCalib = false;
namedWindow(“corner_image“ 0);
resizeWindow(“corner_image“ Size(1280 720));
namedWindow(“corrected“ 0);
resizeWindow(“corrected“ Size(1280 720));
while (num < files.size())
{
image = imread(files[num]);
if (image.empty())
break;
imshow(“corner_image“ image);
waitKey(10);
cvtColor(image grayimage CV_BGR2GRAY);
IplImage tempgray = grayimage;
bool findchessboard = cvCheckChessboard(&tempgray ChessBoardSize);
if (findchessboard)
{
bool find_corners_result = findChessboardCorners(grayimage ChessBoardSize tempcorners 3);
if (find_corners_result)
{
cornerSubPix(grayimage tempcorners cvSize(5 5) cvSize(-1 -1) cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER 30 0.1));
drawChessboardCorners(image ChessBoardSize tempcorners find_corners_result);
imshow(“corner_image“ image);
cvWaitKey(2000);
objectv.push_back(object);
imagev.push_back(tempcorners);
cout << “capture “ << num << “ pictures“ << endl;
}
}
tempcorners.clear();
num++;
}
//cv::Mat cameraMatirx distCoeffs;
std::vector r
- 上一篇:使用C语言来扩展PHP,写PHP扩展dll
- 下一篇:NSGA多目标遗传算法
相关资源
- moravec算子c++代码
- openCV中stitching_detailed.cpp
- 11个常用OpenCV+C++图像处理
- opencv计算5*5邻域方差图
- opencv 视觉 追踪跟踪 经典kcf算法
- vc++6.0配置OpenCV
- 基于OpenCV的图像检索系统(源码)
- test_opencv.cpp
- opencv提取图片中人轮廓
- Python3+Opencv343环境搭建 dll load failed问
- 04_图像编辑器实现.zip
- 基于opencv人眼定位算法C++工程
- 图像连续拼接算法源码
- opencv 2.4.8 官方最新版安装与配置
- C++实现opencv+yolo+tensorflow+deepsort.txt
- Opencv封装成dll供.net调用方法
- 相机标定棋盘
- 自适应图像增强完整OpenCV代码
- 在mfc中picture控件中显示Mat图片
- OpenCv实现两个图片的相似度
- opencv椭圆拟合长短轴比
- Retinex算法,C++,opencv
- 利用opencv实现的条形码检测与识别C
- Opencv2.4.12 SVM手写数字识别
- opencv 正脸+左右侧脸全检测
- 激光雷达数据读取、显示、分割、直
- CvvImage类库
- 基于opencv的C++人眼识别以及眨眼检测
- 在VS2012上基于opencv的C++人眼识别与眨
- 基于暗通道和导向滤波的图像去雾算
评论
共有 条评论