目录
一、研究背景与意义
二、课题内容
(一)双目视觉标定
1.原理
2. 流程
(二)双目视觉测量
1. 对第“4”对图分析
2. 对第“5”对图分析
3. 对第“6”对图分析
4. 将数据综合列表画图
(三)位移测量(0-20mm 11 对图)
1.确定拟合平面
参考文献
一、研究背景与意义
二、课题内容
(一)双目视觉标定
1.原理
2. 流程
(二)双目视觉测量
1. 对第“4”对图分析
% 载入相机参数
load('D:\6.19opencv\stereoParams.mat');
CameraParameters1=stereoParams.CameraParameters1;
%load('D:\6.19opencv\cameraParams2.mat');
CameraParameters2=stereoParams.CameraParameters2;
rotationOfCamera
=
[0.961946016750214,0.00813927148687200,-0.273118313406590;-0.005604972092
34865,0.999933707257798,0.0100581000949768;0.273182073251963,-0.008144528
79788458,0.961927867100449];
translationOfCamera = [-276.724447941251
1.02241233804647
45.6465912222537];
stereoParams
=stereoParameters(CameraParameters1,
CameraParameters2,
rotationOfCamera,translationOfCamera);
% 读取图像
I1 = imread(fullfile('D:\6.19opencv\双目边长测量\camera1','4.jpg'));
I2 = imread(fullfile('D:\6.19opencv\双目边长测量\camera2','4.jpg'));
% 消除畸变
I1 = undistortImage(I1, stereoParams.CameraParameters1);
I2 = undistortImage(I2, stereoParams.CameraParameters2);
% 检测棋盘格角点
[imagePoints1, boardSize1] = detectCheckerboardPoints(I1);
[imagePoints2, boardSize2] = detectCheckerboardPoints(I2);
% 获取三维点
for i = 1:88
center1i = imagePoints1(i,:);
center1(i,1) = center1i(:,1);
center1(i,2) = center1i(:,2);
end
for j = 1:88
center2j = imagePoints2(j,:);
center2(j,1) = center2j(:,1);
center2(j,2) = center2j(:,2);
end
for k = 1:88
point3dk = triangulate(center1(k,:), center2(k,:), stereoParams);point3d(k,1) = point3dk(:,1);
point3d(k,2) = point3dk(:,2);
point3d(k,3) = point3dk(:,3);
end
X = point3d(:,1);
Y = point3d(:,2);
Z = point3d(:,3);
2. 对第“5”对图分析
% 载入相机参数
load('D:\6.19opencv\stereoParams.mat');
CameraParameters1=stereoParams.CameraParameters1;
%load('D:\6.19opencv\cameraParams2.mat');
CameraParameters2=stereoParams.CameraParameters2;
rotationOfCamera
=
[0.961946016750214,0.00813927148687200,-0.273118313406590;-0.005604972092
34865,0.999933707257798,0.0100581000949768;0.273182073251963,-0.008144528
79788458,0.961927867100449];
translationOfCamera = [-276.724447941251
1.02241233804647
45.6465912222537];
stereoParams
=stereoParameters(CameraParameters1,
CameraParameters2,
rotationOfCamera,translationOfCamera);
% 读取图像
I1 = imread(fullfile('D:\6.19opencv\双目边长测量\camera1','5.jpg'));
I2 = imread(fullfile('D:\6.19opencv\双目边长测量\camera2','5.jpg'));
% 消除畸变
I1 = undistortImage(I1, stereoParams.CameraParameters1);
I2 = undistortImage(I2, stereoParams.CameraParameters2);
% 检测棋盘格角点
[imagePoints1, boardSize1] = detectCheckerboardPoints(I1);
[imagePoints2, boardSize2] = detectCheckerboardPoints(I2);
% 获取三维点
for i = 1:88
center1i = imagePoints1(i,:);
center1(i,1) = center1i(:,1);
center1(i,2) = center1i(:,2);
end
for j = 1:88
center2j = imagePoints2(j,:);
center2(j,1) = center2j(:,1);
center2(j,2) = center2j(:,2);
end
for k = 1:88
point3dk = triangulate(center1(k,:), center2(k,:), stereoParams);
point3d(k,1) = point3dk(:,1);
point3d(k,2) = point3dk(:,2);point3d(k,3) = point3dk(:,3);
end
X = point3d(:,1);
Y = point3d(:,2);
Z = point3d(:,3);
3. 对第“6”对图分析
% 载入相机参数
load('D:\6.19opencv\stereoParams.mat');
CameraParameters1=stereoParams.CameraParameters1;
%load('D:\6.19opencv\cameraParams2.mat');
CameraParameters2=stereoParams.CameraParameters2;
rotationOfCamera
=
[0.961946016750214,0.00813927148687200,-0.273118313406590;-0.005604972092
34865,0.999933707257798,0.0100581000949768;0.273182073251963,-0.008144528
79788458,0.961927867100449];
translationOfCamera = [-276.724447941251
1.02241233804647
45.6465912222537];
stereoParams
=stereoParameters(CameraParameters1,
CameraParameters2,
rotationOfCamera,translationOfCamera);
% 读取图像
I1 = imread(fullfile('D:\6.19opencv\双目边长测量\camera1','6.jpg'));
I2 = imread(fullfile('D:\6.19opencv\双目边长测量\camera2','6.jpg'));
% 消除畸变
I1 = undistortImage(I1, stereoParams.CameraParameters1);
I2 = undistortImage(I2, stereoParams.CameraParameters2);
% 检测棋盘格角点
[imagePoints1, boardSize1] = detectCheckerboardPoints(I1);
[imagePoints2, boardSize2] = detectCheckerboardPoints(I2);
% 获取三维点
for i = 1:88
center1i = imagePoints1(i,:);
center1(i,1) = center1i(:,1);
center1(i,2) = center1i(:,2);
end
for j = 1:88
center2j = imagePoints2(j,:);
center2(j,1) = center2j(:,1);
center2(j,2) = center2j(:,2);
end
for k = 1:88
point3dk = triangulate(center1(k,:), center2(k,:), stereoParams);
point3d(k,1) = point3dk(:,1);
point3d(k,2) = point3dk(:,2);point3d(k,3) = point3dk(:,3);
end
X = point3d(:,1);
Y = point3d(:,2);
Z = point3d(:,3);
4. 将数据综合列表画图
(三)位移测量(0-20mm 11 对图)
1.确定拟合平面
①首先将距离为 0 的一对图导入运行
% 载入相机参数
load('D:\6.19opencv\stereoParams.mat');
CameraParameters1=stereoParams.CameraParameters1;
%load('D:\6.19opencv\cameraParams2.mat');
CameraParameters2=stereoParams.CameraParameters2;
rotationOfCamera=[0.961946016750214,0.00813927148687200,-0.27311831340659
0;-0.00560497209234865,0.999933707257798,0.0100581000949768;0.27318207325
1963,-0.00814452879788458,0.961927867100449];
translationOfCamera = [-276.724447941251
1.02241233804647
45.6465912222537];
stereoParams
=stereoParameters(CameraParameters1,
CameraParameters2,
rotationOfCamera,translationOfCamera);
% 读取图像
I1 = imread(fullfile('D:\6.19opencv\位移测量\camera1','0.jpg'));
I2 = imread(fullfile('D:\6.19opencv\位移测量\camera2','0.jpg'));
% 消除畸变
I1 = undistortImage(I1, stereoParams.CameraParameters1);
I2 = undistortImage(I2, stereoParams.CameraParameters2);
% 检测棋盘格角点
[imagePoints1, boardSize1] = detectCheckerboardPoints(I1);
[imagePoints2, boardSize2] = detectCheckerboardPoints(I2);% 获取三维点
for i = 1:88
center1i = imagePoints1(i,:);
center1(i,1) = center1i(:,1);
center1(i,2) = center1i(:,2);
end
for j = 1:88
center2j = imagePoints2(j,:);
center2(j,1) = center2j(:,1);
center2(j,2) = center2j(:,2);
end
for k = 1:88
point3dk = triangulate(center1(k,:), center2(k,:), stereoParams);
point3d(k,1) = point3dk(:,1);
point3d(k,2) = point3dk(:,2);
point3d(k,3) = point3dk(:,3);
end
X = point3d(:,1);
Y = point3d(:,2);
Z = point3d(:,3);
基于点到平面距离公式,计算每个点的距离
function zg_save_distances_to_excel()
% 拟合的平面方程系数
a = 0.213273;
b = 0.050976;
c = -1.000000;
d = 1065.197747;
% 从 Excel 文件读取数据
q = xlsread('D:\6.19opencv\位移测量\2.xlsx', 'sheet1');
% 计算每个点相对于拟合平面的有符号距离
distances = (a * q(:, 1) + b * q(:, 2) + c * q(:, 3) + d) / sqrt(a^2 + b^2 + c^2);
% 创建包含点索引和距离的表格
data = [(1:88)', distances];
% 将数据写入 Excel 文件
xlswrite('D:\6.19opencv\位移测量\distances2.xlsx', data, 'sheet1');
fprintf('距离数据已保存到 distances2.xlsx 文件中。\n');
End
文章来源:https://www.toymoban.com/news/detail-758289.html
文章来源地址https://www.toymoban.com/news/detail-758289.html
参考文献
到了这里,关于双目视觉标定与 3D 坐标测量的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!