-
大小: 20.77MB文件類(lèi)型: .7z金幣: 1下載: 0 次發(fā)布日期: 2023-08-02
- 語(yǔ)言: 其他
- 標(biāo)簽: 相機(jī)標(biāo)定??
資源簡(jiǎn)介
opencv相機(jī)標(biāo)定,加上圖像坐標(biāo)到世界坐標(biāo)的轉(zhuǎn)化
代碼片段和文件信息
//#include???
//#include???
//#include?“cv.h“??
//#include???
//#include???
//#include??
//#include?“atlstr.h“?
#include?“opencv2/core/core.hpp“
#include?“opencv2/imgproc/imgproc.hpp“
#include?“opencv2/calib3d/calib3d.hpp“
#include?“opencv2/highgui/highgui.hpp“
#include?
#include?
using?namespace?std;
using?namespace?cv;
const?int?imageWidth?=?1600;?????????????????????????????//攝像頭的分辨率??
const?int?imageHeight?=?1200;
const?int?boardWidth?=?7;???????????????????????????????//橫向的角點(diǎn)數(shù)目??
const?int?boardHeight?=?7;??????????????????????????????//縱向的角點(diǎn)數(shù)據(jù)??
const?int?boardCorner?=?boardWidth?*?boardHeight;???????//總的角點(diǎn)數(shù)據(jù)??
const?int?frameNumber?=13;?????????????????????????????//相機(jī)標(biāo)定時(shí)需要采用的圖像幀數(shù)??
const?int?squareSize?=?20;??????????????????????????????//標(biāo)定板黑白格子的大小?單位mm??
const?Size?boardSize?=?Size(boardWidth?boardHeight);???//??
Mat?intrinsic;??????????????????????????????????????????//相機(jī)內(nèi)參數(shù)??
Mat?distortion_coeff;???????????????????????????????????//相機(jī)畸變參數(shù)??
vector?rvecs;????????????????????????????????????????//旋轉(zhuǎn)向量??
vector?tvecs;????????????????????????????????????????//平移向量??
vector>?corners;????????????????????????//各個(gè)圖像找到的角點(diǎn)的集合?和objRealPoint?一一對(duì)應(yīng)??
vector>?objRealPoint;???????????????????//各副圖像的角點(diǎn)的實(shí)際物理坐標(biāo)集合??
vector?corner;???????????????????????????????????//某一副圖像找到的角點(diǎn)??
Mat?rgbImage?grayImage;
/*計(jì)算標(biāo)定板上模塊的實(shí)際物理坐標(biāo)*/
void?calRealPoint(vector>&?obj?int?boardwidth?int?boardheight?int?imgNumber?int?squaresize)
{
//??Mat?imgpoint(boardheight?boardwidth?CV_32FC3Scalar(000));??
vector?imgpoint;
for?(int?rowIndex?=?0;?rowIndex? {
for?(int?colIndex?=?0;?colIndex? {
//??imgpoint.at(rowIndex?colIndex)?=?Vec3f(rowIndex?*?squaresize?colIndex*squaresize?0);??
imgpoint.push_back(Point3f(colIndex?*?squaresize?rowIndex?*?squaresize?0));
}
}
for?(int?imgIndex?=?0;?imgIndex? {
obj.push_back(imgpoint);
}
}
/*設(shè)置相機(jī)的初始參數(shù)?也可以不估計(jì)*/
void?CalibrationEvaluate(void)//標(biāo)定結(jié)束后進(jìn)行評(píng)價(jià)
{
double?err=0;
double?total_err=0;
//calibrateCamera(objRealPoint?corners?Size(imageWidth?imageHeight)?intrinsic?distortion_coeff?rvecs?tvecs?0);
cout?<“每幅圖像的定標(biāo)誤差:“?< for?(int?i?=?0;?i? {
vector?image_points2;
vector?tempPointSet?=?objRealPoint[i];
projectPoints(tempPointSet?rvecs[i]?tvecs[i]?intrinsic?distortion_coeff?image_points2);
vector?tempImagePoint?=?corners[i];
Mat?tempImagePointMat?=?Mat(1?tempImagePoint.size()?CV_32FC2);
Mat?image_points2Mat?=?Mat(1?image_points2.size()?CV_32FC2);
for?(int?j?=?0;?j? {
image_points2Mat.at(0?j)?=?Vec2f(image_points2[j].x?image_points2[j].y);
tempImagePointM
評(píng)論
共有 條評(píng)論