summaryrefslogtreecommitdiffstats
path: root/captcha
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-17 23:18:27 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-17 23:18:27 +0200
commitc5234a8b3d223f9860de161894ae8a4623e1ae05 (patch)
treed98aa17e3c0e738940e8957b390cd32e4b0955ee /captcha
parentadded a error message if gui cant connect to server (diff)
downloadpyload-c5234a8b3d223f9860de161894ae8a4623e1ae05.tar.xz
plugins can import captcha method, see #6
Diffstat (limited to 'captcha')
-rw-r--r--captcha/GigasizeCom.py15
-rw-r--r--captcha/NetloadIn.py15
-rw-r--r--captcha/captcha.py14
-rw-r--r--captcha/gigasize-com.py14
4 files changed, 33 insertions, 25 deletions
diff --git a/captcha/GigasizeCom.py b/captcha/GigasizeCom.py
new file mode 100644
index 000000000..136092181
--- /dev/null
+++ b/captcha/GigasizeCom.py
@@ -0,0 +1,15 @@
+from captcha import OCR
+
+class GigasizeCom(OCR):
+ def __init__(self):
+ OCR.__init__(self)
+
+ def get_captcha(self, image):
+ self.load_image(image)
+ self.threshold(2.8)
+ self.run_gocr()
+ return self.result_captcha
+
+if __name__ == '__main__':
+ ocr = GigasizeCom()
+ print ocr.get_captcha('gigasize-com/7.jpg')
diff --git a/captcha/NetloadIn.py b/captcha/NetloadIn.py
index a8fc38757..94103f78b 100644
--- a/captcha/NetloadIn.py
+++ b/captcha/NetloadIn.py
@@ -1,10 +1,11 @@
-from captcha import Ocr
+from captcha import OCR
-class NetloadIn(Ocr):
- def __init__(self, image):
- Ocr.__init__(self, image)
+class NetloadIn(OCR):
+ def __init__(self):
+ OCR.__init__(self)
- def get_captcha(self):
+ def get_captcha(self, image):
+ self.load_image(image)
self.to_greyscale()
self.clean(3)
self.clean(3)
@@ -12,5 +13,5 @@ class NetloadIn(Ocr):
return self.result_captcha
if __name__ == '__main__':
- ocr = NetloadIn('captchas/netload/captcha.php10.png')
- print ocr.get_captcha()
+ ocr = NetloadIn()
+ print ocr.get_captcha('captchas/netload/captcha.php10.png')
diff --git a/captcha/captcha.py b/captcha/captcha.py
index 361893fa3..de3e61cf0 100644
--- a/captcha/captcha.py
+++ b/captcha/captcha.py
@@ -2,13 +2,19 @@ import Image
import ImageOps
import subprocess
-class Ocr(object):
- def __init__(self, image):
+class OCR(object):
+ def __init__(self):
+ pass
+
+ def load_image(self, image):
self.image = Image.open(image)
self.pixels = self.image.load()
self.image_name = 'captcha_clean.png'
self.result_captcha = ''
+ def unload():
+ """delete all tmp images"""
+ pass
def threshold(self, value):
self.image = self.image.point(lambda a: a * value +10)
@@ -27,7 +33,7 @@ class Ocr(object):
self.result_captcha = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0].replace('\n','')
def get_captcha(self):
- pass
+ raise NotImplementedError
def to_greyscale(self):
if self.image.mode != 'L':
@@ -74,5 +80,5 @@ class Ocr(object):
if __name__ == '__main__':
- ocr = Ocr('gigasize-com/7.jpg')
+ ocr = OCR('gigasize-com/7.jpg')
print ocr.get_captcha()
diff --git a/captcha/gigasize-com.py b/captcha/gigasize-com.py
deleted file mode 100644
index b48e20da4..000000000
--- a/captcha/gigasize-com.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from captcha import Ocr
-
-class Gigasize(Ocr):
- def __init__(self, image):
- Ocr.__init__(self, image)
-
- def get_captcha(self):
- self.threshold(2.8)
- self.run_gocr()
- return self.result_captcha
-
-if __name__ == '__main__':
- ocr = Gigasize('gigasize-com/7.jpg')
- print ocr.get_captcha()