最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

教你使用Matlab制作圖形驗(yàn)證碼生成器(app designer)

 更新時(shí)間:2022年02月28日 11:57:04   作者:slandarer  
這篇文章主要和大家分享如何利用Matlab制作一款圖形驗(yàn)證碼生成器,文中的實(shí)現(xiàn)步驟講解詳細(xì),感興趣的小伙伴可以跟隨小編動(dòng)手試一試

突然發(fā)現(xiàn)cla函數(shù)也可以應(yīng)用到app designer控件上,因而對(duì)部分內(nèi)容做出更改,將繪制隱藏像素刷新的方式改為用cla

hold(acAxes,'off');
image(acAxes,[-1,0],[-1,0],ones(1,1,3),'visible','off');
hold(acAxes,'on');

delete(findobj('tag','ax'));

cla(acAxes)
cla(ax)

0效果

1字符圖片生成

如果我們單純的用text繪制圖形,就無(wú)法做到效果中符號(hào)和符號(hào)邊緣兩個(gè)顏色,也無(wú)法做到更大程度的變形,因此我們需要將字符轉(zhuǎn)換為矩陣形式。

想要實(shí)現(xiàn)也非常簡(jiǎn)單,我們只需要?jiǎng)?chuàng)建一個(gè)不可視的fig,在其上繪制字符,保存fig為png格式圖片,再通過(guò)imread讀取圖片,就能獲得字符矩陣:

第一次運(yùn)行程序因?yàn)橐勺址麍D片因而會(huì)比較慢,再次運(yùn)行就可以讀取之前已經(jīng)生成過(guò)的圖片啦:

% 字符圖片矩陣構(gòu)造 ========================================================
% 以下為字符圖片創(chuàng)建過(guò)程
% 原理為構(gòu)造隱藏的figure和axes
% 在其上用text繪制字符并保存figure為圖片
% 導(dǎo)入圖片
if ~exist('Materials','dir')
   mkdir('Materials');
end
fig=figure('units','pixels',...
        'position',[20 80 200 200],...
        'Numbertitle','off',...
        'Color',[1 1 1],...
        'resize','off',...
        'visible','off',...
         'menubar','none');
ax=axes('Units','pixels',...
        'parent',fig,...  
        'Color',[1 1 1],...
        'Position',[0 0 200 200],...
        'XLim',[0 200],...
        'YLim',[0 200],...
        'XColor',[1 1 1],...
        'YColor',[1 1 1]);
