diff options
author | André Glüpker <git@wgmd.de> | 2016-03-23 09:16:07 +0100 |
---|---|---|
committer | André Glüpker <git@wgmd.de> | 2016-03-23 09:16:07 +0100 |
commit | c59a23e3991793edf2ed6e3159cbaeb70ecb6e22 (patch) | |
tree | 20dd42184d6e347bdcc76543a656f4e9e1033532 | |
parent | 939d83907998bc635f5e4aa8f44eb827f0e83fa5 (diff) | |
download | 9kwpyqt-c59a23e3991793edf2ed6e3159cbaeb70ecb6e22.tar.gz 9kwpyqt-c59a23e3991793edf2ed6e3159cbaeb70ecb6e22.tar.bz2 9kwpyqt-c59a23e3991793edf2ed6e3159cbaeb70ecb6e22.zip |
Only detect captchatype once
-rwxr-xr-x | 9kwpyqt.py | 41 |
1 files changed, 25 insertions, 16 deletions
@@ -45,6 +45,7 @@ class ExtendedQLabel(QLabel): image = False # QPixmap() imageR = False # QPixmap() resized imageB = False # QImage() + captchaType = False # int / detected captcha type def __init(self, parent): QLabel.__init(self, parent) @@ -54,12 +55,14 @@ class ExtendedQLabel(QLabel): self.imageR = self.image.scaled(self.size(), Qt.KeepAspectRatio) self.imageB = False + self.captchaType = False self.setPixmap(self.imageR) def removeImage(self, image): self.image = False self.imageR = False self.imageB = False + self.captchaType = False QLabel.setPixmap(QPixmap()) def resizeEvent(self, evt=None): @@ -83,29 +86,35 @@ class ExtendedQLabel(QLabel): x = ev.pos().x() - self.size().width() / 2 + imgx/2 y = ev.pos().y() - self.size().height() / 2 + imgy/2 + if not self.captchaType: + # Which type of captcha is this image? + if PixelInfo(self.imageB.pixel(90, 45)).isExactly(0,0,0) and \ + PixelInfo(self.imageB.pixel( 5, 30)).isHigher(220,220,220) and \ + PixelInfo(self.imageB.pixel(71, 30)).isHigher(220,220,220) and \ + PixelInfo(self.imageB.pixel(40, 5)).isHigher(220,220,220) and \ + PixelInfo(self.imageB.pixel(40, 59)).isHigher(220,220,220): + self.captchaType = 1 + elif PixelInfo(self.imageB.pixel( 16, 47)).isLower(20,20,20) and \ + PixelInfo(self.imageB.pixel(144, 47)).isLower(20,20,20) and \ + PixelInfo(self.imageB.pixel(269, 47)).isLower(20,20,20) and \ + PixelInfo(self.imageB.pixel( 16, 172)).isLower(20,20,20) and \ + PixelInfo(self.imageB.pixel(144, 172)).isLower(20,20,20) and \ + PixelInfo(self.imageB.pixel(269, 172)).isLower(20,20,20) and \ + PixelInfo(self.imageB.pixel( 16, 298)).isLower(20,20,20) and \ + PixelInfo(self.imageB.pixel(144, 298)).isLower(20,20,20) and \ + PixelInfo(self.imageB.pixel(269, 298)).isLower(20,20,20): + self.captchaType = 2 + else: + self.captchaType = -1 - # Which type of captcha is this image? - if PixelInfo(self.imageB.pixel(90, 45)).isExactly(0,0,0) and \ - PixelInfo(self.imageB.pixel( 5, 30)).isHigher(220,220,220) and \ - PixelInfo(self.imageB.pixel(71, 30)).isHigher(220,220,220) and \ - PixelInfo(self.imageB.pixel(40, 5)).isHigher(220,220,220) and \ - PixelInfo(self.imageB.pixel(40, 59)).isHigher(220,220,220): + if self.captchaType == 1: # check if on pixmap (upper 17.5% = infopanel) if x > imgx or y > imgy or x < 0 or y < 0.175*imgy: return xpiece = x // (imgx / 3) + 1 ypiece = (y-0.175*imgy) // (imgy*0.825 / 3) self.clicked.emit(3*ypiece+xpiece, ",") - - elif PixelInfo(self.imageB.pixel( 16, 47)).isLower(20,20,20) and \ - PixelInfo(self.imageB.pixel(144, 47)).isLower(20,20,20) and \ - PixelInfo(self.imageB.pixel(269, 47)).isLower(20,20,20) and \ - PixelInfo(self.imageB.pixel( 16, 172)).isLower(20,20,20) and \ - PixelInfo(self.imageB.pixel(144, 172)).isLower(20,20,20) and \ - PixelInfo(self.imageB.pixel(269, 172)).isLower(20,20,20) and \ - PixelInfo(self.imageB.pixel( 16, 298)).isLower(20,20,20) and \ - PixelInfo(self.imageB.pixel(144, 298)).isLower(20,20,20) and \ - PixelInfo(self.imageB.pixel(269, 298)).isLower(20,20,20): + elif self.captchaType == 2: # check if on pixmap (upper 7% = infopanel) if x > imgx or y > imgy or x < 0 or y < 0.0735*imgy: return |