summaryrefslogtreecommitdiffstats
path: root/module/plugins/captcha/captcha.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/captcha/captcha.py')
-rw-r--r--module/plugins/captcha/captcha.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/module/plugins/captcha/captcha.py b/module/plugins/captcha/captcha.py
index fb85d8996..dda6fed02 100644
--- a/module/plugins/captcha/captcha.py
+++ b/module/plugins/captcha/captcha.py
@@ -28,18 +28,22 @@ class OCR(object):
def __init__(self):
self.logger = logging.getLogger("log")
+
def load_image(self, image):
self.image = Image.open(image)
self.pixels = self.image.load()
self.result_captcha = ''
+
def unload(self):
"""delete all tmp images"""
pass
+
def threshold(self, value):
self.image = self.image.point(lambda a: a * value + 10)
+
def run(self, command):
"""Run a command"""
@@ -50,6 +54,7 @@ class OCR(object):
popen.stderr.close()
self.logger.debug("Tesseract ReturnCode %s Output: %s" % (popen.returncode, output))
+
def run_tesser(self, subset=False, digits=True, lowercase=True, uppercase=True):
#tmpTif = tempfile.NamedTemporaryFile(suffix=".tif")
tmpTif = open(join("tmp", "tmpTif_%s.tif" % self.__name__), "wb")
@@ -103,15 +108,18 @@ class OCR(object):
except:
pass
+
def get_captcha(self, name):
raise NotImplementedError
+
def to_greyscale(self):
if self.image.mode != 'L':
self.image = self.image.convert('L')
self.pixels = self.image.load()
+
def eval_black_white(self, limit):
self.pixels = self.image.load()
w, h = self.image.size
@@ -122,6 +130,7 @@ class OCR(object):
else:
self.pixels[x, y] = 0
+
def clean(self, allowed):
pixels = self.pixels
@@ -167,6 +176,7 @@ class OCR(object):
self.pixels = pixels
+
def derotate_by_average(self):
"""rotate by checking each angle and guess most suitable"""
@@ -241,6 +251,7 @@ class OCR(object):
self.pixels = pixels
+
def split_captcha_letters(self):
captcha = self.image
started = False
@@ -280,6 +291,7 @@ class OCR(object):
return letters
+
def correct(self, values, var=None):
if var:
result = var