Liberty BASIC Community Forum
Special Topics and Projects >> Contests >> Neural OCR
http://libertybasic.conforums.com/index.cgi?board=contests&action=display&num=1513197298

Neural OCR
Post by Rod on Dec 13th, 2017, 2:34pm

There has been some discussion about neural networks. A practical example appears to be Optical Character Recognition.

So just for fun for the holidays.

Create a 26 node neural net that accepts 72 inputs. It should attempt to recognise lower case a through z

You will need to create the net, train it and then have it assess characters.

In this bare bones code the bitmap character is stored as one long integer. AND the pixel data to see whether the pixel is the same or different.


Code:
'nomainwin
WindowWidth  = 600
WindowHeight = 600
UpperLeftX   = (DisplayWidth-WindowWidth)/2
UpperLeftY   = (DisplayHeight-WindowHeight)/2
graphicbox #1.enc, 10, 10, 10, 11
graphicbox #1.dec, 30, 10, 10, 11
open "Neural Net OCR" for window as #1

'Get the device context
hW=hwnd(#1.enc)
hDC = hDC(hW)

#1 "trapclose [quit]"
#1.enc "down ; font Courier_New 8"
#1.dec "down"

'#1.enc "place 0 7 ;\m"
'#1.enc "set 0 0"
'#1.enc "set 7 0"
'#1.enc "set 0 1"
dim bits(127)

for c= 97 to 122
    #1.enc "cls ; place 0 7 ;\";chr$(c)
    bits=0
    for y=0 to 8
        for x=0 to 7
            col=PixelLong(hDC,x,y)
            if col<16000000 then
                '#1.enc "color black ; set ";x;" ";y
                bits=bits + 2^(y*8+x)
                'print x,y,bits
            else
                '#1.enc "color white ; set ";x;" ";y
            end if
        next
    next
    #1.enc "color black"
    for y=0 to 8
        for x=0 to 7
            if bits and 2^(y*8+x) then
                #1.dec "color black ; set ";x;" ";y
            else
                #1.dec "color white ; set ";x;" ";y
            end if
        next
    next

    bits(c)=bits
next

wait


[quit]
call ReleaseDC hW,hDC
close #1
end



Function PixelLong(hDC, xVar, yVar)
    Open "gdi32"for DLL as #gdi
    CallDLL #gdi, "GetPixel",_
        hDC as Ulong,_
        xVar as Long,_
        yVar as Long,_
        PixelLong as Long
   Close #gdi
End Function

Function hDC(handle)
    CallDLL #user32, "GetDC",_
        handle as Ulong,_
        hDC as Ulong
End Function

Sub ReleaseDC hW, hDC
    CallDLL#user32,"ReleaseDC", _
        hW as Ulong, _
        hDC as Ulong, _
        result as Long
End Sub



 

Re: Neural OCR
Post by tsh73 on Dec 13th, 2017, 2:54pm

I'm completely un-aware of this.
Is it along
https://en.wikipedia.org/wiki/Artificial_neural_network
(EDIT:
https://en.wikipedia.org/wiki/Perceptron
?
)
or is where some introductory text exist?
Re: Neural OCR
Post by tenochtitlanuk on Dec 13th, 2017, 5:24pm

I played with this kind of thing in 2016.
See earlier poasting and also my site

Don't have time at present to play further but will be very interested in any contributions.
Re: Neural OCR
Post by Rod on Dec 14th, 2017, 02:48am

Bluatigro has posted once or twice. But his code is very difficult to understand. He puts few words of explanation in and the variables are cryptic. Given his vision this is entirely understandable.

I had not remembered John's work but I thought it might be fun to research and understand neurons/perceptrons a little more and code something.

It is just for fun. So read, research and code what you can.