strPic{length(strElement)}=[];
for i=1:length(strElement)
    % 若是不存在該字符圖片則生成,否則直接導(dǎo)入
    if ~exist(['.\Materials\',strElement(i),'.png'],'file')
        delete(findobj('tag','textStr'));
        text(ax,100,100,strElement(i),'HorizontalAlignment',...
            'center','FontSize',140,'tag','textStr','FontWeigh','bold')
        saveas(fig,['.\Materials\',strElement(i),'.png']);     % 保存圖片
    end
    tempPic=imread(['.\Materials\',strElement(i),'.png']);     % 讀取圖片
    strPic{i}=imresize(tempPic,[150,150]);             % 重新調(diào)整圖片大小
end

2刷新按鈕生成

大家可以看到這個(gè)按鈕的樣式與大部分按鈕不同:

實(shí)際上這是一個(gè)HTML控件,輸入html文件的位置就可以形成類似嵌入頁(yè)面的效果:

acHTML=uihtml(acFigure);
acHTML.HTMLSource='.\Materials\textbtn.html';
acHTML.DataChangedFcn=@refresh;
acHTML.Position=[300 50 88 26];

如代碼所示,我們導(dǎo)入的是Materials文件夾內(nèi)的textbtn.html文件

textbtn.html長(zhǎng)這樣:

<!DOCTYPE html>
<html>
    <head>
        <meta charset=UTF-8>
        <script type="text/javascript">
        function setup(htmlComponent) {           
            document.getElementById("btnonclink").addEventListener("click", function(event) {
                htmlComponent.Data="test";
            });
            }
        </script>
    </head>
    <body>
        <a href="" id=" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" btnonclink">看不清?</a>
    </body>
</html>

當(dāng)然為了防止大家不會(huì)創(chuàng)建,我在m文件中寫了一段能夠自動(dòng)創(chuàng)建html文件的代碼,原理就是將字符串信息寫入txt,再將txt文件后綴改為html:

% .html文件自動(dòng)生成及引入 - - - - - - - - - - - - - - - - - - - - - - - - - 
htmlContent={'<!DOCTYPE html><html><head><meta charset=UTF-8>';
'<script type="text/javascript">';
'function setup(htmlComponent){';         
'document.getElementById("btnonclink").addEventListener("click",function(event){';
'htmlComponent.Data="test";});}</script></head>';
'<body><a href="" id=" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" btnonclink">看不清?</a></body></html>'};
if ~exist('.\Materials\textbtn.html','file')
    fid=fopen('.\Materials\textbtn.txt','w');
    for i=1:length(htmlContent)
        fprintf(fid,'%s\r\n',htmlContent{i}); 
    end
    fclose(fid);
    copyfile('.\Materials\textbtn.txt','.\Materials\textbtn.html');
    delete('.\Materials\textbtn.txt')
end

3圖片處理

3.1圖像任意方向拉伸

這部分原理就是將圖像旋轉(zhuǎn)一定角度后,在豎直方向進(jìn)行拉伸后再旋轉(zhuǎn)回去

3.2字符邊緣

這部分原理將字符均值濾波后,把不完全是黑色的部分設(shè)置為灰色,后期再設(shè)置為其他顏色

3.3圖像處理部分代碼

randColor=@()randi([0,200],[1,3]);   % 生成隨機(jī)顏色的匿名函數(shù)

% 從圖像集合中提取圖像
tPic=strPic{randiNums(ii)};
tPic=tPic(:,:,1);

% 將圖像旋轉(zhuǎn)-拉伸-旋轉(zhuǎn)
randiTheta1=randi([0,90]);
randiTheta2=randi([-30,30]);
randiLenth=randi([0,70]);
tPic=imrotate(255-tPic,randiTheta1,'bilinear','crop');
tPic=imresize(tPic,[150+randiLenth,150]);
tPic=imrotate(tPic,-randiTheta1+randiTheta2,'bilinear','crop');

% 將圖像邊緣進(jìn)行模糊,并將模糊的部分?jǐn)?shù)值設(shè)置為150
tPic=255-imfilter(tPic,I_5);
tPic(tPic~=0&tPic~=255)=150;

% 為符號(hào)和符號(hào)邊緣賦予不同顏色
tempColor1=randColor();tempColor2=randColor();
tempPicR=tPic;tempPicG=tPic;tempPicB=tPic;
tempPicR(tPic==150)=tempColor1(1);tempPicR(tPic==0)=tempColor2(1);
tempPicG(tPic==150)=tempColor1(2);tempPicG(tPic==0)=tempColor2(2);
tempPicB(tPic==150)=tempColor1(3);tempPicB(tPic==0)=tempColor2(3);

tempPic_3=uint8(zeros([size(tPic),3]));
tempPic_3(:,:,1)=tempPicR;
tempPic_3(:,:,2)=tempPicG;
tempPic_3(:,:,3)=tempPicB;

4線條和散點(diǎn)生成

散點(diǎn)就是生成一堆隨機(jī)位置點(diǎn)和一些隨機(jī)顏色后用scatter函數(shù)繪制,線條是生成散點(diǎn)后使用’spline’插值方法插值成線后再繪制:

randColor=@()randi([0,200],[1,3]);           % 生成隨機(jī)顏色的匿名函數(shù)
randColor_n=@(n)randi([0,200],[n,3])./255;   % 生成n個(gè)隨機(jī)顏色的匿名函數(shù) 
randPoint_n=@(n)[randi([5,195],[n,1]),randi([5,65],[n,1])];% 生成n個(gè)隨機(jī)點(diǎn)的匿名函數(shù)

% 繪制散點(diǎn)
pPonintsNum=randi([6,10]);
pPoints=randPoint_n(pPonintsNum);
pPointsColor=randColor_n(pPonintsNum);
scatter(acAxes,pPoints(:,1),pPoints(:,2),6,'filled',...
    'CData',pPointsColor,'AlphaData',0.6)

% 繪制線
lPonintsNum=randi([5,7]);
lPoints=randPoint_n(lPonintsNum);
lPointsColor=[randColor()./255,0.6];
x_lPoints=interp1(1:lPonintsNum,lPoints(:,1),1:0.01:lPonintsNum,'spline');
y_lPoints=interp1(1:lPonintsNum,lPoints(:,2),1:0.01:lPonintsNum,'spline');
plot(acAxes,x_lPoints,y_lPoints,'Color',lPointsColor,'LineWidth',1.5)

5關(guān)于圖像存儲(chǔ)

由于目前版本uifigure還不支持存儲(chǔ)為圖像,因此我們繪制圖像是在figure和uifigure分別繪制一遍,其中figure依舊是不可見(jiàn)狀態(tài),主要用于將圖片驗(yàn)證碼保存為png格式,可以在完整代碼中看出這一點(diǎn)。

同時(shí),本程序的設(shè)置為,每次刷新圖形驗(yàn)證碼,都會(huì)刷新當(dāng)前文件夾下authCode.png為最新的驗(yàn)證碼,如需要保存請(qǐng)及時(shí)將其改名或復(fù)制另存:

6關(guān)于驗(yàn)證碼對(duì)比

首先就是需要提取框內(nèi)驗(yàn)證碼:

codeInPut=acEditField.Value;

因?yàn)槲覀兊尿?yàn)證碼字符都是大寫的,將輸入的文本用upper函數(shù)變?yōu)榇髮懀?/p>

codeInPut=upper(codeInPut);

同時(shí)我們因?yàn)?和O長(zhǎng)的太像,所以不對(duì)其進(jìn)行區(qū)分,直接將輸入的驗(yàn)證碼中的0改為O:

codeInPut(codeInPut=='0')='O';

之后就能夠用strcmp函數(shù)將當(dāng)前驗(yàn)證碼和輸入的驗(yàn)證碼進(jìn)行對(duì)比:

if strcmp(codeInPut,authCode)
    msgbox('驗(yàn)證碼正確')
else
    msgbox('驗(yàn)證碼錯(cuò)誤')
end

7完整代碼

function authCode
strElement=char([49:57,65:90]);              % 1-9,A-Z的字符
randColor=@()randi([0,200],[1,3]);           % 生成隨機(jī)顏色的匿名函數(shù)
randColor_n=@(n)randi([0,200],[n,3])./255;   % 生成n個(gè)隨機(jī)顏色的匿名函數(shù) 
randPoint_n=@(n)[randi([5,195],[n,1]),randi([5,65],[n,1])];% 生成n個(gè)隨機(jī)點(diǎn)的匿名函數(shù)
global authCode;                             % 全局變量:驗(yàn)證碼

% 字符圖片矩陣構(gòu)造 ========================================================
% 以下為字符圖片創(chuàng)建過(guò)程
% 原理為構(gòu)造隱藏的figure和axes
% 在其上用text繪制字符并保存figure為圖片
% 導(dǎo)入圖片
if ~exist('Materials','dir')
   mkdir('Materials');
end
fig=figure('units','pixels',...
        'position',[20 80 200 200],...
        'Numbertitle','off',...
        'Color',[1 1 1],...
        'resize','off',...
        'visible','off',...
         'menubar','none');
ax=axes('Units','pixels',...
        'parent',fig,...  
        'Color',[1 1 1],...
        'Position',[0 0 200 200],...
        'XLim',[0 200],...
        'YLim',[0 200],...
        'XColor',[1 1 1],...
        'YColor',[1 1 1]);
