本帖最后由 panwanpeng 于 2019-6-22 11:47 编辑
链接:https://pan.baidu.com/s/1Hv_MXJt-sDB0k0wJ0x0zdQ
提取码:mjgj
复制这段内容后打开百度网盘手机App,操作更方便哦
[Python] 纯文本查看 复制代码 from aip import AipOcr
APP_ID = '16462688'
API_KEY = 'uiSymXDuajlHu1zzDhzOxnrb'
SECRET_KEY = '0SnZbzYzeKT7fwNBSIbdl0BGrDLzNLGW'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
class get_text():
""" 读取图片 """
@staticmethod
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
""" 调用通用文字识别(高精度版) """
# client.basicAccurate(image)
@staticmethod
def gettext(filePath):
#print(filePath)
image = get_text.get_file_content(filePath)
""" 如果有可选参数 """
options = {}
options["detect_direction"] = "true"
options["probability"] = "true"
""" 带参数调用通用文字识别(高精度版) """
response = client.basicAccurate(image, options)
#print(response)
#data = response['words_result'][0]['words']
content = []
for info in response['words_result']:
#print(info['words'])
content.append(info['words'])
return content
if __name__ == '__main__':
get_text.gettext('D:/PycharmProjects/baiduaipOcr/example.jpg')
[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'jiemian.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(969, 597)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(440, 500, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(440, 540, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setEnabled(False)
self.lineEdit.setGeometry(QtCore.QRect(110, 440, 741, 41))
self.lineEdit.setObjectName("lineEdit")
self.textEdit = QtWidgets.QTextEdit(Form)
self.textEdit.setGeometry(QtCore.QRect(10, 0, 951, 421))
font = QtGui.QFont()
font.setFamily("Agency FB")
self.textEdit.setFont(font)
self.textEdit.setObjectName("textEdit")
self.label = QtWidgets.QLabel(Form)
self.label.setEnabled(False)
self.label.setGeometry(QtCore.QRect(250, 500, 181, 61))
font = QtGui.QFont()
font.setPointSize(10)
font.setStyleStrategy(QtGui.QFont.PreferDefault)
self.label.setFont(font)
self.label.setWordWrap(True)
self.label.setObjectName("label")
self.retranslateUi(Form)
self.pushButton.clicked.connect(Form.open_img)
self.pushButton_2.clicked.connect(Form.shibie)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "盘州市第一中学文字识别软件(beta1.0)"))
self.pushButton.setText(_translate("Form", "打开图片"))
self.pushButton_2.setText(_translate("Form", "开始识别"))
self.label.setText(_translate("Form", "软件利用百度AI高级识别助手,全世界上每天只能识别50次,非重要内容请别乱识别,谢谢!"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
[Python] 纯文本查看 复制代码 from PyQt5.Qt import QWidget,QApplication
from PyQt5.QtWidgets import QFileDialog
from jiemian import Ui_Form
from baiduaip import get_text
import sys
class MF(QWidget,Ui_Form):
def __init__(self,parent = None,*args,**kwargs):
super().__init__(parent,*args,**kwargs)
self.setupUi(self)
def open_img(self):
print('打开图片')
openfile_name = QFileDialog.getOpenFileName(self, '选择文件', '', 'Image files(*.jpg , *.png, *.bmp)')
print(openfile_name[0])
self.lineEdit.setText('您打开的图片是:'+openfile_name[0])
self.imgagesurl = openfile_name[0]
def shibie(self):
print('识别')
content = get_text.gettext(self.imgagesurl)
data = '\n'.join(content)
self.textEdit.setText(data)
clipboard = QApplication.clipboard()
clipboard.setText(data)
if __name__ == '__main__':
app = QApplication(sys.argv)
win = MF()
win.show()
sys.exit(app.exec_())
|