• 大小: 6.5MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-30
  • 语言: 其他
  • 标签: 双目视觉  

资源简介

基于VISUALSTUDIO2013OPENCV2.4.10下的双目摄像机标定立体匹配矫正最后实现三维重建功能

资源截图

代码片段和文件信息

#include“opcv.h“
//初始化棋盘角点数据信息
int initCornerData(int nImages cv::Size imageSize cv::Size boardSize float squareWidth)
{
cornerDatas.nImages = nImages;
cornerDatas.imageSize = imageSize;
cornerDatas.boardSize = boardSize;
cornerDatas.nPoints = nImages*boardSize.width*boardSize.height;
cornerDatas.nPointsPerImage = boardSize.width*boardSize.height;
cornerDatas.objectPoints.resize(nImages vector(cornerDatas.nPointsPerImage cv::Point3f(0 0 0)));
cornerDatas.imagePointsl.resize(nImages vector(cornerDatas.nPointsPerImage cv::Point2f(0 0)));
cornerDatas.imagePointsr.resize(nImages vector(cornerDatas.nPointsPerImage cv::Point2f(0 0)));
//计算角点的世界坐标值
int i j k n;
for (i = 0; i < nImages; i++)
{
n = 0;
for (j = 0; j < boardSize.height; j++)
for (k = 0; k < boardSize.width; k++)
cornerDatas.objectPoints[i][n++] = cv::Point3f(j*squareWidth k*squareWidth 0);
}
return 1;
}
//检测棋盘角点
int detectCorners(cv::Mat& imgl cv::Mat& imgr int imageCount)
{
bool stereoMode = true;
if (!(!imgl.empty())*(!imgr.empty()))
{
stereoMode = false;
}
// 提取当前棋盘对应的角点坐标子矩阵
vector& cornersl = cornerDatas.imagePointsl[imageCount];
vector& cornersr = cornerDatas.imagePointsr[imageCount];
bool foundl = false;
bool foundr = true;
int flags = CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE;
// 寻找棋盘及其角点
if (stereoMode)
{
foundl = findChessboardCorners(imgl cornerDatas.boardSize cornersl flags);
foundr = findChessboardCorners(imgr cornerDatas.boardSize cornersr flags);
}
else
{
if (!imgl.empty())
foundl = findChessboardCorners(imgl cornerDatas.boardSize cornersl flags);
if (!imgr.empty())
foundr = findChessboardCorners(imgr cornerDatas.boardSize cornersr flags);
}
// 若左右视图都成功检测到所有角点
// 则将检测到的角点坐标精确化
if (foundl && foundr)
{
//转换为灰度图
cv::Mat grayl grayr;
cvtColor(imgl grayl CV_RGB2GRAY);
if (stereoMode)
cvtColor(imgr grayr CV_RGB2GRAY);

//计算角点的精确坐标
cv::Size regionSize(2 2);
cornerSubPix(grayl cornersl regionSize cv::Size(-1 -1) cv::TermCriteria(cv::TermCriteria::EPS | cv::TermCriteria::MAX_ITER 30 0.01));
if (stereoMode)
cornerSubPix(grayr cornersr regionSize cv::Size(-1 -1) cv::TermCriteria(cv::TermCriteria::EPS | cv::TermCriteria::MAX_ITER 30 0.01));
}
// 显示检测到的角点
if (stereoMode)
{
drawChessboardCorners(imgl cornerDatas.boardSize cornersl foundl);
drawChessboardCorners(imgr cornerDatas.boardSize cornersr foundr);
}
else
{
if (!imgl.empty())
drawChessboardCorners(imgl cornerDatas.boardSize cornersl foundl);
if (!imgr.empty())
drawChessboardCorners(imgr cornerDatas.boardSize cornersr foundr);
}
if (stereoMode && foundl && foundr)
return 1;
else
return 0;
}
//执行双目摄像机标定若每个摄像机尚未标定,则首先进行单目标定,再进行双目标定
int calibrateStereoCamera(bool cameraUncalibrated)
{
if (cameraUn

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-01-29 18:19  binocularvision2\
     目录           0  2016-01-29 18:16  binocularvision2\binocularvision2\
     文件    16121856  2016-01-29 18:19  binocularvision2\binocularvision2.sdf
     文件         994  2016-01-15 17:07  binocularvision2\binocularvision2.sln
     文件       35328  2016-01-29 18:19  binocularvision2\binocularvision2.v12.suo
     文件        5202  2016-01-16 16:01  binocularvision2\binocularvision2\binocularvision2.vcxproj
     文件        1342  2016-01-16 15:50  binocularvision2\binocularvision2\binocularvision2.vcxproj.filters
     目录           0  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\
     文件        2280  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.log
     目录           0  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.tlog\
     文件         166  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.tlog\binocularvision2.lastbuildstate
     文件        1570  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.tlog\cl.command.1.tlog
     文件       38676  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.tlog\CL.read.1.tlog
     文件        1674  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.tlog\CL.write.1.tlog
     文件        2188  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.tlog\link.command.1.tlog
     文件        5108  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.tlog\link.read.1.tlog
     文件         572  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\binocularvision2.tlog\link.write.1.tlog
     文件      882972  2016-01-20 11:20  binocularvision2\binocularvision2\Debug\initCornerData.obj
     文件      242970  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\main.obj
     文件      871424  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\vc120.idb
     文件     1650688  2016-01-29 11:29  binocularvision2\binocularvision2\Debug\vc120.pdb
     文件       23815  2016-01-29 17:58  binocularvision2\binocularvision2\initCornerData.cpp
     文件         485  2016-01-16 17:27  binocularvision2\binocularvision2\initialboard.h
     文件        6575  2016-01-29 18:16  binocularvision2\binocularvision2\main.cpp
     文件        1865  2016-01-16 17:21  binocularvision2\binocularvision2\opcv.h
     文件        2229  2016-01-29 17:57  binocularvision2\binocularvision2\touwen.h
     目录           0  2016-01-20 11:20  binocularvision2\Debug\
     文件      201728  2016-01-29 11:29  binocularvision2\Debug\binocularvision2.exe
     文件      860860  2016-01-29 11:29  binocularvision2\Debug\binocularvision2.ilk
     文件     2772992  2016-01-29 11:29  binocularvision2\Debug\binocularvision2.pdb

评论

共有 条评论