summaryrefslogtreecommitdiffstats
path: root/module/plugins/captcha
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-07-15 16:25:41 +0200
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-07-15 16:25:41 +0200
commit5060e4c6374a5116d0d8b02528f910f8c5f8bcf9 (patch)
treeb3f80dbd9e759747f9c2acb60f614c5daa7af69e /module/plugins/captcha
parentFix class definition (diff)
downloadpyload-5060e4c6374a5116d0d8b02528f910f8c5f8bcf9.tar.xz
Fix code indentation, some bad whitespaces and missing authors + use 'not' instead 'is None' + replace __pattern__'s r" with r' + other minor cosmetics
Diffstat (limited to 'module/plugins/captcha')
-rw-r--r--module/plugins/captcha/ShareonlineBiz.py3
-rw-r--r--module/plugins/captcha/captcha.py41
2 files changed, 29 insertions, 15 deletions
diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py
index 7b739c295..a3fbbed7c 100644
--- a/module/plugins/captcha/ShareonlineBiz.py
+++ b/module/plugins/captcha/ShareonlineBiz.py
@@ -20,6 +20,7 @@
from module.plugins.OCR import OCR
+
class ShareonlineBiz(OCR):
__name__ = "ShareonlineBiz"
__version__ = "0.1"
@@ -33,7 +34,7 @@ class ShareonlineBiz(OCR):
def __init__(self):
OCR.__init__(self)
- def get_captcha(self, image):
+ def get_captcha(self, image):
self.load_image(image)
self.to_greyscale()
self.image = self.image.resize((160, 50))
diff --git a/module/plugins/captcha/captcha.py b/module/plugins/captcha/captcha.py
index aa84a1a75..48f4a4217 100644
--- a/module/plugins/captcha/captcha.py
+++ b/module/plugins/captcha/captcha.py
@@ -149,19 +149,28 @@ class OCR(object):
for x in xrange(w):
for y in xrange(h):
- if pixels[x, y] == 255: continue
- # no point in processing white pixels since we only want to remove black pixel
+ if pixels[x, y] == 255:
+ continue
+ # No point in processing white pixels since we only want to remove black pixel
count = 0
try:
- if pixels[x-1, y-1] != 255: count += 1
- if pixels[x-1, y] != 255: count += 1
- if pixels[x-1, y + 1] != 255: count += 1
- if pixels[x, y + 1] != 255: count += 1
- if pixels[x + 1, y + 1] != 255: count += 1
- if pixels[x + 1, y] != 255: count += 1
- if pixels[x + 1, y-1] != 255: count += 1
- if pixels[x, y-1] != 255: count += 1
+ if pixels[x-1, y-1] != 255:
+ count += 1
+ if pixels[x-1, y] != 255:
+ count += 1
+ if pixels[x-1, y + 1] != 255:
+ count += 1
+ if pixels[x, y + 1] != 255:
+ count += 1
+ if pixels[x + 1, y + 1] != 255:
+ count += 1
+ if pixels[x + 1, y] != 255:
+ count += 1
+ if pixels[x + 1, y-1] != 255:
+ count += 1
+ if pixels[x, y-1] != 255:
+ count += 1
except:
pass
@@ -173,7 +182,8 @@ class OCR(object):
# second pass: this time set all 1's to 255 (white)
for x in xrange(w):
for y in xrange(h):
- if pixels[x, y] == 1: pixels[x, y] = 255
+ if pixels[x, y] == 1:
+ pixels[x, y] = 255
self.pixels = pixels
@@ -268,9 +278,12 @@ class OCR(object):
firstX = x
lastX = x
- if y > bottomY: bottomY = y
- if y < topY: topY = y
- if x > lastX: lastX = x
+ if y > bottomY:
+ bottomY = y
+ if y < topY:
+ topY = y
+ if x > lastX:
+ lastX = x
black_pixel_in_col = True