Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 1 Fork 0

CHJ-Self/PythonRobotization

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
Text.py 4.88 KB
Copy Edit Raw Blame History
chenhaijian authored 2024年06月17日 10:44 +08:00 . 第一次提交
#! /usr/bin env python3
# -*- coding:utf-8 -*-
# 文字识别
from Screen import Screen
import base64
import requests
import easyocr
from paddleocr import PaddleOCR
class Text():
def __init__(self, _log=None):
self.log = _log
self.screen = Screen()
self.easyocr = easyocr.Reader(['ch_sim','en'])
self.paddleOcr = PaddleOCR(use_angle_cls=True, lang="ch")
self.apiKey = ''# 需要填写百度智能云的API Key
self.secretKey = ''# 需要填写百度智能云的Secret Key
self.type_general_basic = 0
self.type_general = 1
self.type_accurate_basic = 2
self.type_accurate = 3
self.type_webimage = 4
self.type_webimage_loc = 5
self.type_table = 6
self.type_handwriting = 7
self.type_numbers = 8
self.printLog('Text init')
def bind(self, hwnd):
self.hwnd = hwnd
self.screen.bind(hwnd)
def printLog(self, content):
if self.log != None:
self.log.printLog(content)
else:
print(content)
# 获取百度智能云的access token
def getAccessToken(self):
# 获取token值
# client_id 为官网获取的API_KEY, client_secret 为官网获取的SECRET_KEY
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=' + \
'client_credentials&client_id=' + self.apiKey + \
'&client_secret=' + self.secretKey
response = requests.get(host)
access_token = response.json()['access_token']
return access_token
# 联网识字,通过百度api识字
# @border 识别区域
# @type 识别方式,默认是2(通用文字识别(标准含位置版))
def getWordsByBaiDu(self, border=None, type=2):
assessToken = self.getAccessToken()
request_url = None
if type == self.type_general_basic:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"# 通用文字识别(标准版)1000次/月,QPS/并发:2qps
elif type == self.type_general:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general"# 通用文字识别(标准含位置版)1000次/月,QPS/并发:2qps
elif type == self.type_accurate_basic:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"# 通用文字识别(高精度版)1000次/月,QPS/并发:2qps
elif type == self.type_accurate:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate"# 通用文字识别(高精度含位置版)500次/月,QPS/并发:2qps
elif type == self.type_webimage:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/webimage"# 网络图片文字识别 1000次/月,QPS/并发:2qps
elif type == self.type_webimage_loc:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/webimage_loc"# 网络图片文字识别(含位置版)总量500次,QPS/并发:2qps
elif type == self.type_table:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/table"# 表格文字识别V2 500次/月,QPS/并发:2qps
elif type == self.type_handwriting:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/handwriting"# 手写文字识别 500次/月,QPS/并发:2qps
elif type == self.type_numbers:
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/numbers"# 数字识别 1000次/月,QPS/并发:2qps
#
qimg = self.screen.captureScreen('getWords.png', border)
try:
f = open('getWords.png', 'rb')
imgBytes = base64.b64encode(f.read())
params = {"image":imgBytes}
request_url = request_url + "?access_token=" + assessToken
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
self.printLog(str(response.json()["words_result"]))
except Exception as e:
self.printLog('网络识图出错了')
self.printLog(str(e))
return []
else:
return response.json()["words_result"]
def getWordsByEasyOcr(self, border=None):
qimg = self.screen.captureScreen(None, border)
res = self.easyocr.readtext(self.screen.qimageToNDArray(qimg))
self.printLog('getWordsByEasyOcr words: '+str(res))
return res
def getWordsByPaddleocr(self, border=None):
qimg = self.screen.captureScreen(None, border)
res = self.paddleOcr.ocr(self.screen.qimageToNDArray(qimg))
easyOcrRes = [] # 转换成EasyOcr的返回格式
for i in range(len(res[0])):
pos = res[0][i][0]
text = res[0][i][1][0]
similar = res[0][i][1][1]
easyOcrRes.append((pos, text, similar))
self.printLog('getWordsByPaddleocr words: '+str(res))
return easyOcrRes
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Python自动化框架
Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chj-self/PythonRobotization.git
git@gitee.com:chj-self/PythonRobotization.git
chj-self
PythonRobotization
PythonRobotization
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /