opencv4 0棋盤格標定c

2021-10-06 03:26:38 字數 1954 閱讀 3300

參考  修改

#include #include #include #include #include using namespace cv;

using namespace std;

void m_calibration(vector&filesname, size board_size, size square_size, mat &cameramatrix, mat &distcoeffs, vector&rvecsmat, vector&tvecsmat)

/* 提取角點 */

bool bres = findchessboardcorners(imageinput, board_size, image_points, 0);

if (bres)

else

}cout << "角點提取完成!!!" << endl;

/*棋盤三維資訊*/

vector> object_points_seq; // 儲存標定板上角點的三維座標

for (int t = 0; t < image_count; t++)

}object_points_seq.push_back(object_points);

}/* 執行標定函式 */

double rms = calibratecamera(object_points_seq, image_points_seq, image_size, cameramatrix, distcoeffs, rvecsmat, tvecsmat, cv::calib_fix_k3 + cv::calib_zero_tangent_dist);

cout << "rms:" << rms << "畫素" << endl << endl;

cout << "標定完成!!!" << endl;

cout << "開始評價標定結果………………";

double total_err = 0.0; // 所有影象的平均誤差的總和

double err = 0.0; // 每幅影象的平均誤差

double totalerr = 0.0;

double totalpoints = 0.0;

vectorimage_points_pro; // 儲存重新計算得到的投影點

for (int i = 0; i < image_count; i++)

fout << "重投影誤差2:" << sqrt(totalerr / totalpoints) << "畫素" << endl << endl;

fout << "重投影誤差3:" << total_err / image_count << "畫素" << endl << endl;

cout << "x = " << cameramatrix.at(0, 2) << endl;

cout << "y = " << cameramatrix.at(1, 2) << endl;

//儲存定標結果

// cout << "開始儲存定標結果………………" << endl;

// mat rotation_matrix = mat(3, 3, cv_32fc1, scalar::all(0)); /* 儲存每幅影象的旋轉矩陣 */

// fout << "相機內引數矩陣:" << endl;

fout << cameramatrix << endl << endl;

// fout << "畸變係數:\n";

// fout << distcoeffs << endl << endl << endl;

// for (int i = 0; i < image_count; i++)

// cout << "定標結果完成儲存!!!" << endl;

fout << endl;

}int main()

自製棋盤格標定板 單目相機標定

單目相機標定方法可以選用matlab,ros,opencv等。對於非專門標定人員,了解其基本原理就可是實踐了,不需深究細究其公式解法 至少還是要看的懂 畢竟這是一門工程活。本文分別使用 opencv 和 kalibr 對某款手機的相機進行標定。官方教程如下 create calibration pa...

記VS2017使用opencv4 0安裝開發過程

四個地方 乙個是vs專案屬性中c directory的標頭檔案部分加上 e work software opencv build include opencv2 乙個是vs專案屬性中c directory的依賴庫目錄部分加上 e work software opencv build x64 vc14...

OpenCV4 0開啟指定USB攝像頭問題

網上查了些資料,試圖通過usb攝像頭名稱獲取index,從而開啟指定攝像頭,如下 std vectorlist listdevices list for int i 0 i編譯通過後挺好使,誰知第二天重新開機,竟然開啟的是另外的usb攝像頭!追蹤半天沒發現異常,只能得出結論是listdevice得到...