strPic{length(strElement)}=[];
for i=1:length(strElement)
    % 若是不存在該字符圖片則生成,否則直接導(dǎo)入
    if ~exist(['.\Materials\',strElement(i),'.png'],'file')
        delete(findobj('tag','textStr'));
        text(ax,100,100,strElement(i),'HorizontalAlignment',...
            'center','FontSize',140,'tag','textStr','FontWeigh','bold')
        saveas(fig,['.\Materials\',strElement(i),'.png']);     % 保存圖片
    end
    tempPic=imread(['.\Materials\',strElement(i),'.png']);     % 讀取圖片
    strPic{i}=imresize(tempPic,[150,150]);             % 重新調(diào)整圖片大小
end

% 更改fig ax樣式,為方便后期驗(yàn)證碼存儲(chǔ)
fig.Position=[100 100 200 70];
ax.Position=[1 1 199.5 70];
ax.XTick=[];
ax.YTick=[];
ax.XLim=[0,200];
ax.YLim=[0,70];
ax.XColor=[0.7 0.7 0.7];
ax.YColor=[0.7 0.7 0.7];
ax.Box='on';
ax.YDir='reverse';
hold(ax,'on');


% APP designer窗口構(gòu)建 ====================================================
acFigure=uifigure();
acFigure.Position=[100 100 370 90];
acFigure.Name='authCode';
acFigure.Resize='off';

acAxes=uiaxes(acFigure);
acAxes.Position=[10 10 200 70];
acAxes.XTick=[];
acAxes.YTick=[];
acAxes.XLim=[0,200];
acAxes.YLim=[0,70];
acAxes.XColor=[0.7 0.7 0.7];
acAxes.YColor=[0.7 0.7 0.7];
acAxes.Box='on';
acAxes.YDir='reverse';
hold(acAxes,'on');

acEditField=uieditfield(acFigure,'text');
acEditField.Position=[220 52 70 23];
acEditField.FontSize=16;
acEditField.FontWeight='bold';
acEditField.FontColor=[0.3,0.3,0.3];

% .html文件自動(dòng)生成及引入 - - - - - - - - - - - - - - - - - - - - - - - - - 
htmlContent={'<!DOCTYPE html><html><head><meta charset=UTF-8>';
'<script type="text/javascript">';
'function setup(htmlComponent){';         
'document.getElementById("btnonclink").addEventListener("click",function(event){';
'htmlComponent.Data="test";});}</script></head>';
'<body><a href="" id=" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" btnonclink">看不清?</a></body></html>'};
if ~exist('.\Materials\textbtn.html','file')
    fid=fopen('.\Materials\textbtn.txt','w');
    for i=1:length(htmlContent)
        fprintf(fid,'%s\r\n',htmlContent{i}); 
    end
    fclose(fid);
    copyfile('.\Materials\textbtn.txt','.\Materials\textbtn.html');
    delete('.\Materials\textbtn.txt')
end
acHTML=uihtml(acFigure);
acHTML.HTMLSource='.\Materials\textbtn.html';
acHTML.DataChangedFcn=@refresh;
acHTML.Position=[300 50 88 26];
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

acButton=uibutton(acFigure);
acButton.Position=[220 15 140 30];
acButton.Text='確 認(rèn) 驗(yàn) 證 碼';
acButton.BackgroundColor=[0.31 0.58 0.80];
acButton.FontColor=[1 1 1];
acButton.FontWeight='bold';
acButton.FontSize=14;
acButton.ButtonPushedFcn=@verify;

% 回調(diào)函數(shù) ================================================================
    function refresh(~,~)
        cla(acAxes)
        cla(ax)
        
        I_5=fspecial('average',[5,5]);   % 5*5均值濾波模板
        randiNums=randi([1,length(strElement)],[1,4]);
        authCode=strElement(randiNums);  % 驗(yàn)證碼
        disp(authCode)
        for ii=1:4
            tPic=strPic{randiNums(ii)};
            tPic=tPic(:,:,1);
            %tempPic(tempPic<250)=150;
            
            % 將圖像旋轉(zhuǎn)-拉伸-旋轉(zhuǎn)
            randiTheta1=randi([0,90]);
            randiTheta2=randi([-30,30]);
            randiLenth=randi([0,70]);    
            tPic=imrotate(255-tPic,randiTheta1,'bilinear','crop');
            tPic=imresize(tPic,[150+randiLenth,150]);
            tPic=imrotate(tPic,-randiTheta1+randiTheta2,'bilinear','crop'); 
            
            % 將圖像邊緣進(jìn)行模糊,并將模糊的部分?jǐn)?shù)值設(shè)置為150
            tPic=255-imfilter(tPic,I_5);
            tPic(tPic~=0&tPic~=255)=150;

            % 為符號(hào)和符號(hào)邊緣賦予不同顏色
            tempColor1=randColor();tempColor2=randColor();
            tempPicR=tPic;tempPicG=tPic;tempPicB=tPic;
            tempPicR(tPic==150)=tempColor1(1);tempPicR(tPic==0)=tempColor2(1);
            tempPicG(tPic==150)=tempColor1(2);tempPicG(tPic==0)=tempColor2(2);
            tempPicB(tPic==150)=tempColor1(3);tempPicB(tPic==0)=tempColor2(3);
            
            tempPic_3=uint8(zeros([size(tPic),3]));
            tempPic_3(:,:,1)=tempPicR;
            tempPic_3(:,:,2)=tempPicG;
            tempPic_3(:,:,3)=tempPicB;
            
            % 顯示圖片
            image(acAxes,[-size(tempPic_3,2)/2,size(tempPic_3,2)/2]./3.5+40*ii+randi([-5,5]),...
                         [-size(tempPic_3,1)/2,size(tempPic_3,1)/2]./3.5+35+randi([-5,5]),...
                         tempPic_3,'AlphaData',tempPic_3(:,:,1)~=255,'Interpolation','bilinear')
            image(ax,[-size(tempPic_3,2)/2,size(tempPic_3,2)/2]./3.5+40*ii+randi([-5,5]),...
                         [-size(tempPic_3,1)/2,size(tempPic_3,1)/2]./3.5+35+randi([-5,5]),...
                         tempPic_3,'AlphaData',tempPic_3(:,:,1)~=255,'Interpolation','bilinear')         
        end
        
        % 繪制散點(diǎn)
        pPonintsNum=randi([6,10]);
        pPoints=randPoint_n(pPonintsNum);
        pPointsColor=randColor_n(pPonintsNum);
        scatter(acAxes,pPoints(:,1),pPoints(:,2),6,'filled',...
            'CData',pPointsColor,'AlphaData',0.6)
        scatter(ax,pPoints(:,1),pPoints(:,2),6,'filled',...
            'CData',pPointsColor,'AlphaData',0.6)
        
        % 繪制線
        lPonintsNum=randi([5,7]);
        lPoints=randPoint_n(lPonintsNum);
        lPointsColor=[randColor()./255,0.6];
        x_lPoints=interp1(1:lPonintsNum,lPoints(:,1),1:0.01:lPonintsNum,'spline');
        y_lPoints=interp1(1:lPonintsNum,lPoints(:,2),1:0.01:lPonintsNum,'spline');
        plot(acAxes,x_lPoints,y_lPoints,'Color',lPointsColor,'LineWidth',1.5)
        plot(ax,x_lPoints,y_lPoints,'Color',lPointsColor,'LineWidth',1.5)
        
        saveas(fig,'.\authCode.png');
    end
refresh()

    function verify(~,~)
        codeInPut=acEditField.Value;
        codeInPut=upper(codeInPut);
        codeInPut(codeInPut=='0')='O';
        if strcmp(codeInPut,authCode)
            msgbox('驗(yàn)證碼正確')
        else
            msgbox('驗(yàn)證碼錯(cuò)誤')
        end
        
    end

end

:程序第一次運(yùn)行由于有html文件及png文件需要生成,因而會(huì)比較慢,之后的運(yùn)行速度會(huì)快很多。

對(duì)于以前版本沒(méi)有uihtml控件可以先嘗試如下代碼:

這里用正常按鈕替換了uihtml控件

function authCode2
strElement=char([49:57,65:90]);              % 1-9,A-Z的字符
randColor=@()randi([0,200],[1,3]);           % 生成隨機(jī)顏色的匿名函數(shù)
randColor_n=@(n)randi([0,200],[n,3])./255;   % 生成n個(gè)隨機(jī)顏色的匿名函數(shù) 
randPoint_n=@(n)[randi([5,195],[n,1]),randi([5,65],[n,1])];% 生成n個(gè)隨機(jī)點(diǎn)的匿名函數(shù)
global authCode;                             % 全局變量:驗(yàn)證碼

% 字符圖片矩陣構(gòu)造 ========================================================
% 以下為字符圖片創(chuàng)建過(guò)程
% 原理為構(gòu)造隱藏的figure和axes
% 在其上用text繪制字符并保存figure為圖片
% 導(dǎo)入圖片
if ~exist('Materials','dir')
   mkdir('Materials');
end
fig=figure('units','pixels',...
        'position',[20 80 200 200],...
        'Numbertitle','off',...
        'Color',[1 1 1],...
        'resize','off',...
        'visible','off',...
         'menubar','none');
ax=axes('Units','pixels',...
        'parent',fig,...  
        'Color',[1 1 1],...
        'Position',[0 0 200 200],...
        'XLim',[0 200],...
        'YLim',[0 200],...
        'XColor',[1 1 1],...
        'YColor',[1 1 1]);
strPic{length(strElement)}=[];
for i=1:length(strElement)
    % 若是不存在該字符圖片則生成,否則直接導(dǎo)入
    if ~exist(['.\Materials\',strElement(i),'.png'],'file')
        delete(findobj('tag','textStr'));
        text(ax,100,100,strElement(i),'HorizontalAlignment',...
            'center','FontSize',140,'tag','textStr','FontWeigh','bold')
        saveas(fig,['.\Materials\',strElement(i),'.png']);     % 保存圖片
    end
    tempPic=imread(['.\Materials\',strElement(i),'.png']);     % 讀取圖片
    strPic{i}=imresize(tempPic,[150,150]);             % 重新調(diào)整圖片大小
end

% 更改fig ax樣式,為方便后期驗(yàn)證碼存儲(chǔ)
fig.Position=[100 100 200 70];
ax.Position=[1 1 199.5 70];
ax.XTick=[];
ax.YTick=[];
ax.XLim=[0,200];
ax.YLim=[0,70];
ax.XColor=[0.7 0.7 0.7];
ax.YColor=[0.7 0.7 0.7];
ax.Box='on';
ax.YDir='reverse';
hold(ax,'on');


% APP designer窗口構(gòu)建 ====================================================
acFigure=uifigure();
acFigure.Position=[100 100 370 90];
acFigure.Name='authCode';
acFigure.Resize='off';

acAxes=uiaxes(acFigure);
acAxes.Position=[10 10 200 70];
acAxes.XTick=[];
acAxes.YTick=[];
acAxes.XLim=[0,200];
acAxes.YLim=[0,70];
acAxes.XColor=[0.7 0.7 0.7];
acAxes.YColor=[0.7 0.7 0.7];
acAxes.Box='on';
acAxes.YDir='reverse';
hold(acAxes,'on');

acEditField=uieditfield(acFigure,'text');
acEditField.Position=[220 52 70 23];
acEditField.FontSize=16;
acEditField.FontWeight='bold';
acEditField.FontColor=[0.3,0.3,0.3];

acfreshBtn=uibutton(acFigure);
acfreshBtn.Text='看不清?';
acfreshBtn.ButtonPushedFcn=@refresh;
acfreshBtn.Position=[300 50 60 27];
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

acButton=uibutton(acFigure);
acButton.Position=[220 15 140 30];
acButton.Text='確 認(rèn) 驗(yàn) 證 碼';
acButton.BackgroundColor=[0.31 0.58 0.80];
acButton.FontColor=[1 1 1];
acButton.FontWeight='bold';
acButton.FontSize=14;
acButton.ButtonPushedFcn=@verify;

% 回調(diào)函數(shù) ================================================================
    function refresh(~,~)
        cla(acAxes)
        cla(ax)
%         hold(acAxes,'off');
%         image(acAxes,[-1,0],[-1,0],ones(1,1,3),'visible','off');
%         hold(acAxes,'on');
%         delete(findobj('tag','ax'));
        
        I_5=fspecial('average',[5,5]);   % 5*5均值濾波模板
        randiNums=randi([1,length(strElement)],[1,4]);
        authCode=strElement(randiNums);  % 驗(yàn)證碼
        disp(authCode)
        for ii=1:4
            tPic=strPic{randiNums(ii)};
            tPic=tPic(:,:,1);
            %tempPic(tempPic<250)=150;
            
            % 將圖像旋轉(zhuǎn)-拉伸-旋轉(zhuǎn)
            randiTheta1=randi([0,90]);
            randiTheta2=randi([-30,30]);
            randiLenth=randi([0,70]);    
            tPic=imrotate(255-tPic,randiTheta1,'bilinear','crop');
            tPic=imresize(tPic,[150+randiLenth,150]);
            tPic=imrotate(tPic,-randiTheta1+randiTheta2,'bilinear','crop'); 
            
            % 將圖像邊緣進(jìn)行模糊,并將模糊的部分?jǐn)?shù)值設(shè)置為150
            tPic=255-imfilter(tPic,I_5);
            tPic(tPic~=0&tPic~=255)=150;

            % 為符號(hào)和符號(hào)邊緣賦予不同顏色
            tempColor1=randColor();tempColor2=randColor();
            tempPicR=tPic;tempPicG=tPic;tempPicB=tPic;
            tempPicR(tPic==150)=tempColor1(1);tempPicR(tPic==0)=tempColor2(1);
            tempPicG(tPic==150)=tempColor1(2);tempPicG(tPic==0)=tempColor2(2);
            tempPicB(tPic==150)=tempColor1(3);tempPicB(tPic==0)=tempColor2(3);
            
            tempPic_3=uint8(zeros([size(tPic),3]));
            tempPic_3(:,:,1)=tempPicR;
            tempPic_3(:,:,2)=tempPicG;
            tempPic_3(:,:,3)=tempPicB;
            
            % 顯示圖片
            image(acAxes,[-size(tempPic_3,2)/2,size(tempPic_3,2)/2]./3.5+40*ii+randi([-5,5]),...
                         [-size(tempPic_3,1)/2,size(tempPic_3,1)/2]./3.5+35+randi([-5,5]),...
                         tempPic_3,'AlphaData',tempPic_3(:,:,1)~=255,'Interpolation','bilinear')
            image(ax,[-size(tempPic_3,2)/2,size(tempPic_3,2)/2]./3.5+40*ii+randi([-5,5]),...
                         [-size(tempPic_3,1)/2,size(tempPic_3,1)/2]./3.5+35+randi([-5,5]),...
                         tempPic_3,'AlphaData',tempPic_3(:,:,1)~=255,'Interpolation','bilinear')         
        end
        
        % 繪制散點(diǎn)
        pPonintsNum=randi([6,10]);
        pPoints=randPoint_n(pPonintsNum);
        pPointsColor=randColor_n(pPonintsNum);
        scatter(acAxes,pPoints(:,1),pPoints(:,2),6,'filled',...
            'CData',pPointsColor,'AlphaData',0.6)
        scatter(ax,pPoints(:,1),pPoints(:,2),6,'filled',...
            'CData',pPointsColor,'AlphaData',0.6)
        
        % 繪制線
        lPonintsNum=randi([5,7]);
        lPoints=randPoint_n(lPonintsNum);
        lPointsColor=[randColor()./255,0.6];
        x_lPoints=interp1(1:lPonintsNum,lPoints(:,1),1:0.01:lPonintsNum,'spline');
        y_lPoints=interp1(1:lPonintsNum,lPoints(:,2),1:0.01:lPonintsNum,'spline');
        plot(acAxes,x_lPoints,y_lPoints,'Color',lPointsColor,'LineWidth',1.5)
        plot(ax,x_lPoints,y_lPoints,'Color',lPointsColor,'LineWidth',1.5)
        
        saveas(fig,'.\authCode.png');
    end
refresh()

    function verify(~,~)
        codeInPut=acEditField.Value;
        codeInPut=upper(codeInPut);
        codeInPut(codeInPut=='0')='O';
        if strcmp(codeInPut,authCode)
            msgbox('驗(yàn)證碼正確')
        else
            msgbox('驗(yàn)證碼錯(cuò)誤')
        end
        
    end

end

以上就是教你使用Matlab制作圖形驗(yàn)證碼生成器(app designer)的詳細(xì)內(nèi)容,更多關(guān)于Matlab圖形驗(yàn)證碼生成器的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C++深入講解類與封裝的概念與使用

    C++深入講解類與封裝的概念與使用

    我們都知道C++有三大特性:封裝、繼承、多態(tài),現(xiàn)在我們來(lái)總結(jié)一下封裝的相關(guān)知識(shí)與類的概念,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-04-04
  • c++ 移動(dòng)構(gòu)造相關(guān)總結(jié)

    c++ 移動(dòng)構(gòu)造相關(guān)總結(jié)

    這篇文章主要介紹了c++ 移動(dòng)構(gòu)造的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用c++,感興趣的朋友可以了解下
    2021-02-02
  • C++實(shí)現(xiàn)T型插補(bǔ)詳解

    C++實(shí)現(xiàn)T型插補(bǔ)詳解

    這篇文章主要介紹了C++實(shí)現(xiàn)T型插補(bǔ),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-10-10
  • C++關(guān)鍵字mutable學(xué)習(xí)筆記

    C++關(guān)鍵字mutable學(xué)習(xí)筆記

    這篇文章主要為大家介紹了C++關(guān)鍵字mutable學(xué)習(xí)筆記,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10
  • C++構(gòu)造函數(shù)深度學(xué)習(xí)

    C++構(gòu)造函數(shù)深度學(xué)習(xí)

    這篇文章主要為大家詳細(xì)介紹了C++構(gòu)造函數(shù),深度學(xué)習(xí)C++構(gòu)造函數(shù),感興趣的小伙伴們可以參考一下
    2016-08-08
  • C++知識(shí)點(diǎn)之inline函數(shù)、回調(diào)函數(shù)和普通函數(shù)

    C++知識(shí)點(diǎn)之inline函數(shù)、回調(diào)函數(shù)和普通函數(shù)

    這篇文章主要給大家介紹了關(guān)于C++知識(shí)點(diǎn)之inline函數(shù)、回調(diào)函數(shù)和普通函數(shù)的相關(guān)使用方法,以及回調(diào)函數(shù)和普通函數(shù)的區(qū)別小結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-07-07
  • Ubuntu18.04上安裝Qt5.10的步驟實(shí)踐

    Ubuntu18.04上安裝Qt5.10的步驟實(shí)踐

    Qt是一個(gè)跨平臺(tái)的C++圖形用戶界面庫(kù),本文就介紹了Ubuntu18.04上安裝Qt5.10的步驟實(shí)踐,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • C語(yǔ)言實(shí)現(xiàn)三子棋游戲

    C語(yǔ)言實(shí)現(xiàn)三子棋游戲

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)三子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • 重構(gòu)-C++實(shí)現(xiàn)矩陣的簡(jiǎn)單實(shí)例

    重構(gòu)-C++實(shí)現(xiàn)矩陣的簡(jiǎn)單實(shí)例

    下面小編就為大家?guī)?lái)一篇重構(gòu)-C++實(shí)現(xiàn)矩陣的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-06-06
  • 學(xué)生成績(jī)管理系統(tǒng)C語(yǔ)言代碼實(shí)現(xiàn)

    學(xué)生成績(jī)管理系統(tǒng)C語(yǔ)言代碼實(shí)現(xiàn)

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言代碼實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01

最新評(píng)論

大洼县| 都江堰市| 武穴市| 马关县| 河池市| 莱阳市| 万荣县| 安化县| 永胜县| 五台县| 许昌市| 安仁县| 乐昌市| 镇巴县| 天镇县| 黎川县| 班玛县| 武威市| 饶河县| 黄陵县| 冀州市| 太和县| 曲阜市| 华池县| 城市| 开原市| 饶阳县| 大兴区| 台州市| 洞头县| 吉木萨尔县| 正阳县| 定远县| 兰州市| 定日县| 孝感市| 平陆县| 旬邑县| 梧州市| 泊头市| 南郑县|