def GetImage(self):
        # 清空圖片和文字輸入框
        for i, obj in enumerate(self.inputBoxs):
            obj.clear()
        for i,obj in enumerate(self.pixBoxs):
            obj.clear()

        # 取得驗證碼stream
        s = requests.Session()
        req = s.get('http://railway.hinet.net/ImageOut.jsp')

        im = pilIm.open(StringIO(req.content)).convert('RGB')
        io = StringIO()
        im.save(io, format='png')
        qimg = QtGui.QImage.fromData(io.getvalue())
        self.captchaPic.qimage = qimg
        # 原始驗證碼
        self.captchaPic.setPixmap(QtGui.QPixmap(qimg))

        Img = Image(req.content)
        # 取得處理完後的圖片
        self.imgarr = Img.StartProcess()
        # 用來儲存轉成QPixmap的圖片 用來存檔
        self.PixMaparr = []
        for index,img in enumerate(self.imgarr):
            try:
                height, width,channel = img.shape
                bytes = 3*width
                qimg = QtGui.QImage(img.data, width, height,bytes, QtGui.QImage.Format_RGB888)
                pixmap = QtGui.QPixmap(qimg)
                self.pixBoxs[index].qimage = qimg
                self.pixBoxs[index].setPixmap(pixmap)
                self.PixMaparr.append(pixmap)
            except:
                pass
Example #2
0
    def SecondRequest(self, s):

        if not self.IsGoSuccess or not self.IsBackSuccess:

            # =====================
            # 填寫驗證碼頁面
            # =====================
            # 取得驗證碼圖片
            req = s.get('http://railway.hinet.net/ImageOut.jsp')
            req.raise_for_status()
            im = Image.open(StringIO(req.content)).convert('RGB')
            io = StringIO()
            im.save(io, format='png')
            qimg = QtGui.QImage.fromData(io.getvalue())
            self.mainWindow.captchaPic.setPixmap(QtGui.QPixmap(qimg))
            self.mainWindow.logMsg('\n解析驗證碼中...')
            QtGui.QApplication.processEvents()
            x = CVImg(req.content)
            imgs = x.StartProcess()  # 取得處理完後的驗證碼圖片陣列

            # 將圖片陣列轉成keras可處理格式
            data = np.empty((len(imgs), 50, 50, 3), dtype="float32")
            for index, img in enumerate(imgs):
                arr = np.asarray(
                    img, dtype="float32") / 255.0  # 將黑白圖片轉成1,0陣列 原本是0,255
                data[index, :, :, :] = arr
            lock.acquire()
            classes = self.model.predict_classes(data)
            lock.release()
            result = []
            letters = list('0123456789')
            for c in classes:
                result.append(letters[c])
            answer = ''.join(result).upper()
            self.mainWindow.logMsg('驗證碼解答: ' + answer + '\n')

            # num, ok = QtGui.QInputDialog.getText(self.mainWindow, u"驗證碼", u"請輸入驗證碼")

            if len(answer) >= 5:
                self.ThirdRequest(s, answer)
            else:
                self.SecondRequest(s)
Example #3
0
    def GetImage(self):
        # 取得驗證碼stream
        s = requests.Session()
        req = s.get('http://railway.hinet.net/ImageOut.jsp')

        im = pilIm.open(StringIO(req.content)).convert('RGB')
        io = StringIO()
        im.save(io, format='png')
        qimg = QtGui.QImage.fromData(io.getvalue())
        self.captchaPic.setPixmap(QtGui.QPixmap(qimg))

        Img = Image(req.content)
        # 取得處理完後的圖片
        imgarr = Img.StartProcess()

        for index,img in enumerate(imgarr):
            try:
                height, width,channel = img.shape
                bytes = 3*width
                self.pixBoxs[index].setPixmap(QtGui.QPixmap(QtGui.QImage(img.data, width, height,bytes, QtGui.QImage.Format_RGB888)))
            except:
                pass