Bedir Halcı
Published © GPL3+

Antique Book Classifier

The fundamental purpose of this work is to extract book properties from the title pages of antique books and classify them accordingly.

AdvancedWork in progress30 days656
Antique Book Classifier

Things used in this project

Hardware components

Digilent Zynq-7010
FPGA
×1
Pmod CLP
Digilent Pmod CLP
Display
×1
Digilent Pcam 5C
Camera
×1

Software apps and online services

MATLAB
MATLAB
Code Development
Vivado Design Suite
AMD Vivado Design Suite
Hardware Design with Verilog Description

Story

Read more

Schematics

Hardware Design

Overall schematic for basic design

Code

MATLAB Codes to Develop Overall Algorithm - I

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function [R w]=Sunum(n)
clearvars -except n
[R w s1 s2]=Core('alphabet.jpg','dic.jpg',n);
end

MATLAB Codes to Develop Overall Algorithm – II

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function [R,text,sym1,sym2]=Core(im1,im2,n)
text='';
az='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
sym1=Let(im1,0,n);
sym2=Let(im2,0,n);
R=zeros(length(sym1),length(sym2));
for i=1:length(sym1)
    for j=1:length(sym2)
        R(i,j)=sym1{i}'*sym2{j}/(norm(sym1{i})*norm(sym2{j}));
    end
end
for i=1:length(sym1)
    sym1{i}=sym1{i}/norm(sym1{i});
end
for j=1:length(sym2)
    [M,I]=max(R(:,j));
    text=[text az(I)];
end
end

MATLAB Codes to Develop Overall Algorithm – III

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function sym=Let(im,bol,nu)
i=imread(im);
if size(i,3)==3
    i=rgb2gray(i);
end
t=0.5;
i=~im2bw(i,t);
if bol
    figure
    imshow(i);
end
u=1;
i=bwareaopen(i,u);
siz=size(i);
b=true;
c=false;
d=true;
x=[];
y=x;
for j=1:siz(1);
    for k=1:siz(2);
        if b && ~c && i(j,k)==1
            b=false;
            break;
        end
        if c
            d=d&~i(j,k);
            if ~d
                break;
            end
        end
        b=true;
    end
    if c&&d
        y=[y j];
        b=true;
        c=false;
    end
    if ~b
        c=true;
        x=[x j];
    end
    d=true;
end
rows={};
for k=1:length(x);
    rows{end+1}=i(x(k):y(k),:);
    %figure
    %imshow(rows{end});
end
k=0;
symbols={};
for n=1:length(x);
    siz=size(rows{n});
    b=true;
    c=false;
    d=true;
    x=[];
    y=x;
    for q=1:siz(2);
        for p=1:siz(1);
            if b && ~c && rows{n}(p,q)==1
                b=false;
                break;
            end
            if c
                d=d&~rows{n}(p,q);
                if ~d
                    break;
                end
            end
            b=true;
        end
        if c&&d
            y=[y q];
            b=true;
            c=false;
        end
        if d&&~b
            c=true;
            x=[x q];
        end
        d=true;
    end
    for p=1:length(x);
        a=(rows{n}(:,x(p):y(p)));
        alp=a(any(a,2),:);
        symbols{end+1}=alp;
    end
    k=k+length(x);
end
al=nu-1;
sym={};
m=200;
for k=1:length(symbols)
    u=svd(double(symbols{k}));
    %u=u(u>1);
    len=length(u);
    if len>al
        u=u(end-al:end);
    else
        u=[zeros(al+1-len,1);u];
    end
    u=u/norm(u);
    u=[zeros(m-length(u),1)' u']';
    sym{end+1}=u;
end
end

MATLAB Codes to Develop Overall Algorithm – IV

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function s=archetype

s1=svder('Bohemia.jpg');
s2=svder('Uru.jpg');

s=(s1+s2)/2;

end

MATLAB Codes to Develop Overall Algorithm – V

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function s=svder(image)
i=imread(image);
if size(i,3)==3
    i=rgb2gray(i);
end
t=0.5;
i=~im2bw(i,t);
u=1;
i=bwareaopen(i,u);
siz=size(i);
b=true;
c=false;
d=true;
x=[];
y=x;
for j=1:siz(1);
    for k=1:siz(2);
        if b && ~c && i(j,k)==1
            b=false;
            break;
        end
        if c
            d=d&~i(j,k);
            if ~d
                break;
            end
        end
        b=true;
    end
    if c&&d
        y=[y j];
        b=true;
        c=false;
    end
    if ~b
        c=true;
        x=[x j];
    end
    d=true;
end
rows={};
for k=1:length(x);
    rows{end+1}=i(x(k):y(k),:);
