# UAV visual angle display (UAV image positioning) -- matlab code of a mathematical modeling problem a

slandarer 2021-10-14 05:02:38

I'm not free soon , Water is a simple ....
So far, only the first question has been written , Write again when you have time .....

### Problem description

Unmanned aircraft is abbreviated as “ Unmanned aerial vehicle (uav) ”, It is an unmanned aircraft operated by radio remote control equipment and self-contained program control device . UAV equipped with image equipment takes aerial photos at high altitude 、 Area patrol 、 It is widely used in military investigation .2018 year 9 month , The Harmonized System Committee of the World Customs Organization classifies UAVs as “ Flying camera ”.

It is an important technology to determine the position and attitude of UAV by using the captured images . A flat area can be approximately regarded as a horizontal plane , Now a certain type of UAV is used to patrol this area . Take the ground as 𝑥𝑜𝑦 Noodles , The vertical upward direction is 𝑧 The axis establishes a rectangular coordinate system according to the right-hand system . When the drone takes an image , Its central plane of symmetry 𝑆 Always keep upright , Recording plane 𝑆 be relative to 𝑥𝑜𝑧 The azimuth of the face is 𝜃（0 ≤ 𝜃 ≤ 360°）, namely 𝜃 = 0° when , The drone is facing 𝑥 Positive axis ;𝜃 = 90° when , The drone is facing 𝑦 Positive axis . The pan tilt of the UAV can adjust the shooting angle of the camera up and down , Note that the top view angle between the central axis of the lens and the horizontal plane is 𝜑（0 ≤ 𝜑 ≤ 90°）, namely 𝜑 = 0° when , Lens level ;𝜑 = 90° when , The lens is straight down . such , The position and shooting angle of the UAV can be five tuples (𝑥, 𝑦, 𝑧, 𝜃,𝜑) Characterization , Hereinafter referred to as the status of UAV .

To determine the status of the UAV , Set several marker points on its patrol area （ It can be regarded as a point light source ）, See Annex I for coordinate data . When the UAV is shooting in a certain state , The image of these marked points will appear in the picture . It is known that the camera lens of UAV is fixed focus , Its horizontal perspective 𝛼 = 60°, The pixels of the photos taken are 840*630.

1： When nothing people machine Of shape state branch other by (40,30,20,210°, 55°) and (−20,40,35,43°, 27°) when , Draw the shot （ Mark the point ） Photo . Separate shall be provided jpg file

In fact, if you want to write simply, you don't have to write so much trouble , The latter part is mainly for drawing a schematic diagram ：

