【图像处理】基于matlab GUI自动报靶系统【含Matlab源码 814期】
作者:互联网
一、简介
基于matlab GUI自动报靶系统
二、源代码
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
三、运行结果
四、备注
完整代码或者代写添加QQ 1564658423
标签:shoot,GUI,global,system,handles,源码,matlab,varargin,gui 来源: https://www.cnblogs.com/homeofmatlab/p/14735097.html