function varargout = shoot_system(varargin)
% SHOOT_SYSTEM M-file for shoot_system.fig
%军用报靶系统主函数
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);
% ---输出返回到命令行.
function varargout = shoot_system_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- 载入图像,这张靶图像没有弹点痕迹
function pushbutton1_Callback(hObject, eventdata, handles)
global before
global num
num=0;
B=imread('b1.jpg');
axes(handles.axes1);
imshow(B)
before=B;
% --- 在图像处理,去除噪声,圆心坐标与各个靶环间隔的检测.
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('处理完成!')
% --- 模拟打靶,方法是把有弹点图像叠加到源图像中
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
% --- 图像减影,把弹孔分割,滤除弹孔的噪声,弹孔的环值识别
function pushbutton4_Callback(hObject, eventdata, handles)
global after
global before
global x_center
global y_center
global lamda %靶环间的间隔距离
global num
%图像减影,及滤除弹孔的噪声
K=imabsdiff(after,before);
K2=im2bw(K,0.05);
K2=medfilt2(K2,[4,4]);
K2=medfilt1(double(K2),8);
%imshow(K2);
[L,n]=bwlabel(K2,8);
all_ba=zeros(1,num);
for j=1:n
[r1,c1]=find(L==j);
rc1=[r1 c1];
[x,y]=size(rc1);
%弹孔的坐标检测,环值识别
ba_zuobiao=zeros(1,2);
x_count=0;
y_count=0;
for i=1:x
x_count=x_count+rc1(i,1);
y_count=y_count+rc1(i,2);
end
ba_zuobiao(1)=x_count/x;
ba_zuobiao(2)=y_count/x;
distance=((x_center-ba_zuobiao(1))^2+(y_center-ba_zuobiao(2))^2)^(1/2);
ba=0;
for i=1:5
if(distance-i*lamda>0)
continue;
else
ba=10-i+1;
break;
end
end
all_ba(j)=ba;
end
result=num2str(all_ba);
set(handles.edit1,'string',result);
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% 关闭系统
function pushbutton6_Callback(hObject, eventdata, handles)
close(gcf);
- 1
- 2
- 3
前往页