summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/captcha/LinksaveIn.py24
-rw-r--r--module/plugins/captcha/ShareonlineBiz.py6
-rw-r--r--module/plugins/internal/Captcha.py18
-rw-r--r--module/plugins/internal/OCR.py34
4 files changed, 41 insertions, 41 deletions
diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py
index 27d1898bb..34e32a208 100644
--- a/module/plugins/captcha/LinksaveIn.py
+++ b/module/plugins/captcha/LinksaveIn.py
@@ -50,15 +50,15 @@ class LinksaveIn(OCR):
npix[x, y] = lut[pix[x, y]]
frame_nr += 1
new.save(self.data_dir+"unblacked.png")
- self.image = new.copy()
- self.pixels = self.image.load()
+ self.img = new.copy()
+ self.pixels = self.img.load()
self.result_captcha = ""
def get_bg(self):
stat = {}
cstat = {}
- img = self.image.convert("P")
+ img = self.img.convert("P")
for bgpath in glob.glob(self.data_dir+"bg/*.gif"):
stat[bgpath] = 0
bg = Image.open(bgpath)
@@ -96,7 +96,7 @@ class LinksaveIn(OCR):
def substract_bg(self, bgpath):
bg = Image.open(bgpath)
- img = self.image.convert("P")
+ img = self.img.convert("P")
bglut = bg.resize((256, 1))
bglut.putdata(xrange(256))
@@ -108,7 +108,7 @@ class LinksaveIn(OCR):
bgpix = bg.load()
pix = img.load()
- orgpix = self.image.load()
+ orgpix = self.img.load()
for x in xrange(bg.size[0]):
for y in xrange(bg.size[1]):
rgb_bg = bglut[bgpix[x, y]]
@@ -120,7 +120,7 @@ class LinksaveIn(OCR):
def eval_black_white(self):
new = Image.new("RGB", (140, 75))
pix = new.load()
- orgpix = self.image.load()
+ orgpix = self.img.load()
thresh = 4
for x in xrange(new.size[0]):
for y in xrange(new.size[1]):
@@ -135,8 +135,8 @@ class LinksaveIn(OCR):
pix[x, y] = (0, 0, 0)
if b > max(r, g)+thresh:
pix[x, y] = (0, 0, 0)
- self.image = new
- self.pixels = self.image.load()
+ self.img = new
+ self.pixels = self.img.load()
def recognize(self, image):
@@ -145,15 +145,15 @@ class LinksaveIn(OCR):
self.substract_bg(bg)
self.eval_black_white()
self.to_greyscale()
- self.image.save(self.data_dir+"cleaned_pass1.png")
+ self.img.save(self.data_dir+"cleaned_pass1.png")
self.clean(4)
self.clean(4)
- self.image.save(self.data_dir+"cleaned_pass2.png")
+ self.img.save(self.data_dir+"cleaned_pass2.png")
letters = self.split_captcha_letters()
final = ""
for n, letter in enumerate(letters):
- self.image = letter
- self.image.save(ocr.data_dir+"letter%d.png" % n)
+ self.img = letter
+ self.img.save(ocr.data_dir+"letter%d.png" % n)
self.run_tesser(True, True, False, False)
final += self.result_captcha
diff --git a/module/plugins/captcha/ShareonlineBiz.py b/module/plugins/captcha/ShareonlineBiz.py
index 3e04bdcad..126d022ee 100644
--- a/module/plugins/captcha/ShareonlineBiz.py
+++ b/module/plugins/captcha/ShareonlineBiz.py
@@ -18,8 +18,8 @@ class ShareonlineBiz(OCR):
def recognize(self, image):
self.load_image(image)
self.to_greyscale()
- self.image = self.image.resize((160, 50))
- self.pixels = self.image.load()
+ self.img = self.img.resize((160, 50))
+ self.pixels = self.img.load()
self.threshold(1.85)
# self.eval_black_white(240)
# self.derotate_by_average()
@@ -28,7 +28,7 @@ class ShareonlineBiz(OCR):
final = ""
for letter in letters:
- self.image = letter
+ self.img = letter
self.run_tesser(True, True, False, False)
final += self.result_captcha
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