Results 1 to 2 of 2

Thread: [C#] Neopets OCR

  1. #1
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m

    [C#] Neopets OCR

    Code:
    using System.Drawing;
    using System.IO;
    using System.Text;
    
    namespace NeoFunctions
    {
        static class NeoOCR
        {
            public static Point OCR(string img)
            {
                using (MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(img)))
                {
                    return OCR(new Bitmap(ms));
                }
            }
    
            public static Point OCR(Bitmap img)
            {
                Point oS = new Point();
                int width = img.Width;
                int height = img.Height;
                float darkPixel = 1;
                for (int x = 0; x < width; x += 10)
                {
                    for (int y = 0; y < height; y += 10)
                    {
                        float curPixel = img.GetPixel(x, y).GetBrightness();
                        if (curPixel < darkPixel)
                        {
                            darkPixel = curPixel;
                            oS.X = x;
                            oS.Y = y;
                        }
                    }
                }
                return oS;
            }
    
            public static string AlternatePrice(string price)
            {
                string oldprice = price.Replace(",", string.Empty);
                string newprice = string.Empty;
                int alt = 1;
                while(newprice.Length < oldprice.Length)
                    newprice += oldprice[alt = alt == 1 ? 0 : 1];
                return newprice;
            }
        }
    }
    OCR(string img) - string parameter is the HTML of the captcha image (headers excluded). Returns the coordinates (as a Point) of the pet.
    OCR(Bitmap img) - Bitmap parameter is the captcha image. Returns the coordinates (as a Point) of the pet.

    AlternatePrice(string price) isn't really part of the OCR process but this takes the price and alternates the first two characters.
    Input: 28429 Output: 28282

  2. The Following 3 Users Say Thank You to Zachafer For This Useful Post:

    DarkByte (08-17-2012),j03 (08-02-2012),runbikesurf (08-17-2012)

  3. #2

    Joined
    Jun 2012
    Posts
    1,699
    Thanks
    876
    Thanked
    2,881/1,142
    DL/UL
    44/1
    Mentioned
    562 times
    Time Online
    118d 6h 45m
    Avg. Time Online
    40m
    same thing in vb.net

    Code:
     Public Function docaptcha(ByVal myBitmap As Bitmap) As Point
            Dim lowestbrightness As Single = 1000000
            Dim Height As Int32 = myBitmap.Width
            Dim Width As Int32 = myBitmap.Height
            Dim lowestbrightness_x As Integer
            Dim lowestbrightness_y As Integer
            For y = 0 To Width - 1 Step 4
                For x = 1 To Height - 1 Step 4
                    If x >= Height Then Exit For 'Debug shouldnt hit this
                    If y >= Width Then Exit For 'Debug shouldnt hit this
                    'myBitmap.SetPixel(x, y, Color.ForestGreen) 'Draw scan points
                    Dim pixelbright As Single = myBitmap.GetPixel(x, y).GetBrightness
                    If pixelbright < lowestbrightness Then
                        lowestbrightness = pixelbright
                        lowestbrightness_x = x
                        lowestbrightness_y = y
                    End If
                Next x
            Next y
    
            Return New Point(lowestbrightness_x, lowestbrightness_y)
        End Function
    implementation e.g;
    Dim newimage As Bitmap = thewrapper.getimage(captchaurl, thewrapper.LastPage)
    Dim ocrpoint As New Point
    ocrpoint = abhandler.docaptcha(newimage)
    strhtml = thewrapper.Request("POST", "http://www.neopets.com/haggle.phtml?current_offer=" & tempprice & "&x=" & ocrpoint.X & "&y=" & ocrpoint.Y, currentitemurl)
    If strhtml.Contains("I accept your") = True Then
    'Item bought
    buylog.Add("Bought item - " & currentitemname)
    End If
    Last edited by DarkByte; 08-17-2012 at 05:59 AM.

  4. The Following 2 Users Say Thank You to DarkByte For This Useful Post:

    j03 (08-17-2012),runbikesurf (08-17-2012)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •