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 GG Last night I almost...
11-18-2009 04:30 PM
Last post by tox tha fox
Today 10:48 PM
14 Replies, 124 Views
Go to first new post 1.4billion :o
11-16-2009 12:43 PM
by tWi
Last post by l_royalty_l
Today 10:47 PM
14 Replies, 294 Views
Go to first new post Gay for Pay?
09-03-2009 02:30 PM
by Gloomy
Last post by Beaux
Today 10:46 PM
26 Replies, 282 Views
Go to first new post Monogamy - yes or no?
09-07-2009 12:53 PM
by Oops
Last post by kibblenecessity
Today 10:41 PM
28 Replies, 341 Views
Go to first new post Physical Beauty Or...
10-27-2009 02:13 PM
Last post by Beaux
Today 10:38 PM
33 Replies, 268 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: 131
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 10:53 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.18105507 seconds (100.00% PHP - 0% MySQL) with 21 queries