diff options
Diffstat (limited to 'module/plugins/internal')
-rw-r--r-- | module/plugins/internal/Captcha.py | 18 | ||||
-rw-r--r-- | module/plugins/internal/OCR.py | 34 |
2 files changed, 26 insertions, 26 deletions
diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index da5440978..fe0830693 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -47,11 +47,11 @@ class Captcha(Plugin): return self.decrypt_image(img, input_type, output_type, ocr, timeout) - def decrypt_image(self, data, input_type='jpg', output_type='textual', ocr=False, timeout=120): + def decrypt_image(self, img, input_type='jpg', output_type='textual', ocr=False, timeout=120): """ Loads a captcha and decrypts it with ocr, plugin, user input - :param data: image raw data + :param img: image raw data :param get: get part for request :param post: post part for request :param cookies: True if cookies should be enabled @@ -66,21 +66,21 @@ class Captcha(Plugin): result = "" time_ref = ("%.2f" % time.time())[-6:].replace(".", "") - with open(os.path.join("tmp", "captcha_image_%s_%s.%s" % (self.pyfile.plugin.__name__, time_ref, input_type)), "wb") as tmp_img: - tmp_img.write(encode(data)) + with open(os.path.join("tmp", "captcha_image_%s_%s.%s" % (self.pyfile.plugin.__name__, time_ref, input_type)), "wb") as img_f: + img_f.write(encode(img)) if ocr: if isinstance(ocr, basestring): - OCR = self.pyload.pluginManager.loadClass("captcha", ocr) #: Rename `captcha` to `ocr` in 0.4.10 - result = OCR(self.pyfile).recognize(tmp_img.name) + _OCR = self.pyload.pluginManager.loadClass("captcha", ocr) #: Rename `captcha` to `ocr` in 0.4.10 + result = _OCR(self.pyfile).recognize(img_f.name) else: - result = self.recognize(tmp_img.name) + result = self.recognize(img_f.name) if not result: captchaManager = self.pyload.captchaManager try: - self.task = captchaManager.newTask(data, input_type, tmp_img.name, output_type) + self.task = captchaManager.newTask(img, input_type, img_f.name, output_type) captchaManager.handleCaptcha(self.task) @@ -101,7 +101,7 @@ class Captcha(Plugin): result = self.task.result if not self.pyload.debug: - self.remove(tmp_img.name, trash=False) + self.remove(img_f.name, trash=False) # self.log_info(_("Captcha result: ") + result) #@TODO: Remove from here? diff --git a/module/plugins/internal/OCR.py b/module/plugins/internal/OCR.py index 8d080e436..217305459 100644 --- a/module/plugins/internal/OCR.py +++ b/module/plugins/internal/OCR.py @@ -40,8 +40,8 @@ class OCR(Plugin): def load_image(self, image): - self.image = Image.open(image) - self.pixels = self.image.load() + self.img = Image.open(image) + self.pixels = self.img.load() self.result_captcha = "" @@ -53,7 +53,7 @@ class OCR(Plugin): def threshold(self, value): - self.image = self.image.point(lambda a: a * value + 10) + self.img = self.img.point(lambda a: a * value + 10) def call_cmd(self, command, *args, **kwargs): @@ -90,7 +90,7 @@ class OCR(Plugin): return self.log_debug("Saving tiff...") - self.image.save(tmpTif.name, 'TIFF') + self.img.save(tmpTif.name, 'TIFF') if os.name is "nt": command = os.path.join(pypath, "tesseract", "tesseract.exe") @@ -138,20 +138,20 @@ class OCR(Plugin): self.remove(tmpSub.name, trash=False) - def recognize(self, name): + def recognize(self, image): raise NotImplementedError def to_greyscale(self): - if self.image.mode != 'L': - self.image = self.image.convert('L') + if self.img.mode != 'L': + self.img = self.img.convert('L') - self.pixels = self.image.load() + self.pixels = self.img.load() def eval_black_white(self, limit): - self.pixels = self.image.load() - w, h = self.image.size + self.pixels = self.img.load() + w, h = self.img.size for x in xrange(w): for y in xrange(h): if self.pixels[x, y] > limit: @@ -163,7 +163,7 @@ class OCR(Plugin): def clean(self, allowed): pixels = self.pixels - w, h = self.image.size + w, h = self.img.size for x in xrange(w): for y in xrange(h): @@ -218,7 +218,7 @@ class OCR(Plugin): """ Rotate by checking each angle and guess most suitable """ - w, h = self.image.size + w, h = self.img.size pixels = self.pixels for x in xrange(w): @@ -231,11 +231,11 @@ class OCR(Plugin): for angle in xrange(-45, 45): - tmpimage = self.image.rotate(angle) + tmpimage = self.img.rotate(angle) pixels = tmpimage.load() - w, h = self.image.size + w, h = self.img.size for x in xrange(w): for y in xrange(h): @@ -275,8 +275,8 @@ class OCR(Plugin): hkey = key hvalue = value - self.image = self.image.rotate(hkey) - pixels = self.image.load() + self.img = self.img.rotate(hkey) + pixels = self.img.load() for x in xrange(w): for y in xrange(h): @@ -290,7 +290,7 @@ class OCR(Plugin): def split_captcha_letters(self): - captcha = self.image + captcha = self.img started = False letters = [] width, height = captcha.size |