def readImageQR(self, image): buffer = QBuffer() buffer.open(QBuffer.ReadWrite) image.save(buffer, "BMP") pillow_image = Image.open(io.BytesIO(buffer.data())) barcodes = pyzbar.decode(pillow_image, symbols=[pyzbar.ZBarSymbol.QRCODE]) if barcodes: self.qr_data_available.emit(barcodes[0].data.decode('utf-8')) return True else: return False
def qpixmap_to_np(im: QPixmap) -> np.ndarray: # from PIL.ImageQt.fromqimage buffer = QBuffer() buffer.open(QIODevice.ReadWrite) if im.hasAlphaChannel(): im.save(buffer, "png") else: im.save(buffer, "ppm") npbuf = np.frombuffer(buffer.data(), "<B") buffer.close() out = cv2.imdecode(npbuf, cv2.IMREAD_UNCHANGED) if out.shape[2] == 3: # Add alpha channel out = np.pad(out, ((0, 0), (0, 0), (0, 1)), constant_values=0xFF) return out
def prnt(self, screenShot: QPixmap): buffer = QBuffer() buffer.open(QBuffer.ReadWrite) screenShot.save(buffer, 'png') data = buffer.data().data() res = self.client.basicGeneral(data) if 'words_result_num' in res.keys(): print('[ INFO ] 识别成功') text = '' result = res['words_result'] d = { '单选题': self.ui.rad_1, '多选题': self.ui.rad_2, '填空题': self.ui.rad_3, '问答题': self.ui.rad_4, '判断题': self.ui.rad_14, '分析题': self.ui.rad_5, '解答题': self.ui.rad_5, '计算题': self.ui.rad_5, '证明题': self.ui.rad_5, } for words in result: ques_type = False for k in d.keys(): if k in words['words']: ques_type = True print('[ INFO ] 题目类型:', k) d[k].setChecked(True) d[k].repaint() break if not ques_type: text += words['words'] text = text.replace('(', '(').replace(')', ')').replace( '?', '?').replace(',', ',') print('[ INFO ] 题目:', text) self.ui.questLineEdit.setText(text) self.ui.questLineEdit.repaint() self.ui.searchButton.click() else: print('[ INFO ] 识别失败')
def _create_tooltip(self, anchor: str) -> str: path = Path(anchor) suffix = path.suffix if suffix in ('.txt', '.py', '.html', '.xml'): data = self._read_file(path) if data: file_buf = data.decode('utf-8') if suffix == '.html': return file_buf else: return f'<pre>{file_buf}</pre>' elif suffix in ('.png', '.jpg'): image = self._read_image(path) if image: buffer = QBuffer() buffer.open(QIODevice.WriteOnly) pixmap = QPixmap.fromImage(image) pixmap.save(buffer, "PNG") data = bytes(buffer.data().toBase64()).decode() return f'<img src="data:image/png;base64,{data}">' return f'<p>{anchor}</p>'
def save_library(self): global pc_lib global pc_ui directory, ext = QtWidgets.QFileDialog.getSaveFileName( self, 'Save Files', os.path.dirname(__file__), "Pose Library(*.poslib)", '*.poslib') if directory is not '': for entry in pc_lib: # Convert Pixmap to Byte Array byte_array = QByteArray() buffer = QBuffer(byte_array) buffer.open(QIODevice.WriteOnly) entry["preview"].save(buffer, 'PNG') encoded = buffer.data().toBase64() entry["preview"] = encoded.data().decode("utf8") # Write data to file f = open(directory, "w") f.write(json.dumps(pc_lib)) f.close() # Reload the pose libary load_library(directory)
def get_raw(self): ''' Get the scene information. (can be be save in .pii) Return ------ out: (dict) Dictionary of scene date to be save in .pii file. ''' image_data = str() pixmap = self._backgroundNode.pixmap() # Extract Image Data if not pixmap.isNull(): buffer = QBuffer() buffer.open(QIODevice.WriteOnly) pixmap.save(buffer, "PNG") # Image Data image_data = bytes(buffer.data().toBase64()).decode('ascii') nodeList = [] for each in self._scene.items(): if type(each) == PickNode: textColor = each.defaultTextColor() bgColor = each.Background item = { PIIPick.TYPE: PIINode.PICK, PIIPick.TEXT: each.toPlainText(), PIIPick.SIZE: each.font().pointSize(), PIIPick.POSITION: (each.pos().x(), each.pos().y()), PIIPick.COLOR: (textColor.red(), textColor.green(), textColor.blue()), PIIPick.BACKGROUND: (bgColor.red(), bgColor.green(), bgColor.blue()), PIIPick.SELECTION: each.Items, PIIPick.SHAPE: each.Shape } nodeList.append(item) elif type(each) == ButtonNode: textColor = each.defaultTextColor() bgColor = each.Background item = { PIIButton.TYPE: PIINode.BUTTON, PIIButton.TEXT: each.toPlainText(), PIIButton.SIZE: each.font().pointSize(), PIIButton.POSITION: (each.pos().x(), each.pos().y()), PIIButton.COLOR: (textColor.red(), textColor.green(), textColor.blue()), PIIButton.BACKGROUND: (bgColor.red(), bgColor.green(), bgColor.blue()), PIIButton.COMMAND: each.Command, PIIButton.COMMANDTYPE: each.CommandsType } nodeList.append(item) rawData = { PII.VERSION: "1.0.0", PII.BACKGROUND: image_data, PII.NODES: nodeList } return rawData