end
k=0;
symbols={};
for n=1:length(x);
    siz=size(rows{n});
    b=true;
    c=false;
    d=true;
    x=[];
    y=x;
    for q=1:siz(2);
        for p=1:siz(1);
            if b && ~c && rows{n}(p,q)==1
                b=false;
                break;
            end
            if c
                d=d&~rows{n}(p,q);
                if ~d
                    break;
                end
            end
            b=true;
        end
        if c&&d
            y=[y q];
            b=true;
            c=false;
        end
        if d&&~b
            c=true;
            x=[x q];
        end
        d=true;
    end
    for p=1:length(x);
        a=(rows{n}(:,x(p):y(p)));
        alp=a(any(a,2),:);
        symbols{end+1}=alp;
    end
    k=k+length(x);
end
al=5;
sym={};
for k=1:length(symbols)
    u=svd(double(symbols{k}));
    if length(u)>=al
        u=u(1:al);
    else
        u=[u;zeros(al-length(u),1)];
    end
    u=u/norm(u);
    sym{end+1}=u;
end
s=[];
for n=1:length(sym)
    s=[s sym{n}];
end

end

MATLAB Codes to Develop Overall Algorithm – VI

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function t=tester(i,s)

im=imread(i);
v=vectorer(im);
t=extracter(v,s);

end

MATLAB Codes to Develop Overall Algorithm – VII

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function v=vectorer(im)

n=80;

v=[];
for i=1:n
    v=[v im(i,:)];
end

end

MATLAB Codes to Develop Overall Algorithm – VIII

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function t=extracter(v,s)

I=matrixer(v);
M=finder(I);
R=correlater(M,s);
t=texter(R);

end

MATLAB Codes to Develop Overall Algorithm – IX

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function I=matrixer(v)

n=80;

I=zeros(n);

for i=1:n
    I(i,:)=v(n*(i-1)+1:n*i);
end

end

MATLAB Codes to Develop Overall Algorithm – X

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function M=finder(I)

nu=5;
u=svd(I);
u=u(1:nu);
M=u/norm(u);
plot(M)

end

MATLAB Codes to Develop Overall Algorithm – XI

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function R=correlater(M,s)

n=65;

R=zeros(n,1);
m=mean(s')';

for i=1:n
        R(i)=dot(s(:,i)-m,M-m);
end

end

MATLAB Codes to Develop Overall Algorithm – XII

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function t=texter(R)

n=65;

az='AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz.,0123456789-';
[aa,indices]=sort(R,'descend');
for i=1:n
    if R(indices(i))>0.04
        t(i)=az(indices(i));
    end
end

end

MATLAB Codes to Develop Overall Algorithm – XIII

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function r=arethey(i1,i2)

im1=imread(i1);
if size(im1,3)==3
    im1=rgb2gray(im1);
end
t1=0.5;
im1=~im2bw(im1,t1);
v1=double(rectorer(im1));
im2=imread(i2);
if size(im2,3)==3
    im2=rgb2gray(im2);
end
t2=0.5;
im2=~im2bw(im2,t2);
v2=double(rectorer(im2));
r=dot(v1,v2)/(norm(v1)*norm(v2));

end

MATLAB Codes to Develop Overall Algorithm – XIV

MATLAB
The basis codes that are derived from Logical Reasoning and Brainstorming
function v=rectorer(im)

n=275;

v=[];
for i=1:n
    v=[v im(i,:)];
end

end

Verilog Description to Develop Overall Hardware Design - I

Verilog
The basis schematic that is derived from Logical Reasoning and Pre-Thinking
module abc(i,p,z);
input i;
output p,z;
wire o,e,q,s,y;
camera camera(i,o);
extraction extraction(o,e);
search search(e,q,s,y);
ethernet ethernet(s,p,q);
display display(y,z);
endmodule

module camera(i,o);
input i;
output o;
endmodule

module extraction(o,e);
input o;
output e;
endmodule

module search(e,q,s,y);
input e,q;
output s,y;
endmodule

module ethernet(s,p,q);
input s;
output p,q;
endmodule

module display(y,z);
input y;
output z;
endmodule

Verilog Description to Develop Overall Hardware Design - II

Verilog
The basis codes that are derived from the MATLAB codes
module vcabc(i,o);
input [6:0] i;
output [2:0] o;
parameter [6:0] p=7'b1010101;
corr ccc(i,p,o);
endmodule

module corr(x,y,o);
input [6:0] x,y;
output [2:0] o;
wire [6:0] w;
assign w=x^y;
sum6 sss(w,o);
endmodule

module sum6(i,o);
input [6:0] i;
output [2:0] o;
assign o=i[0]+i[1]+i[2]+i[3]+i[4]+i[5]+i[6];
endmodule

Credits

Bedir Halcı
1 project • 1 follower
An engineering and physics student at Marmara University who analyse reality in a philosophical manner and theorise possible teleologies.
Contact

Comments

Please log in or sign up to comment.