|
楼主 |
发表于 2022-11-11 16:08:30
|
显示全部楼层
- function pos=getPosFromImg(I)
- I1=(I(:,:,2));
- I_gray=rgb2gray(I);
- [a,b] = size(I_gray);
- I_left=I(:,1:b/2);
- I_right=I(:,b/2+1:b);
- I1_left=I1(:,1:b/2);subplot(3,3,1);imshow(I1_left);title('绿色左图像');
- I1_right=I1(:,b/2+1:b);subplot(3,3,2);imshow(I1_right);title('绿色左图像');
- I_bw1=I1_left>160;subplot(3,3,3);imshow(I_bw1);title('左二值化图像');
- I_bw2=I1_right>160;subplot(3,3,4);imshow(I_bw2);title('右二值化图像');
- figure();
- %根据图像获取小球中心点坐标
- [row_center1,column_center1]=getCenterFromImg(I_bw1);
- [row_center2,column_center2]=getCenterFromImg(I_bw2);
- %根据坐标点求两个直线焦点获取结果
- p1=column_center1-636.5;
- f1=965;
- theta_10=-0.067;
- theta_1e=atan(p1/f1);
- theta_1=theta_10+theta_1e;
- u1=tan(theta_1);
- p2=column_center2-639.5;
- f2=973;
- theta_20=-0.067;
- theta_2e=atan(p2/f2);
- theta_2=theta_20+theta_2e;
- u2=tan(theta_2);
- xA=-26;
- xB=26;
- pos.y=(xB-xA)/(u1-u2);
- pos.x=u1*(xB-xA)/(u1-u2)+xA;
- l=[(pos.x+26)^2+pos.y^2]^0.5;
- p3=row_center1-480;
- theta_1n=atan(p3/f1);
- pos.z=l*tan(theta_1n);
复制代码 |
|