網路上經常下載東西或者要登入帳號密碼時都會出現一組文字的驗證碼要求使用者輸入完畢後才可以登入下載,這時候我們可以嘗試著使用電腦幫我們做影像辨識,然後自動輸入這組文字,以下是程式碼暫時就不解是原理了。
當然以下這個程式只能辨識簡易的辨識系統或者辨識整篇文章...太複雜的圖片可能就沒辦法了
%% Image binary /圖像二值化 %將圖片背景雜訊刪除 pic = double(imread('2.jpeg')) ; gray_pic = zeros(size(pic,1),size(pic,2)); for j=1:size(pic,1) for i= 1:size(pic,2) gray_pic(j,i) = round(mean(pic(j,i,:))); % Get gray level picture end end gray_pic(gray_pic>80)=255 ; gray_pic(gray_pic<=80)=0 ; % Bindary thresholds = 80 imshow(uint8(gray_pic)) % see the result imagen=uint8(gray_pic); %將圖片辨識為文字 % Convert to BW threshold = graythresh(imagen); imagen =~im2bw(imagen,threshold); % Remove all object containing fewer than 30 pixels imagen = bwareaopen(imagen,30); %Storage matrix word from image word=[ ]; re=imagen; %Opens text.txt as file for write fid = fopen('text.txt', 'wt'); % Load templates load templates global templates % Compute the number of letters in template file num_letras=size(templates,2); while 1 %Fcn 'lines' separate lines in text [fl re]=lines(re); imgn=fl; %Uncomment line below to see lines one by one %imshow(fl);pause(0.5) %----------------------------------------------------------------- % Label and count connected components [L Ne] = bwlabel(imgn); for n=1:Ne [r,c] = find(L==n); % Extract letter n1=imgn(min(r):max(r),min(c):max(c)); % Resize letter (same size of template) img_r=imresize(n1,[42 24]); %Uncomment line below to see letters one by one %imshow(img_r);pause(0.5) %------------------------------------------------------------------- % Call fcn to convert image to text letter=read_letter(img_r,num_letras); % Letter concatenation word=[word letter]; end %fprintf(fid,'%s\n',lower(word));%Write 'word' in text file (lower) fprintf(fid,'%s\n',word);%Write 'word' in text file (upper) % Clear 'word' variable word=[ ]; %*When the sentences finish, breaks the loop if isempty(re) %See variable 're' in Fcn 'lines' break end end fclose(fid); %Open 'text.txt' file winopen('text.txt') clear all
感謝 您的教學 受益良多
回覆刪除