Quantcast

Jump to content


Photo

OCR in python?


  • Please log in to reply
52 replies to this topic

#26 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 28 March 2012 - 03:37 PM

Ill share my 13 failures with you; see if your methods work better. Who knows waser, maybe this is one test where the darkest pixel would have been better.

Waser: RunOCR_LaserWave <-- That method


The other method I developed actually got all of your failed ones. ;)

http://www.neocodex....ost__p__1257577

Pretty old and rough code but it still works. I suspect that method might be 100% accurate.

#27 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 28 March 2012 - 03:47 PM

I wish I could see that forum. What does it take in order to be able to view that thread?

#28 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 28 March 2012 - 03:52 PM

I wish I could see that forum. What does it take in order to be able to view that thread?

Ass kissing, and a lot of it.

Waser, could you hop on IRC?

#29 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 28 March 2012 - 03:54 PM

Ass kissing, and a lot of it.

Waser, could you hop on IRC?



Well that's disheartening... <_<

#30 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 28 March 2012 - 03:56 PM

How do you think i got to be admin after 1.5 years?

#31 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 28 March 2012 - 04:03 PM

How do you think i got to be admin after 1.5 years?


Ohh I didn't think that was an admin only forum. Jesus I don't ever expect to make it there.

#32 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 28 March 2012 - 04:36 PM

Ohh I didn't think that was an admin only forum. Jesus I don't ever expect to make it there.


It's not, it's programmer+ only.

#33 DoNotAnnoyMe

DoNotAnnoyMe
  • 157 posts

Posted 29 March 2012 - 01:18 AM

a little hint for the darkest pixel method: I found it to work better with a little weirdness added to the method (don't make stats myself tho, but with the normal darkest pixel it failed quite often):

yeah, it's JS, sue me :p


var w = this.captcha.width;
var h = this.captcha.height;

this.canvas.width  = w;
this.canvas.height = h;

var context = this.canvas.getContext("2d");
context.drawImage(this.captcha,0,0,w,h);
var data = context.getImageData(0,0,w,h).data; // height*width*RGBA

// find highest luminance of downscaled inversion
var image = new Array;
for(var i = 0; i+1 < h; i+=2)
{
  for(var j = 0; j+1 < w; j += 2)
  {
    var r = 0;
    var g = 0;
    var b = 0;
    for(var n = 0; n < 4; n++)
    {
      var start = 4*(j+(n%2)+(i+Math.floor(n/2))*w);
      r += data[start];
      g += data[start+1];
      b += data[start+2];
    }
    r = 256 - r/4;
    g = 256 - g/4;
    b = 256 - b/4;
    image.push(new Coord(j,i,(new Color(r,g,b,1)).Luminance()));
  }
}
image.sort(function(a,b) { return (a.v - b.v); });

// highest luinance one is our candidate
this.target = image.pop();

so in a nutshell: I take the image downscaled by 2 in both directions and take the average of all 4 "source pixels" as input - this seemed to yield a lot better results than working on the image itself :)

also luminance isn't really luminance, it's just the average of the rgb values (could also use sum)

Edited by DoNotAnnoyMe, 29 March 2012 - 01:22 AM.


#34 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 30 March 2012 - 09:33 AM

I downloaded an image pack of ~900. The same ones that RDD posted when he posted a tutorial on making an OCR. Checking every pixel only solve 2 more than every other pixel. It was still only aroun 94% accurate. I'll never make a superior product than abrosia so this exercise was pointless. <_<

#35 Icey Defeat

Icey Defeat
  • 8298 posts


Users Awards

Posted 30 March 2012 - 10:42 AM

a little hint for the darkest pixel method: I found it to work better with a little weirdness added to the method (don't make stats myself tho, but with the normal darkest pixel it failed quite often):

yeah, it's JS, sue me :p


var w = this.captcha.width;
var h = this.captcha.height;

this.canvas.width  = w;
this.canvas.height = h;

var context = this.canvas.getContext("2d");
context.drawImage(this.captcha,0,0,w,h);
var data = context.getImageData(0,0,w,h).data; // height*width*RGBA

// find highest luminance of downscaled inversion
var image = new Array;
for(var i = 0; i+1 < h; i+=2)
{
  for(var j = 0; j+1 < w; j += 2)
  {
    var r = 0;
    var g = 0;
    var b = 0;
    for(var n = 0; n < 4; n++)
    {
      var start = 4*(j+(n%2)+(i+Math.floor(n/2))*w);
      r += data[start];
      g += data[start+1];
      b += data[start+2];
    }
    r = 256 - r/4;
    g = 256 - g/4;
    b = 256 - b/4;
    image.push(new Coord(j,i,(new Color(r,g,b,1)).Luminance()));
  }
}
image.sort(function(a,b) { return (a.v - b.v); });

// highest luinance one is our candidate
this.target = image.pop();

so in a nutshell: I take the image downscaled by 2 in both directions and take the average of all 4 "source pixels" as input - this seemed to yield a lot better results than working on the image itself :)

also luminance isn't really luminance, it's just the average of the rgb values (could also use sum)


