function varargout = MainForm(varargin)
% MAINFORM MATLAB code for MainForm.fig
% MAINFORM, by itself, creates a new MAINFORM or raises the existing
% singleton*.
%
% H = MAINFORM returns the handle to a new MAINFORM or the handle to
% the existing singleton*.
%
% MAINFORM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAINFORM.M with the given input arguments.
%
% MAINFORM('Property','Value',...) creates a new MAINFORM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MainForm_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MainForm_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help MainForm
% Last Modified by GUIDE v2.5 28-Jun-2013 10:42:40
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MainForm_OpeningFcn, ...
'gui_OutputFcn', @MainForm_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
% End initialization code - DO NOT EDIT
% --- Executes just before MainForm is made visible.
function MainForm_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to MainForm (see VARARGIN)
% Choose default command line output for MainForm
handles.output = hObject;
clc;
set(handles.axes1, 'Box', 'on', 'Color', 'c', 'XTickLabel', '', 'YTickLabel', '');
set(handles.axes2, 'Box', 'on', 'Color', 'c', 'XTickLabel', '', 'YTickLabel', '');
set(handles.text4, 'String', '');
handles.fileurl = 0;
handles.Img = 0;
handles.Imgbw = 0;
handles.Ti = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MainForm wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = MainForm_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function varargout = pushbutton1_CreateFcn(hObject, eventdata, handles)
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 载入图像
file = fullfile(pwd, 'test/下载.jpg');
[Filename, Pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
'*.*','All Files' }, '载入验证码图像',...
file);
if isequal(Filename, 0) || isequal(Pathname, 0)
return;
end
% 显示图像
axes(handles.axes1); cla reset;
axes(handles.axes2); cla reset;
set(handles.axes1, 'Box', 'on', 'Color', 'c', 'XTickLabel', '', 'YTickLabel', '');
set(handles.axes2, 'Box', 'on', 'Color', 'c', 'XTickLabel', '', 'YTickLabel', '');
set(handles.text4, 'String', '');
% 存储
fileurl = fullfile(Pathname,Filename);
Img = imread(fileurl);
imshow(Img, [], 'Parent', handles.axes1);
set(handles.text2, 'String', '验证码图像');
handles.fileurl = fileurl;
handles.Img = Img;
guidata(hObject, handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isequal(handles.Img, 0)
return;
end
Img = handles.Img;
% 颜色空间转换
hsv = rgb2hsv(Img);
h = hsv(:, :, 1);
s = hsv(:, :, 2);
v = hsv(:, :, 3);
% 定位噪音点
bw1 = h > 0.16 & h < 0.30;
bw2 = s > 0.65 & s < 0.80;
bw = bw1 & bw2;
% 过滤噪音点
Imgr = Img(:, :, 1);
Imgg = Img(:, :, 2);
Imgb = Img(:, :, 3);
Imgr(bw) = 255;
Imgg(bw) = 255;
Imgb(bw) = 255;
% 去噪结果
Imgbw = cat(3, Imgr, Imgg, Imgb);
imshow(Imgbw, [], 'Parent', handles.axes2);
set(handles.text3, 'String', '验证码图像去噪');
handles.Imgbw = Imgbw;
guidata(hObject, handles);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isequal(handles.Imgbw, 0)
return;
end
Imgbw = handles.Imgbw;
% 灰度化
Ig = rgb2gray(Imgbw);
% 二值化
Ibw = im2bw(Ig, 0.8);
% 常量参数
sz = size(Ibw);
cs = sum(Ibw, 1);
mincs = min(cs);
maxcs = max(cs);
masksize = 16;
% 初始化
S1 = []; E1 = [];
% 1对应开始,2对应结束
flag = 1;
s1 = 1;
tol = maxcs;
while s1 < sz(2)
for i = s1 : sz(2)
% 移动游标
s2 = i;
if cs(s2) < tol && flag == 1
% 达到起始位置
flag = 2;
S1 = [S1 s2-1];
break;
elseif cs(s2) >= tol && flag == 2
% 达到结束位置
flag = 1;
E1 = [E1 s2];
break;
end
end
s1 = s2 + 1;
end
% 图像反色
Ibw = ~Ibw;
% 图像细化
Ibw = bwmorph(Ibw, 'thin', inf);
for i = 1 : length(S1)
% 图像裁剪
Ibwi = Ibw(:, S1(i):E1(i));
% 面积滤波
[L, num] = bwlabel(Ibwi);
stats = regionprops(L);
Ar = cat(1, stats.Area);
[maxAr, ind_maxAr] = max(Ar);
recti = stats(ind_maxAr).BoundingBox;
recti(1) = recti(1) + S1(i) - 1;
recti(2) = recti(2);
recti(3) = recti(3);
recti(4) = recti(4);
Rect{i} = recti;
% 图像裁剪
Ibwi = imcrop(Ibw, recti);
rate = masksize/max(size(Ibwi));
Ibwi = imresize(Ibwi, rate, 'bilinear');
ti = zeros(masksize, masksize);
rsti = round((size(ti, 1)-size(Ibwi, 1))/2);
csti = round((size(ti, 2)-size(Ibwi, 2))/2);
ti(rsti+1:rsti+size(Ibwi,1), csti+1:csti+size(Ibwi,2))=Ibwi;
% 存储
Ti{i} = ti;
end
imshow(Ibw, [], 'Parent', handles.axes2); hold on;
for i = 1 : length(Rect)
rectangle('Position', Rect{i}, 'EdgeColor', 'r', 'LineWidth', 2);
end
hold off;
set(handles.text3, 'String', '验证码数字定位');
handles.Ti = Ti;
guidata(hObject, handles);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isequal(handles.Ti, 0)
return;
end
% 加入红色边框
Ti = handles.Ti;
It = [];
spcr = ones(size(Ti{1}, 1), 3)*255;
spcg = ones(size(Ti{1}, 1), 3)*0;
spcb = ones(size(Ti{1}, 1), 3)*0;
spc = cat(3, spcr, spcg, spcb);
% 整合到一起
It = [It spc];
for i = 1 : length(Ti)
ti = Ti{i};
ti = cat(3, ti, ti, ti);
ti = im2uint8(mat2gray(ti));
It = [It ti spc];
end
imshow(It, [], 'Parent', handles.axes2); hold on;
set(handles.text3, 'String', '验证码归一化');
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and
没有合适的资源?快使用搜索试试~ 我知道了~
《Matlab计算机视觉与深度学习实战》代码 基于不变矩的数字验证码识别.zip
共372个文件
jpg:367个
m:4个
fig:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 51 浏览量
2023-07-15
16:31:40
上传
评论
收藏 288KB ZIP 举报
温馨提示
《Matlab计算机视觉与深度学习实战》代码
资源推荐
资源详情
资源评论
收起资源包目录
《Matlab计算机视觉与深度学习实战》代码 基于不变矩的数字验证码识别.zip (372个子文件)
MainForm.fig 10KB
5939.jpg 1KB
8598.jpg 1KB
8306.jpg 1KB
9530.jpg 1KB
9962.jpg 1KB
9586.jpg 1KB
5939_1.jpg 1KB
3439.jpg 1KB
2243.jpg 1KB
2806.jpg 1KB
8622.jpg 1KB
9333.jpg 1KB
6373.jpg 1KB
下载.jpg 1KB
4073.jpg 1KB
1635_2.jpg 1KB
1635_1.jpg 1KB
1802.jpg 1KB
2243_1.jpg 1KB
7022.jpg 1KB
3521.jpg 1KB
7273.jpg 1KB
1327.jpg 1KB
2243_2.jpg 1KB
1635.jpg 1KB
1169.jpg 1KB
1178.jpg 1005B
1513.jpg 982B
0_6_3.jpg 488B
0_7_3.jpg 488B
0_10_3.jpg 488B
0_11_3.jpg 488B
0_9_3.jpg 488B
0_5_3.jpg 488B
6_1_3.jpg 488B
9_12_2.jpg 487B
9_16_2.jpg 487B
6_16_2.jpg 487B
6_22_2.jpg 487B
6_16_3.jpg 487B
6_18_2.jpg 487B
6_21_2.jpg 487B
6_15_2.jpg 487B
6_5_2.jpg 487B
6_6_2.jpg 487B
6_20_2.jpg 487B
6_17_2.jpg 487B
8_9_2.jpg 486B
8_17_1.jpg 486B
8_21_1.jpg 486B
8_10_2.jpg 486B
8_11_2.jpg 486B
6_10_4.jpg 486B
6_20_4.jpg 486B
6_19_3.jpg 486B
6_18_3.jpg 486B
6_16_4.jpg 486B
6_21_3.jpg 486B
6_23_3.jpg 486B
6_11_4.jpg 486B
6_17_3.jpg 486B
6_9_4.jpg 486B
6_24_3.jpg 486B
5_15_1.jpg 486B
6_25_3.jpg 486B
5_7_2.jpg 486B
6_14_4.jpg 486B
5_20_2.jpg 486B
6_19_4.jpg 486B
5_9_1.jpg 486B
6_7_4.jpg 486B
6_18_4.jpg 486B
6_20_3.jpg 486B
6_15_4.jpg 486B
5_8_2.jpg 486B
5_13_1.jpg 486B
5_19_2.jpg 486B
5_11_2.jpg 486B
5_10_1.jpg 486B
5_17_2.jpg 486B
5_11_1.jpg 486B
5_21_2.jpg 486B
5_9_2.jpg 486B
5_12_2.jpg 486B
5_14_1.jpg 486B
5_13_2.jpg 486B
8_19_1.jpg 485B
8_6_2.jpg 485B
8_14_1.jpg 485B
0_13_3.jpg 485B
8_15_1.jpg 485B
8_18_1.jpg 485B
8_7_2.jpg 485B
9_8_2.jpg 485B
8_16_1.jpg 485B
8_5_2.jpg 485B
9_14_4.jpg 485B
9_20_1.jpg 485B
9_15_4.jpg 485B
共 372 条
- 1
- 2
- 3
- 4
资源评论
AbelZ_01
- 粉丝: 894
- 资源: 5441
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 海尔618算价表_七海5.20_16.00xlsx(1)(2).xlsx
- WebCrawler.scr
- 【计算机专业毕业设计】大学生就业信息管理系统设计源码.zip
- YOLO 数据集:8种路面缺陷病害检测【包含划分好的数据集、类别class文件、数据可视化脚本】
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于YOLOv8的FPS TPS AI自动锁定源码+使用步骤说明.zip
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于yolov8+streamlit的火灾检测部署源码+模型.zip
- 测试aaaaaaabbbbb
- VID20240521070643.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功