Go Back   Gaming Gutter > Non-Gaming > Programming > Source Code


Source Code - Have a source code/project files you want to post? Do so here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» Recent Threads
Go to first new post If you had one day to...
11-03-2008 05:09 AM
Last post by ASHTEHCOMMIE
Today 11:44 PM
39 Replies, 643 Views
Go to first new post Neopets Auto Adopter
05-03-2008 09:10 AM
by Sid
Last post by fierce_deity.exe
Today 11:38 PM
299 Replies, 23,901 Views
Go to first new post Anyone here play RO?
11-12-2008 07:56 PM
Last post by Zagoy
Today 11:35 PM
11 Replies, 56 Views
Go to first new post Fav Football Team?
11-19-2008 03:58 PM
by shep
Last post by Zagoy
Today 11:33 PM
13 Replies, 62 Views
Go to first new post What's your weather?
11-08-2008 04:43 PM
by reirei
Last post by Zagoy
Today 11:33 PM
59 Replies, 362 Views
Reply
 
LinkBack Thread Tools Display Modes

 VB6 Neopets OCR
Old 04-08-2007, 09:19 PM   #1 (permalink)
sockopen
Guest

 
Posts: n/a
GPoints: 0 [Check]
iTrader: / %
VB6 Neopets OCR

This is the fastest writable and most accurate Neopets OCR I've written.

Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

Private Type SAFEARRAYBOUND
    cElements As Long
    lLbound As Long
End Type

Private Type SAFEARRAY2D
    cDims As Integer
    fFeatures As Integer
    cbElements As Long
    cLocks As Long
    pvData As Long
    Bounds(0 To 1) As SAFEARRAYBOUND
End Type

Private Type BITMAP
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type

Dim SA As SAFEARRAY2D, Data() As Byte

Private Sub picArr(captcha As StdPicture)
Dim BMP As BITMAP
    GetObjectAPI captcha.Handle, Len(BMP), BMP
    SA.cbElements = 1: SA.cDims = 2
    SA.Bounds(0).cElements = BMP.bmHeight
    SA.Bounds(1).cElements = BMP.bmWidth * 3 + 3 And &HFFFFFFFC
    SA.pvData = BMP.bmBits
    CopyMemory ByVal VarPtrArray(Data), VarPtr(SA), 4
End Sub

Private Sub dBox(ByVal x1&, ByVal y1&, ByVal R&)
Dim i As Integer
    For i = 0 To R
        Data((x1 + i) * 3 + 1, y1 + R) = 1 And &HFF
        Data((x1 + i) * 3 + 1, y1 - R) = 1 And &HFF
        Data((x1 - i) * 3 + 1, y1 + R) = 1 And &HFF
        Data((x1 - i) * 3 + 1, y1 - R) = 1 And &HFF
        Data((x1 + R) * 3 + 1, y1 + i) = 1 And &HFF
        Data((x1 + R) * 3 + 1, y1 - i) = 1 And &HFF
        Data((x1 - R) * 3 + 1, y1 + i) = 1 And &HFF
        Data((x1 - R) * 3 + 1, y1 - i) = 1 And &HFF
    Next i
End Sub

Public Function ChangePicture(picNewCaptcha As String)
    picCaptcha.Picture = LoadPicture(picNewCaptcha)
End Function

Public Function OCR() As String
Dim xPl As Long, yPl As Long, curCol As Long, i As Long
Dim t As Long: t = timeGetTime()
    picArr picCaptcha.Picture
    For xPl = 20 To picCaptcha.ScaleWidth - 20 Step 2
        For yPl = 20 To picCaptcha.ScaleHeight - 20 Step 2
            curCol = ((Data(xPl * 3, yPl) * 256&) + Data(xPl * 3 + 1, yPl)) * 256& + Data(xPl * 3 + 2, yPl)
            If (curCol And &HFF) + ((curCol \ 256) And &HFF) + ((curCol \ 65536) And &HFF) < 230 Then
                dBox xPl, yPl, 4
                yPl = picCaptcha.ScaleHeight - yPl
                OCR = "&x=" & xPl & "&y=" & yPl
                t = timeGetTime() - t
                picCaptcha.Refresh
                Exit Function
            End If
        Next yPl
    Next xPl
End Function
Copy that code into a 'User Control'; on the user control, you will need a PictureBox named picCaptcha. Under Properties of picCaptcha, ensure that ScaleMode has been set to '3 - Pixel'. Add this user control to your form and name it sockOCR, or, change it to whatever you want, in the following examples, the user control will be named sockOCR.

Change the picture on the user control:
Code:
sockOCR.ChangePicture App.Path & "\captcha.jpg"
Retrieve the co-ordinates from the image:
Code:
strCoordinates = sockOCR.OCR
and the new value of strCoordinates would be exactly that, the co-ordinates, which may be something like "&x=50&y=20"



This OCR more times than not takes less than 0 milliseconds to fully execute and return the co-ordinates, and was accurate on 9172 out of the 9173 tested images. Inserting the whole function into a Do loop that executes with a very dark color difference and decreases the acceptable color difference value until a dark enough spot is found increases the accuracy to 100% but sacrifices up to a couple milliseconds of time.
  Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -7. The time now is 11:45 PM.


vBulletin skin developed by: eXtremepixels
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.15847492 seconds (100.00% PHP - 0% MySQL) with 17 queries