Were you noticing a massive decrease in speed? By massive I mean like 1 ms to 3 ms lol.

#36 RitzWin

RitzWin
  • 241 posts

Posted 30 March 2012 - 11:08 AM

I downloaded an image pack of ~900. The same ones that RDD posted when he posted a tutorial on making an OCR. Checking every pixel only solve 2 more than every other pixel. It was still only aroun 94% accurate. I'll never make a superior product than abrosia so this exercise was pointless. <_<


tbh, 94% is better then I do when I try to figure out what a captcha is saying IRL...

#37 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 30 March 2012 - 11:31 AM

It's clicking on the image of a neopet not solving for the letters haha

#38 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 March 2012 - 01:50 PM

I downloaded an image pack of ~900. The same ones that RDD posted when he posted a tutorial on making an OCR. Checking every pixel only solve 2 more than every other pixel. It was still only aroun 94% accurate. I'll never make a superior product than abrosia so this exercise was pointless. <_<


You should work at improving the accuracy, try to think of how you could do it.

#39 iargue

iargue
  • 10048 posts


Users Awards

Posted 30 March 2012 - 01:56 PM

Which one? I think the one we currently don't use in Abrosia is the most accurate.


Its sad that one was never implemented :(

#40 DoNotAnnoyMe

DoNotAnnoyMe
  • 157 posts

Posted 30 March 2012 - 02:01 PM

Were you noticing a massive decrease in speed? By massive I mean like 1 ms to 3 ms lol.


of course not as I'm still taking all pixels into account, just downscaling by averaging 4 input pixels into 1 output pixel to prevent single very dark pixels from making me fail :p

#41 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 March 2012 - 02:03 PM

Its sad that one was never implemented :(


Pyro is testing it in his own ABer, it might get added to Abrosia later on depending on how that testing goes.

#42 Caique

Caique
  • 12 posts

Posted 05 May 2014 - 07:23 PM

I'm sorry for up this old topic, but where can I find the raredaredevil's tutorial?
I already found the darkest pixel, so what now? D:

 

I dont wanna any code, I just want to know how this method works to implement it


Edited by Caique, 05 May 2014 - 07:24 PM.


#43 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 06 May 2014 - 01:27 AM

I'm sorry for up this old topic, but where can I find the raredaredevil's tutorial?
I already found the darkest pixel, so what now? D:

 

I dont wanna any code, I just want to know how this method works to implement it

 

You just need to send them as the x and y variables when you send your buy data.



#44 Caique

Caique
  • 12 posts

Posted 06 May 2014 - 06:28 AM

You just need to send them as the x and y variables when you send your buy data.

But I read that send the exactly x and y can be "dangerous". Generally the program "draw" the pet and send the central pixel.

Is it  that I want to know: I already found the darkest pixel, how I get the pet central pixel coordinates?


Edited by Caique, 06 May 2014 - 06:30 AM.


#45 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 06 May 2014 - 06:34 AM

But I read that send the exactly x and y can be "dangerous". Generally the program "draw" the pet and send the central pixel.

Is it  that I want to know: I already found the darkest pixel, how I get the pet central pixel coordinates?

 

There's no risk in just sending the coordinates for the darkest pixel. You could always just add a random offset to each coordinate if you really didn't want to send the darkest pixel position.



#46 Caique

Caique
  • 12 posts

Posted 06 May 2014 - 06:47 PM

There's no risk in just sending the coordinates for the darkest pixel. You could always just add a random offset to each coordinate if you really didn't want to send the darkest pixel position.

Oh Yeah, i did it and works *-----*

Now i'll terminate my code



#47 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 16 May 2014 - 04:03 PM

My PyCharm is expired right now but you can always convert to grayscale then make a box :D. I'd post my code but I'm slightly intoxicated and can't open PyCharm.


There's no risk in just sending the coordinates for the darkest pixel. You could always just add a random offset to each coordinate if you really didn't want to send the darkest pixel position.

 

I usually do X + randomint(2,10) and Y + randomint(2,11). Never had an issue in all the tests I've done on shop 21.



#48 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 16 May 2014 - 04:04 PM

My PyCharm is expired right now but you can always convert to grayscale then make a box :D. I'd post my code but I'm slightly intoxicated and can't open PyCharm.


 

I usually do X + randomint(2,10) and Y + randomint(2,11). Never had an issue in all the tests I've done on shop 21.

 

Why would you need to convert to grayscale?



#49 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 16 May 2014 - 04:10 PM

You don't really need to but it helped me initially to "see" what was going on in the image. If you convert it to gray scale or invert the image you get a better idea of the distinct features of the captcha. Speed is pretty irrelevant these days if you don't want to be frozen. If you're new you're better off making a functional OCR than saving 50 MS. 



#50 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 16 May 2014 - 04:13 PM

You don't really need to but it helped me initially to "see" what was going on in the image. If you convert it to gray scale or invert the image you get a better idea of the distinct features of the captcha. Speed is pretty irrelevant these days if you don't want to be frozen. If you're new you're better off making a functional OCR than saving 50 MS. 

 

The computer doesn't care though. :p An inverted image does look more impressive than just the regular one I guess. :p




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users