Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
2022.10.12
Browse files Browse the repository at this point in the history
  • Loading branch information
losehu committed Oct 12, 2022
1 parent c7209fd commit 7d9cb49
Show file tree
Hide file tree
Showing 49 changed files with 883 additions and 5,305 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 8 additions & 8 deletions QT-Source/change-view/.qtc_clangd/compile_commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -2126,10 +2126,10 @@
"-ferror-limit=1000",
"-x",
"c++-header",
"C:\\Users\\RUPC\\Desktop\\github\\RUBO-IPM\\QT-Source\\change-view\\UI\\ui_udm.h"
"C:\\Users\\RUPC\\Desktop\\github\\RUBO-IPM\\QT-Source\\change-view\\UI\\ui_udipm.h"
],
"directory": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/.qtc_clangd",
"file": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/UI/ui_udm.h"
"file": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/UI/ui_udipm.h"
},
{
"arguments": [
Expand Down Expand Up @@ -2208,10 +2208,10 @@
"-ferror-limit=1000",
"-x",
"c++-header",
"C:\\Users\\RUPC\\Desktop\\github\\RUBO-IPM\\QT-Source\\change-view\\UI\\ui_ipm.h"
"C:\\Users\\RUPC\\Desktop\\github\\RUBO-IPM\\QT-Source\\change-view\\UI\\ui_menu.h"
],
"directory": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/.qtc_clangd",
"file": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/UI/ui_ipm.h"
"file": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/UI/ui_menu.h"
},
{
"arguments": [
Expand Down Expand Up @@ -2290,10 +2290,10 @@
"-ferror-limit=1000",
"-x",
"c++-header",
"C:\\Users\\RUPC\\Desktop\\github\\RUBO-IPM\\QT-Source\\change-view\\UI\\ui_menu.h"
"C:\\Users\\RUPC\\Desktop\\github\\RUBO-IPM\\QT-Source\\change-view\\UI\\ui_ipm.h"
],
"directory": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/.qtc_clangd",
"file": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/UI/ui_menu.h"
"file": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/UI/ui_ipm.h"
},
{
"arguments": [
Expand Down Expand Up @@ -2372,9 +2372,9 @@
"-ferror-limit=1000",
"-x",
"c++-header",
"C:\\Users\\RUPC\\Desktop\\github\\RUBO-IPM\\QT-Source\\change-view\\UI\\ui_udipm.h"
"C:\\Users\\RUPC\\Desktop\\github\\RUBO-IPM\\QT-Source\\change-view\\UI\\ui_udm.h"
],
"directory": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/.qtc_clangd",
"file": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/UI/ui_udipm.h"
"file": "C:/Users/RUPC/Desktop/github/RUBO-IPM/QT-Source/change-view/UI/ui_udm.h"
}
]
439 changes: 286 additions & 153 deletions QT-Source/change-view/Makefile.Debug

Large diffs are not rendered by default.

439 changes: 286 additions & 153 deletions QT-Source/change-view/Makefile.Release

Large diffs are not rendered by default.

113 changes: 82 additions & 31 deletions QT-Source/change-view/UDM/distorted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#include "distorted.h"
#include "QTimer"
#include "QFuture"
#include "udm.h"
string dir;
int conor_width ;
int conor_high ;

double distorted_parameter[11];


string pic0_name;


