From c59a23e3991793edf2ed6e3159cbaeb70ecb6e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Wed, 23 Mar 2016 09:16:07 +0100 Subject: Only detect captchatype once --- 9kwpyqt.py | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/9kwpyqt.py b/9kwpyqt.py index 29e9d28..f6e1635 100755 --- a/9kwpyqt.py +++ b/9kwpyqt.py @@ -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 -- cgit v1.2.3