``````function getViewUAV(coe)
% UAV parameter setting
UAV.Pos=coe(1:3);%[40,30,20];
UAV.Theta=coe(4);
UAV.Phi=coe(5);
UAV.Alpha=60;
UAV.Img_Row=630;
UAV.Img_Col=840;
% Data calculation
r=tan((90-UAV.Phi)/180*pi)*UAV.Pos(3);
R=UAV.Pos(3)/cos((90-UAV.Phi)/180*pi);
Lcol_=R*tan(UAV.Alpha/2/180*pi);
Lrow_=Lcol_/UAV.Img_Col*UAV.Img_Row;
% Target point coordinates
targetPos=[UAV.Pos(1)+r*cos(UAV.Theta/180*pi),...
UAV.Pos(2)+r*sin(UAV.Theta/180*pi),0];
targetV=targetPos-UAV.Pos;
% Central axis coordinates
midLPos=[targetPos(1)+Lcol_*cos(UAV.Theta/180*pi+pi/2),...
targetPos(2)+Lcol_*sin(UAV.Theta/180*pi+pi/2),0];
midRPos=[targetPos(1)+Lcol_*cos(UAV.Theta/180*pi-pi/2),...
targetPos(2)+Lcol_*sin(UAV.Theta/180*pi-pi/2),0];
midL_V=midLPos-UAV.Pos;
midR_V=midRPos-UAV.Pos;
norm_V=cross(midL_V,midR_V);
norm_V=norm_V./norm(norm_V).*sign(norm_V(3));
% Vertical plane frame
LUPos=midLPos+norm_V.*Lrow_;
RUPos=midRPos+norm_V.*Lrow_;
LDPos=midLPos-norm_V.*Lrow_;
RDPos=midRPos-norm_V.*Lrow_;
LU_V=LUPos-UAV.Pos;
RU_V=RUPos-UAV.Pos;
LD_V=LDPos-UAV.Pos;
RD_V=RDPos-UAV.Pos;
% Ground trapezoidal frame
LUPos0=UAV.Pos+LU_V./(UAV.Pos(3)-LUPos(3)).*UAV.Pos(3);
RUPos0=UAV.Pos+RU_V./(UAV.Pos(3)-RUPos(3)).*UAV.Pos(3);
LDPos0=UAV.Pos+LD_V./(UAV.Pos(3)-LDPos(3)).*UAV.Pos(3);
RDPos0=UAV.Pos+RD_V./(UAV.Pos(3)-RDPos(3)).*UAV.Pos(3);
% Find the point in the trapezoidal box
polygon_X=[LUPos0(1),RUPos0(1),RDPos0(1),LDPos0(1)];
polygon_Y=[LUPos0(2),RUPos0(2),RDPos0(2),LDPos0(2)];
[in,on]=inpolygon(dataPos(:,1),dataPos(:,2),polygon_X,polygon_Y);
inpolygonPos=dataPos(in|on,:);
% Find the intersection point between the connecting line between the ground trapezoidal frame and the UAV and the target plane
inpolygonVSet=inpolygonPos-UAV.Pos;
inpolygonLSet=sum(inpolygonVSet.*(targetV./norm(targetV)),2);
inpolygonRateSet=norm(targetV)./inpolygonLSet;
inboxPos=inpolygonVSet.*inpolygonRateSet+UAV.Pos;
% Mapping to 840*630 Square box
XYPos=inboxPos(:,1:2);
XYV=XYPos-UAV.Pos(1:2);
tTheta=((360-UAV.Theta)+90)/180*pi;
XYPos=[XYV(:,1).*cos(tTheta)-XYV(:,2).*sin(tTheta),...
XYV(:,2).*cos(tTheta)+XYV(:,1).*sin(tTheta)]+UAV.Pos(1:2);
LDV=LDPos(1:2)-UAV.Pos(1:2);
XYPos00=[LDV(1).*cos(tTheta)-LDV(2).*sin(tTheta),...
LDV(2).*cos(tTheta)+LDV(1).*sin(tTheta)]+UAV.Pos(1:2);
Lcol=2*Lcol_;
Lrow=2*Lrow_*cos((90-UAV.Phi)/180*pi);
XYPos=(XYPos-XYPos00)./[Lcol,Lrow].*[UAV.Img_Col,UAV.Img_Row];
% Draw a scatter plot
figure()
ax=gca;
hold(ax,'on')
ax.XLim=[0,UAV.Img_Col];
ax.YLim=[0,UAV.Img_Row];
ax.XTick=[];ax.XColor='none';
ax.YTick=[];ax.YColor='none';
outerpos=ax.OuterPosition;
ti=ax.TightInset;
left=outerpos(1) + ti(1);
bottom=outerpos(2) + ti(2);
ax_width=outerpos(3) - ti(1) - ti(3);
ax_height=outerpos(4) - ti(2) - ti(4);
ax.Position=[left bottom ax_width ax_height];
scatter(XYPos(:,1),XYPos(:,2),15,'filled','CData',[0 0 0])
saveas(ax,['c',num2str(coe),'.png'])
tImg=imresize(tImg,[UAV.Img_Row,UAV.Img_Col]);
imwrite(tImg,['c',num2str(coe),'.png']);
% Mapping diagram
figure()
ax=gca;
hold(ax,'on')
grid(ax,'on')
ax.DataAspectRatio =[1 1 1];
ax.DataAspectRatioMode='manual';
scatter3(UAV.Pos(1),UAV.Pos(2),UAV.Pos(3),30,'filled')
scatter3(targetPos(1),targetPos(2),targetPos(3),30,'filled')
scatter3(dataPos(:,1),dataPos(:,2),dataPos(:,3),3,'filled','CData',[0 0.251 0.451])
plot3([UAV.Pos(1),targetPos(1)],[UAV.Pos(2),targetPos(2)],[UAV.Pos(3),targetPos(3)],...
'LineWidth',2,'Color','k');
plot3([midLPos(1),midRPos(1)],[midLPos(2),midRPos(2)],[midLPos(3),midRPos(3)],...
'LineWidth',2,'Color',[0.8,0.2,0.2]);
fill3([LUPos(1),RUPos(1),RDPos(1),LDPos(1)],...
[LUPos(2),RUPos(2),RDPos(2),LDPos(2)],...
[LUPos(3),RUPos(3),RDPos(3),LDPos(3)],[0.3,0.3,0.3],'FaceAlpha',0.3)
fill3([LUPos0(1),RUPos0(1),RDPos0(1),LDPos0(1)],...
[LUPos0(2),RUPos0(2),RDPos0(2),LDPos0(2)],...
[LUPos0(3),RUPos0(3),RDPos0(3),LDPos0(3)],[0.3,0.3,0.6],'FaceAlpha',0.2)
plot3([LUPos0(1),UAV.Pos(1)],[LUPos0(2),UAV.Pos(2)],[LUPos0(3),UAV.Pos(3)],'Color',[0.3,0.3,0.6])
plot3([RUPos0(1),UAV.Pos(1)],[RUPos0(2),UAV.Pos(2)],[RUPos0(3),UAV.Pos(3)],'Color',[0.3,0.3,0.6])
plot3([LDPos(1),UAV.Pos(1)],[LDPos(2),UAV.Pos(2)],[LDPos(3),UAV.Pos(3)],'Color',[0.3,0.3,0.6])
plot3([RDPos(1),UAV.Pos(1)],[RDPos(2),UAV.Pos(2)],[RDPos(3),UAV.Pos(3)],'Color',[0.3,0.3,0.6])
end
``````

xls file ：
Extraction code ： pntp

### Usage mode

Command line or new m The file runs the following code ：

``````getViewUAV([40,30,20,210,55])
getViewUAV([-20,40,35,43,27])
``````

### Use effect

The secret fear goes deep

[40,30,20,210,55]
The shooting effect ：

Schematic diagram of UAV ：

It hits the corner
[-20,40,35,43,27]
The shooting effect ：

Schematic diagram of UAV ：

### Postscript

Because I've been really busy lately , I didn't do much after asking , But I think I can try to estimate the density of the midpoint of the figure first , After homogenizing the image density distribution, the point set is registered , Or after estimating the density, set the angle range of the UAV according to the density, and then continuously change various parameters, such as cyclic hard search .... If someone sees it, they can consider writing it when they are free hiahiahia