int get_distorted_mat(string pic_name[], string pic_name_ok[], int pic_num, int conor_width, int conor_high,
Expand All @@ -39,9 +41,9 @@ int get_distorted_mat(string pic_name[], string pic_name_ok[], int pic_num, int
/* 提取角点 */
if (0 == findChessboardCorners(imageInput, board_size, image_points_buf)) {
cout << filename << " 找不到角点\n"; //找不到角点
} else if (image_size.width != imageInput.cols) {
} else if (image_size.width != imageInput.cols||image_size.height != imageInput.rows) {
cout << "图片尺寸不同" << endl;
exit(0);
return -1;
} else {
Mat view_gray;
cvtColor(imageInput, view_gray, COLOR_RGB2GRAY);
Expand All @@ -56,13 +58,12 @@ int get_distorted_mat(string pic_name[], string pic_name_ok[], int pic_num, int

}
}
udm_pic.width=image_size.width;
udm_pic.high=image_size.height;

pic_num = ok_pic;
// pic_num = find_corner( pic_name, pic_name_ok, pic_num, image_size, board_size , image_points_buf, image_points_seq, conor_width, conor_high);
for(int i=0;i<ok_pic;i++)
pic_name[i]=pic_name_ok[i];
int total = image_points_seq.size();

pic0_name=pic_name[0];
pic_name[i]=pic_name_ok[i]; int total = image_points_seq.size();
cout << "total = " << total << endl;
cout << "角点提取完成!\n";
//以下是摄像机标定
Expand Down Expand Up @@ -97,30 +98,9 @@ pic0_name=pic_name[0];
}
/* 开始标定 */
calibrateCamera(object_points, image_points_seq, image_size, cameraMatrix, distCoeffs, rvecsMat, tvecsMat, 0);
cout << "标定完成!\n";
//对标定结果进行评价
cout << "开始评价标定结果………………\n";
double total_err = 0.0; /* 所有图像的平均误差的总和 */
double err = 0.0; /* 每幅图像的平均误差 */
vector<Point2f> image_points2; /* 保存重新计算得到的投影点 */
for (int i = 0; i < pic_num; i++) {
vector<Point3f> tempPointSet = object_points[i];
/* 通过得到的摄像机内外参数,对空间的三维点进行重新投影计算,得到新的投影点 */
projectPoints(tempPointSet, rvecsMat[i], tvecsMat[i], cameraMatrix, distCoeffs, image_points2);
/* 计算新的投影点和旧的投影点之间的误差*/
vector<Point2f> tempImagePoint = image_points_seq[i];
Mat tempImagePointMat = Mat(1, tempImagePoint.size(), CV_32FC2);
Mat image_points2Mat = Mat(1, image_points2.size(), CV_32FC2);
for (int j = 0; j < tempImagePoint.size(); j++) {
image_points2Mat.at<Vec2f>(0, j) = Vec2f(image_points2[j].x, image_points2[j].y);
tempImagePointMat.at<Vec2f>(0, j) = Vec2f(tempImagePoint[j].x, tempImagePoint[j].y);
}
err = norm(image_points2Mat, tempImagePointMat, NORM_L2);
total_err += err /= point_counts[i];
}
std::cout << "总体平均误差:" << total_err / pic_num << "像素" << endl;
std::cout << "评价完成!" << endl;
Mat rotation_matrix = Mat(3, 3, CV_32FC1, Scalar::all(0)); /* 保存每幅图像的旋转矩阵 */



cout << "相机内参数矩阵:" << endl;
cout << cameraMatrix << endl << endl;
cout << "畸变系数:\n";
Expand All @@ -138,6 +118,77 @@ pic0_name=pic_name[0];
parameter[8] = distCoeffs.at<double>(0, 4);
parameter[9] = distCoeffs.at<double>(0, 2);
parameter[10] = distCoeffs.at<double>(0, 3);
pic0_name=pic_name[0];



///**********自动计算结果图大小**********/
int ImgWidth = (int) distorted_parameter[0];
int ImgHeight = (int) distorted_parameter[1];
double fx = distorted_parameter[2]
, fy = distorted_parameter[3]
, ux = distorted_parameter[4]
, uy = distorted_parameter[5]
, k1 = distorted_parameter[6]
, k2 = distorted_parameter[7]
, k3 = distorted_parameter[8]
, p1 = distorted_parameter[9]
, p2 = distorted_parameter[10];
udm_pic.max_x = -9999999, udm_pic.max_y = -9999999, udm_pic.min_x = 9999999, udm_pic.min_y = 9999999;
for (int i = 0; i < ImgHeight; i++) {
for (int j = 0; j < ImgWidth; j++) {
double xDistortion = (j - ux) / fx;
double yDistortion = (i - uy) / fy;

double xCorrected, yCorrected;

double x0 = xDistortion;
double y0 = yDistortion;
for (int j = 0; j < 10; j++) {
double r2 = xDistortion * xDistortion + yDistortion * yDistortion;

double distRadialA = 1 / (1. + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2);
double distRadialB = 1.;

double deltaX = 2. * p1 * xDistortion * yDistortion + p2 * (r2 + 2. * xDistortion * xDistortion);
double deltaY = p1 * (r2 + 2. * yDistortion * yDistortion) + 2. * p2 * xDistortion * yDistortion;

xCorrected = (x0 - deltaX) * distRadialA * distRadialB;
yCorrected = (y0 - deltaY) * distRadialA * distRadialB;

xDistortion = xCorrected;
yDistortion = yCorrected;
}
xCorrected = xCorrected * fx + ux;
yCorrected = yCorrected * fy + uy;

if (i == 0 && j == 0) {

udm_pic.min_x = min_int(udm_pic.min_x, xCorrected);
udm_pic.min_y = min_int(udm_pic.min_y, yCorrected);//左上
}
if (i == 0 && j == ImgWidth - 1) {
//右上
udm_pic.min_y = min_int(udm_pic.min_y, yCorrected);
udm_pic.max_x = max_int(udm_pic.min_x, xCorrected);

}
if (i == ImgHeight - 1 && j == 0) {
//左下
udm_pic.min_x = min_int(udm_pic.min_x, xCorrected);
udm_pic.max_y = max_int(udm_pic.min_y, yCorrected);

}
if (i == ImgHeight - 1 && j == ImgWidth - 1) {
//右下
udm_pic.max_x = max_int(udm_pic.min_x, xCorrected);

udm_pic.max_y = max_int(udm_pic.min_y, yCorrected);
}
}
}


return ok_pic;


Expand Down
2 changes: 1 addition & 1 deletion QT-Source/change-view/UDM/distorted.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern string dir;
//cpp
extern double distorted_parameter[11];

// extern string pic0_name;
extern string pic0_name;



Expand Down
20 changes: 15 additions & 5 deletions QT-Source/change-view/UDM/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by RUBO on 2022/10/6.
//
#include "file.h"
bool path_check_ok=0;
int get_picname(string dir,string pic_name[])
{

Expand Down Expand Up @@ -62,18 +63,25 @@ vector<string> getFilesList(string dirpath) {
vector<string> getFilesList(string dir)
{
vector<string> allPath;

if(dir=="")
{
path_check_ok=0;
return allPath;
}
// 在目录后面加上"\\*.*"进行第一次搜索
string dir2 = dir + "\\*.*";

intptr_t handle;
_finddata_t findData;

handle = _findfirst(dir2.c_str(), &findData);
handle = _findfirst(dir2.c_str(), &findData);
if (handle == -1) {// 检查是否成功
cout << "can not found the file ... " << endl;
// cout << "can not found the file ... " << endl;
path_check_ok=0;
_findclose(handle); // 关闭搜索句柄
return allPath;
}
while (_findnext(handle, &findData) == 0)
}
while (_findnext(handle, &findData) == 0&&handle != -1)
{
if (findData.attrib & _A_SUBDIR) //是否含有子目录
{
Expand All @@ -92,6 +100,8 @@ vector<string> getFilesList(string dir)
}
}
_findclose(handle); // 关闭搜索句柄
path_check_ok=1;

return allPath;
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion QT-Source/change-view/UDM/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ using namespace cv;
using namespace std;
int get_picname(string dir,string pic_name[]);
vector<string> getFilesList(string dir);
#endif
extern bool path_check_ok;

#endif
Loading

0 comments on commit 7d9cb49

Please sign in to comment.