1, Introduction of shooting simulation system
1 subject description
2 subject modeling process
a) First, obtain the parameters of the weapon, and calculate the response common deviation of the weapon in direction and height from these parameters;
b) Second, the deviation of direction and height in the shooting process is normally distributed. In matlab, normrnd function is used to realize the modification function (where the standard deviation is the common calculation error);
c) Third, according to the calculated value, make the attack midpoint on the target: the radius of the 10 rings of the target is 0.75m, the radius of the 9 rings is 1.75m, and so on, the radius of the 6 rings is 4.75m, and all the outside of the 6 rings are recorded as 0 rings, so as to output the results of each shooting;
d) Fourth, calculate the total number of rings, average number of rings and hit rate. The hit rate is more than 6 rings, accounting for the proportion of 10 guns.
3, Key difficulties in the implementation of the subject
a) It's hard to start at the beginning
Because I didn't listen carefully in class, to tell the truth, I couldn't start with the program at the beginning, and I didn't know how to make progress at all.
In this case, I bought a reference book and tested the only example in the reference book. Although it is completely copied, it also encountered a lot of trouble in the process. The tag s of several objects in the book are inconsistent, which makes the program unable to run. After reading the book and pondering it carefully, I modified the program and ran it successfully. In this process, I began to understand the program.
After reading the GUI chapter, I basically began to have a clue, and then I began to select the topic, design the interface and analyze the function.
When choosing the course question, I also tangled. Finally, I chose a 4-star topic. It is really because of the problem of time arrangement, because I have to take double degree classes on weekends. I am not willing to skip any classes.
b) Procedural problems
Because the topic selection is still quite simple, the program has been very smooth. I reviewed the graphics in the book when making graphics, and reviewed some characteristics of matlab program when writing callback functions. Because I have learned c language, I feel that in addition to matlab, there are some special uses, such as script files, function files, and several process control statements, which are very similar. The program will start soon.
Some of the functions you want to realize, such as hiding the coordinate axis and pop-up dialog box, are searched on the Internet. After experiments, they are finally written into the program.
c) Add sound
This is a big trouble I encountered. When I added it, I thought I was very creative. Later, I found that some students added that function, but I did encounter a lot of trouble in this process.
When I first had this idea, I searched the Internet for whether I could add background music and found that I could use the wavread function. Then I found a gunshot of ak47 on the Internet. Unexpectedly, this gunshot bothered me for a long time.
Of course, I know I can only add wav format audio file, download this gunshot is also wav format, but I can't add it anyway. When debugging, you enter the wavread function and find the place where the error message jumps out, but you can't understand it. After copying and pasting that paragraph, I found a problem on Baidu, which is about it. There are some mentioned in it wav format is not a standard format and may not be input into matlab. I searched wav content, confirmed the idea, downloaded the format conversion software, and turned the audio n times, but it still didn't work.
Finally, it's also a coincidence that when I look at the web page, I find that the recorder brought by windows can produce standards wav format, which has become my last hope. If this doesn't work anymore, I think I'll give up loading sound. Of course, it succeeded in the end.
2, Partial source code
function varargout = shoot_system(varargin) % SHOOT_SYSTEM M-file for shoot_system.fig %Main function of military target reporting system gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @shoot_system_OpeningFcn, ... 'gui_OutputFcn', @shoot_system_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end function shoot_system_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); % ---Output returns to the command line. function varargout = shoot_system_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; % --- Load the image. This target image has no bullet marks function pushbutton1_Callback(hObject, eventdata, handles) global before global num num=0; B=imread('b1.jpg'); axes(handles.axes1); imshow(B) before=B; % --- In image processing, noise is removed, and the center coordinates and the interval between each target ring are detected. function pushbutton2_Callback(hObject, eventdata, handles) global before global rc global x_center global y_center global lamda J=double(im2bw(before,0.5)); J=medfilt1(J,4); B=[0 1 0;1 1 1;1 0 1]; A=imdilate(J,B); [x,y]=size(A); [L,m] = bwlabel(A,8); zuobiao=zeros(m,2); n=1; for i=1:m [r,c] = find(L==i); rc=[r c]; a1=max(r); a2=min(r); a=a1-a2;% r1=a/2; test1=(a1+a2)/2; b1=max(c); b2=min(c); b=b1-b2;% r2=b/2; test2=(b1+b2)/2; deta=abs(b-a);% if(deta/((a+b)/2)<1/100 && (a1-a2)/x<0.8) zuobiao(n,1)=test1; zuobiao(n,2)=test2; banjing(n,1)=r1; banjing(n,2)=r2; n=n+1; end end n=n-1; x_count=0; y_count=0; for j=1:n x_count=x_count+zuobiao(j,1); y_count=y_count+zuobiao(j,2); end x_center=x_count/n; y_center=y_count/n; banjing_1=zeros(1,n); for i=1:n banjing_1(i)=(banjing(i,1)+banjing(i,2))/2; end banjing_2=sort(banjing_1); count=0; for i=1:(n-1) count=count+abs(banjing_2(i)-banjing_2(i+1)); end lamda=count/(n-1); msgbox('Processing complete!') % --- Simulation shooting, the method is to superimpose the bullet point image on the source image function pushbutton3_Callback(hObject, eventdata, handles) global num global after num=num+1; NUM=7; for i=1:NUM switch num case{1} after=imread('b2.jpg'); axes(handles.axes1); imshow(after); break case{2} after=imread('b3.jpg'); axes(handles.axes1); imshow(after); break case{3} after=imread('b4.jpg'); axes(handles.axes1); imshow(after); break case{4} after=imread('b5.jpg'); axes(handles.axes1); imshow(after); break case{5} after=imread('b6.jpg'); axes(handles.axes1); imshow(after); break case{6} after=imread('b7.jpg'); axes(handles.axes1); imshow(after); break case{7} after=imread('b8.jpg'); axes(handles.axes1); imshow(after); end end
3, Operation results
4, matlab version and references
1 matlab version
2014a
2 references
[1] Cai Limei MATLAB image processing -- theory, algorithm and example analysis [M] Tsinghua University Press, 2020
[2] Yang Dan, Zhao Haibin, long Zhe Detailed explanation of MATLAB image processing example [M] Tsinghua University Press, 2013
[3] Zhou pin MATLAB image processing and graphical user interface design [M] Tsinghua University Press, 2013
[4] Liu Chenglong Proficient in MATLAB image processing [M] Tsinghua University Press, 2015
[5] Chen Hao, Fang Yong, Zhu Dazhou, Wang Cheng, Chen Zilong Edge detection of corn plant thermal infrared image based on ant colony algorithm [J] Research on agricultural mechanization 2015,37(06)