资源简介
利用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多目标遗传算法
相关资源
- 人脸识别(opencv_facedetect_v4l2)
- 基于opencv的模板匹配代码
- opencv图片扫描以及校正
- opencv手部轮廓识别以及轨迹识别
- opencv2 3D标定.cpp
- 基于opencv漫水填充算法综合
- opencv激光中心线的提取
- OpenCV Computer Vision Application Programming
- 基于图割的图像分割OpenCV+MFC实现
- 识别魔方颜色
- opencv版俄罗斯方块源码
- VS2013 / MFC + OpenCV 2.4.9实现视频的播放
- 粒子滤波器+目标跟踪的C++实现,VS2
- 张平OpenCV算法精讲基于python和C++教材
- 虹膜识别开源代码OSIRIS4.1基于opencv
- Sift特征点提取与匹配opencv库
- YCbCr、混合高斯以及YCbCg肤色检测模型
- 光流法代码
- OpenCV打开摄像机显示在MFC窗口工程源
- 使用c++读取图像到二维矩阵
- 三维点云的圆柱面拟合
- MFC+OPENCV摄像机标定程序
- 基于特征脸的人脸识别MFC+OpenCV
- opencv图像处理MFC
- OPENCV人脸检测加角点检测并输出坐标
- FillHole.rar
- 道路提取算法 c++ opencv
- PCA代码实现详解
- opencv卡尔曼滤波
- SeamCarving opencv c++
评论
共有 条评论