当前位置:网站首页>[Chapter 10: a website digital verification code recognition based on moment invariants matlab deep learning practical application case]
[Chapter 10: a website digital verification code recognition based on moment invariants matlab deep learning practical application case]
2022-06-22 01:49:00 【Haibao 7】
【 The first 10 Chapter Digital verification code recognition based on moment invariants MATLAB In depth study of practical application cases 】
GUI The interface effect is shown in the figure 




Subfunction
invmoments.m file
function res = invmoments(x)
x = double(x);
[M,N,~] = size(x);
[X,Y] = meshgrid(1:M, 1:N);
X = X(:);
Y = Y(:);
x = x(:);
m.m00 = sum(x);
m.m10 = sum(X.*x);
m.m01 = sum(Y.*x);
m.m11 = sum(X.*Y.*x);
m.m20 = sum(X.^2.*x);
m.m02 = sum(Y.^2.*x);
m.m30 = sum(X.^3.*x);
m.m03 = sum(Y.^3.*x);
m.m12 = sum(X.*Y.^2.*x);
m.m21 = sum(X.^2.*Y.*x);
xbar = m.m10/m.m00;
ybar = m.m01/m.m00;
e.hp11 = (m.m11 - ybar*m.m10) / m.m00^2;
e.hp20 = (m.m20 - xbar*m.m10) / m.m00^2;
e.hp02 = (m.m02 - ybar*m.m01) / m.m00^2;
e.hp30 = (m.m30 - 3*xbar*m.m20 + 2*xbar^2*m.m10) / m.m00^2.5;
e.hp03 = (m.m03 - 3*ybar*m.m02 + 2*ybar^2*m.m01) / m.m00^2.5;
e.hp21 = (m.m21 - 2*xbar*m.m11 -ybar*m.m20 + 2*xbar^2*m.m01) / m.m00^2.5;
e.hp12 = (m.m12 - 2*ybar*m.m11 -xbar*m.m02 + 2*ybar^2*m.m10) / m.m00^2.5;
res(1) = e.hp20 + e.hp02;
res(2) = (e.hp20 - e.hp02)^2 + 4*e.hp11^2;
res(3) = (e.hp30 - 3*e.hp12)^2 + (3*e.hp21 - e.hp03)^2;
res(4) = (e.hp30 + e.hp12)^2 + (e.hp21 + e.hp03)^2;
res(5) = (e.hp30 - 3*e.hp12)*(e.hp30 + e.hp12)*...
((e.hp30 + e.hp12)^2 - 3*(e.hp21 + e.hp03)^2)+...
(3*e.hp21 - e.hp03)*(e.hp21 + e.hp03)*...
(3*(e.hp30 + e.hp12)^2 - (e.hp21 + e.hp03)^2);
res(6) = (e.hp20 - e.hp02) * ((e.hp30 + e.hp12)^2-...
(e.hp21 + e.hp03)^2)+...
4*e.hp11*(e.hp30 + e.hp12)*(e.hp21 + e.hp03);
res(7) = (3*e.hp21 - e.hp03) * (e.hp30 + e.hp12) * ...
( (e.hp30 + e.hp12)^2 - 3*(e.hp21 + e.hp03)^2) +...
(3*e.hp12 - e.hp30)*(e.hp21 + e.hp03)*...
(3*(e.hp30 + e.hp12)^2 - (e.hp21 + e.hp03)^2);
Subfunctions GetAllFiles.m
function fileList = GetAllFiles(dirName)
dirData = dir(dirName);
dirIndex = [dirData.isdir];
fileList = {
dirData(~dirIndex).name}';
if ~isempty(fileList)
fileList = cellfun(@(x) fullfile(dirName,x),...
fileList,'UniformOutput',false);
end
subDirs = {
dirData(dirIndex).name};
validIndex = ~ismember(subDirs,{
'.','..'});
for iDir = find(validIndex)
nextDir = fullfile(dirName,subDirs{
iDir});
fileList = [fileList; GetAllFiles(nextDir)];
end
end
function
GetDatabase
function GetDatabase()
files = dir(fullfile(pwd, 'images/*.jpg'));
for i = 0 : 9
foldername = fullfile(pwd, sprintf('Databse/%d', i));
if ~exist(foldername, 'dir')
mkdir(foldername);
end
end
h = waitbar(0,' Dealing with , Please wait ...', 'Name', ' Generate template library ');
steps = length(files);
for fi = 1 : length(files)
filename = fullfile(pwd, sprintf('images/%s', files(fi).name));
[pathstr, name, ext] = fileparts(filename);
name = name(1:4);
Img = imread(filename);
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);
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 = [];
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);
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
for i = 1 : length(Ti)
namei = name(i);
outfilenamei = fullfile(pwd, sprintf('Databse/%s/%s_%d_%d.jpg', namei, namei, fi, i));
imwrite(Ti{
i}, outfilenamei);
end
fprintf('\n Disposed of %d------%d\n', fi, length(files));
h = waitbar(fi / steps);
end
close(h) ;
database 
Case image 



High accuracy 
Download the full source code of this article [ link –> Portal ]
边栏推荐
猜你喜欢

SQL operation: with expression and its application

华为云发布桌面IDE-CodeArts

数学知识复习:三重积分

第 03 章 基于多尺度形态学提取眼前节组织-全套系统MATLAB智能驾驶深度学习

第 18 章 基于GUI搭建通用视频处理工具matlab应用GUI实现

High score schemes have been opened to the public, and the second round of the China "software Cup" remote sensing competition is coming!

Benchmarking copilot, the first in China: natural language one click generation method level code aixcoder XL is coming

ASEMI肖特基二极管1N5819参数,1N5819代换,1N5819货源

类和对象(下)

站在数字化风口,工装企业如何“飞起来”
随机推荐
php-admin部署-解决全部错误
Five years after graduation, I finally became a software testing engineer with a monthly salary of 13000
Localdatetime format time
LeetCode 5242. Best English letters with both upper and lower case
Winform项目控制台调试方式
出现IOError: No translation files found for default language zh-cn.的解决方法
出现UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe9 in position 0: ordinal not in range解决方法
Pyechart drawing word cloud
LocalDateTime格式化时间
Recommended by Ali, Tencent and Baidu software testing engineers - waterfall model of software testing model
MBA-day18 消元法
技术探秘: 360数科夺得ICDAR OCR竞赛世界第一
刚学了一个炫酷3D三棱锥立体特效,快来看看
ASEMI肖特基二极管1N5819参数,1N5819代换,1N5819货源
Point cloud registration -- 4pcs principle and Application
IE浏览器自动跳转edge怎么恢复
[noi simulation] interval distance (block and convolution)
一条短视频成本几十万元,虚拟数字人凭“实力”出圈
Rational rose 安装教程
ASEMI快恢复二极管FR107参数,FR107实物,FR107应用