#include <iostream>
#include <fstream>
static void help() {
cout
<< "\n------------------------------------------------------------------\n"
<< " 這個程式展示了 OpenCV 運動結構 (SFM) 模組中的相機軌跡重建能力。\n"
<< " \n"
<< " \n"
<< " example_sfm_scene_reconstruction <檔案路徑> <f> <cx> <cy>\n"
<< " example_sfm_trajectory_reconstruction <tracks_file_path> <f> <cx> <cy>\n"
<< " 其中:是軌道檔案在您系統中的絕對路徑。\n"
<< " \n"
<< " 該檔案必須具有以下格式:\n"
<< " row1 : track 1 的 x1 y1 x2 y2 ... x36 y36\n"
<< " row2 : track 2 的 x1 y1 x2 y2 ... x36 y36\n"
<< " 等等\n"
<< " \n"
<< " 即,一行給出某個點在幀 1 到 36 中被跟蹤時測量的 2D 位置。如果在一個檢視中沒有找到匹配項,則 x\n"
<< " 和 y 是 -1。\n"
<< " 每行對應於一個不同的點。\n"
<< " \n"
<< " f 是以畫素為單位的焦距。\n"
<< " \n"
<< " cx 是影像主點的 x 座標,以畫素為單位。\n"
<< " cy 是影像主點的 y 座標,以畫素為單位。\n"
<< "------------------------------------------------------------------\n\n"
/* 構建以下結構資料
<< endl;
}
if (!myfile.is_open())
{
if (!myfile.is_open()) {
cout << "無法讀取檔案:" << _filename << endl;
{
double x, y;
exit(0);
} else {
int n_frames = 0, n_tracks = 0;
files.push_back(line_str);
// 從文字檔案中提取資料
for ( ; getline(myfile,line_str); ++n_tracks)
istringstream line(line_str);
{
vector<Vec2d> track;
for ( n_frames = 0; line >> x >> y; ++n_frames)
if ( x > 0 && y > 0)
{
track.push_back(
Vec2d(x,y));
track.push_back(
Vec2d(-1));
else
tracks.push_back(track);
}
// 將資料嵌入重建 API 格式
}
{
for (int j = 0; j < n_tracks; ++j)
frame(0,j) = tracks[j][i][0];
{
frame(1,j) = tracks[j][i][1];
points2d.push_back(
Mat(frame));
}
myfile.close();
}
/* 鍵盤迴調來控制 3D 視覺化
}
}
{
camera_pov = !camera_pov;
/* 示例主程式碼
}
// 從文字檔案中讀取 2D 點
{
// 解析影像路徑
{
help();
exit(0);
}
parser_2D_tracks( argv[1], points2d );
// 設定相機校準矩陣
bool is_projective = true;
bool is_projective = true;
0, 0, 1);
reconstruct(points2d, Rs_est, ts_est, K, points3d_estimated, is_projective);
reconstruct(images_paths, Rs_est, ts_est, K, points3d_estimated, is_projective);
cout << "\n----------------------------\n" << endl;
cout << "重建:" << endl;
cout << "============================" << endl;
cout << "估計的 3D 點:" << points3d_estimated.size() << endl;
cout << "估計的相機:" << Rs_est.size() << endl;
cout << "精煉的內參:" << endl << K << endl << endl;
cout << "3D 視覺化:" << endl;
cout << "估計的 3D 點:" << points3d_estimated.size() << endl;
window_est.setBackgroundColor();
window_est.registerKeyboardCallback(&keyboard_callback);
cout << "恢復點 ... ";
for (int i = 0; i < points3d_estimated.size(); ++i)
for (int i = 0; i < points3d_estimated.size(); ++i)
point_cloud_est.push_back(
Vec3f(points3d_estimated[i]));
cout << "[完成]" << endl;
cout << "恢復相機 ... ";
vector<Affine3d> path_est;
for (size_t i = 0; i < Rs_est.size(); ++i)
path_est.push_back(
Affine3d(Rs_est[i],ts_est[i]));
cout << "渲染軌跡 ... ";
cout << "恢復相機 ... ";
cout << endl << "按:" << endl;
cout << " 's' 切換相機視角" << endl;
cout << " 'q' 關閉視窗" << endl;
if ( path_est.size() > 0 )
// 動畫軌跡
{
while(!window_est.wasStopped())
for (size_t i = 0; i < point_cloud_est.size(); ++i)
{
Vec3d point = point_cloud_est[i];
{
char buffer[50];
sprintf (buffer, "%d", static_cast<int>(i));
cube_widget.setRenderingProperty(viz::LINE_WIDTH, 2.0);
window_est.showWidget(
"Cube"+
String(buffer), cube_widget, point_pose);
}
if ( camera_pov )
window_est.setViewerPose(cam_pose);
// 渲染完整的軌跡
else
{
window_est.showWidget("CPW", cpw, cam_pose);
window_est.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
// 更新軌跡索引(彈簧效果)
}
// 幀率 1s
window_est.removeAllWidgets();
指定其座標 x、y 和 z 的 3D 點的模板類。
}
}
return 0;
}
定義 affine.hpp:127
cv::Matx< double, 3, 3 >
從 Mat 派生的模板矩陣類。
定義 mat.hpp:2257
cv::Vec< double, 2 >
定義 types.hpp:255
此類表示鍵盤事件。
cv::viz::KeyboardEvent::symbol
定義 types.hpp:303
cv::viz::KeyboardEvent::action
定義 types.hpp:302
Viz3d 類表示 3D 視覺化視窗。此類是隱式共享的。
這個 3D 小部件透過其軸或視錐體表示場景中的相機位置....
定義 viz3d.hpp:68
void reconstruct(InputArrayOfArrays points2d, OutputArray Ps, OutputArray points3d, InputOutputArray K, bool is_projective=false)
定義 widgets.hpp:544
此 3D 小部件定義一個立方體。
定義 widgets.hpp:373
std::string String
定義 cvstd.hpp:151
#define CV_64F
Definition interface.h:79
在執行自動校準時,從 2D 對應點重建 3D 點。
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3