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
» GG Stuff

Follow us on Twitter!

Get the GG toolbar today (for firefox only)
» Recent Threads
Go to first new post [PHP] MD5 List Cracker
11-19-2009 05:00 PM
by tWi
Last post by mehike
Today 04:43 AM
12 Replies, 182 Views
Go to first new post Journaling
11-17-2009 06:53 PM
by Cody!
Last post by Charger
Today 04:40 AM
5 Replies, 52 Views
Go to first new post If you could be the...
Today 03:57 AM
by Charger
Last post by Charger
Today 04:18 AM
2 Replies, 12 Views
Go to first new post Post Your Picture (Read...
10-10-2006 12:34 AM
by Ryan
Last post by Fran
Today 04:12 AM
13,111 Replies, 221,438 Views
Go to first new post Does it make a guy gay...
03-22-2009 01:32 PM
Last post by Charger
Today 04:11 AM
263 Replies, 7,787 Views
Reply
 
LinkBack Thread Tools Display Modes

 [Javascript] Neopets OCR
Old 09-25-2009, 01:37 PM   #1 (permalink)
Junior Member

Male sim0n is offline
 
sim0n's Avatar
 
Join Date: May 2009
Location: UK
Age: 18
Posts: 22
GPoints: 132
iTrader: 0 / 0%
sim0n Is Recognizable
Rep Power: 0
[Javascript] Neopets OCR

Another implementation of the "darkest pixel" OCR method for Neopets autobuyers. Wrote this one for a Greasemonkey autobuyer I've been working on.

Requires the Canvas tag (HTML 5) however since this will be ran through Greasemonkey, I would assume that you all keep your browsers up to date and the Canvas tag is implemented in the latest versions of Firefox, Opera, Safari, and Konqueror.

Code:
function getDarkestPixel(src, c) {
    if (c == undefined) {
        c = document.createElement("canvas");
        document.appendChild(c);
    }
    var img = new Image()
    img.src = src;
    img.onload = function() {

        c.width = img.width;
        c.height = img.height;
        var cvx = c.getContext("2d");
        cvx.drawImage(img, 0, 0);
        var imgd = cvx.getImageData(0, 0, img.width, img.height);
        
        var intDarkest = 765;
        var ptDarkest = new Array(2);

        for (y = 0; y < imgd.height; y++) {
            for (x = 0; x < imgd.width; x++) {
                var i = (y * 4) * imgd.width + (x * 4);
                var intColour = imgd.data[i] + imgd.data[i+1] + imgd.data[i+2];

                if(intColour < intDarkest) {
                    intDarkest = intColour;
                    ptDarkest[0] = x;
                    ptDarkest[1] = y;
                }
            }
        }
        
        i = (ptDarkest[1] * 4) * imgd.width + (ptDarkest[0] * 4);
        
        imgd.data[i]=255;
        imgd.data[i+1]=255;
        imgd.data[i+2]=255;
        imgd.data[i+3]=255; 
        cvx.putImageData(imgd,0,0,0,0, imgd.width, imgd.height);
    }
}
usage:

Code:
            var c = document.createElement("canvas");
            c.id = "canvas"
            document.body.appendChild(c)
            getDarkestPixel("http://www.neopets.com/captcha_show.phtml?_x_pwned...", c)
__________________

  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.1.0

All times are GMT -7. The time now is 05:26 AM.


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.21101999 seconds (100.00% PHP - 0% MySQL) with 21 queries