資源簡介
基于opencv的已知左右圖像坐標求空間中三維坐標,以及已知空間坐標求其在左右圖像中的二維坐標。

代碼片段和文件信息
//opencv2.4.9?vs2012
#include?
#include?
#include?
?
using?namespace?std;
using?namespace?cv;
?
Point2f?xyz2uv(Point3f?worldPointfloat?intrinsic[3][3]float?translation[1][3]float?rotation[3][3]);
Point3f?uv2xyz(Point2f?uvLeftPoint2f?uvRight);
?
//圖片對數量
int?PicNum?=?14;
?
//左相機內參數矩陣
float?leftIntrinsic[3][3]?=?{4037.82450 ?0 947.65449
??0 3969.79038 455.48718
??0 ?0 1};
//左相機畸變系數
float?leftDistortion[1][5]?=?{0.18962?-4.05566?-0.00510?0.02895?0};
//左相機旋轉矩陣
float?leftRotation[3][3]?=?{0.912333 -0.211508 ?0.350590?
0.023249 -0.828105 -0.560091?
0.408789 ?0.519140 -0.750590};
//左相機平移向量
float?leftTranslation[1][3]?=?{-127.199992?28.190639?1471.356768};
?
//右相機內參數矩陣
float?rightIntrinsic[3][3]?=?{3765.83307 ?0 339.31958
0 3808.08469 660.05543
0 ?0 1};
//右相機畸變系數
float?rightDistortion[1][5]?=?{-0.24195?5.97763?-0.02057?-0.01429?0};
//右相機旋轉矩陣
float?rightRotation[3][3]?=?{-0.134947 ?0.989568 -0.050442?
??0.752355 ?0.069205 -0.655113?
?-0.644788 -0.126356 -0.753845};
//右相機平移向量
float?rightTranslation[1][3]?=?{50.877397?-99.796492?1507.312197};
?
?
int?main()
{
//已知空間坐標求成像坐標
/*Point3f?point(700220530);
cout<<“左相機中坐標:“< cout< cout<<“右相機中坐標:“< cout<
//已知左右相機成像坐標求空間坐標
//Point2f?l?=?xyz2uv(pointleftIntrinsicleftTranslationleftRotation);
//Point2f?r?=?xyz2uv(pointrightIntrinsicrightTranslationrightRotation);
Point2f?l?=(2000?1000);
Point2f?r?=(10001000);
Point3f?worldPoint;
worldPoint?=?uv2xyz(lr);
cout<<“空間坐標為:“< ?
system(“pause“);
?
return?0;
}
?
?
//************************************
//?Description:?根據左右相機中成像坐標求解空間坐標
//?Method:????uv2xyz
//?FullName:??uv2xyz
//?Access:????public?
//?Parameter:?Point2f?uvLeft
//?Parameter:?Point2f?uvRight
//?Returns:???cv::Point3f
//?Author:????小白
//?Date:??????2017/01/10
//?History:
//************************************
Point3f?uv2xyz(Point2f?uvLeftPoint2f?uvRight)
{
//??[u1]??????|X| ??[u2]??????|X|
//Z*|v1|?=?Ml*|Y| Z*|v2|?=?Mr*|Y|
//??[?1]??????|Z| ??[?1]??????|Z|
// ??|1| |1|
Mat?mLeftRotation?=?Mat(33CV_32FleftRotation);
Mat?mLeftTranslation?=?Mat(31CV_32FleftTranslation);
Mat?mLeftRT?=?Mat(34CV_32F);//左相機M矩陣
hconcat(mLeftRotationmLeftTranslationmLeftRT);
Mat?mLeftIntrinsic?=?Mat(33CV_32FleftIntrinsic);
Mat?mLeftM?=?mLeftIntrinsic?*?mLeftRT;
//cout<<“左相機M矩陣?=?“< ?
Mat?mRightRotation?=?Mat(33CV_32FrightRotation);
Mat?mRightTranslation?=?Mat(31CV_32FrightTranslation);
Mat?mRightRT?=?Mat(34CV_32F);//右相機M矩陣
hconcat(mRightRotationmRightTranslationmRightRT);
Mat?mRightIntrinsic?=?Mat(3
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????80384??2018-11-12?17:44??xyz2uv\Debug\myfirst_opencv.exe
?????文件?????419016??2018-11-12?17:44??xyz2uv\Debug\myfirst_opencv.ilk
?????文件????2108416??2018-11-12?17:44??xyz2uv\Debug\myfirst_opencv.pdb
?????文件??????26563??2018-11-08?19:15??xyz2uv\girl.jpg
?????文件???????1322??2018-11-12?17:43??xyz2uv\myfirst_opencv\Debug\cl.command.1.tlog
?????文件??????19944??2018-11-12?17:43??xyz2uv\myfirst_opencv\Debug\CL.read.1.tlog
?????文件????????802??2018-11-12?17:43??xyz2uv\myfirst_opencv\Debug\CL.write.1.tlog
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
?????文件??????????2??2018-11-12?17:44??xyz2uv\myfirst_opencv\Debug\li
............此處省略51個文件信息
評論
共有 條評論