python做图像识别该学什么_Python实现图片识别加翻译【高薪必学】
Python使用百度AI接口實現圖片識別加翻譯
另外很多人在學習Python的過程中,往往因為沒有好的教程或者沒人指導從而導致自己容易放棄,為此我建了個Python交流.裙 :一久武其而而流一思(數字的諧音)轉換下可以找到了,里面有最新Python教程項目可拿,不懂的問題多跟里面的人交流,都會解決哦!接下來進入主題
python誕生30周年
# encoding:utf-8
import requests
import base64
from PIL import Image
import pytesseract
# 這里需要安裝一下 Tesseract-OCR
# 鏈接:https://pan.baidu.com/s/1D2eODet7x9xshBVi6ZUZ_Q
# 提取碼:qfef
# 安裝好之后別忘了把Tesseract-OCR路徑添加到環境變量中
import json
import requests
import keyboard #監聽按鍵庫
from PIL import ImageGrab #圖像處理庫
import time
from aip import AipOcr #pip install baidu_aip
# print("開始截圖")
# 1. 截取圖片
keyboard.wait(hotkey='ctrl+alt+a')
# print("鍵盤按下了'ctrl+alt+a'")
keyboard.wait('enter')
# print("鍵盤按下了'enter'")
# 模擬延遲,來解決grabclipboard函數的緩存問題(grabclipboard函數操作太快,它就會讀取上一次的內容)
time.sleep(0.1)
# 2. 保存圖片到電腦上
image = ImageGrab.grabclipboard()
image.save('screen.png')
#*************************************************************************************
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
# 二進制方式打開圖片文件
f = open('screen.png', 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
access_token = "你自己的access_token,百度AI里面有教程,我把網址放下面了"
# https://ai.baidu.com/ai-doc/OCR/vk3h7y58v
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
print("文字識別:")
if response:
locList = response.json()['words_result']
for i in locList:
print(i['words'])
print("\n翻譯:")
if response:
locList = response.json()['words_result']
for i in locList:
text = i['words']
##================================================================================##
key = {
'type': "AUTO",
'i': word,
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"ue": "UTF-8",
"action": "FY_BY_CLICKBUTTON",
"typoResult": "true"
}
# key 這個字典為發送給有道詞典服務器的內容
response = requests.post(url, data=key)
# 判斷服務器是否相應成功
if response.status_code == 200:
# 然后相應的結果
return response.text
else:
print("有道詞典調用失敗")
# 失敗就返回空
return None
def get_reuslt(repsonse):
# 通過 json.loads 把返回的結果加載成 json 格式
result = json.loads(repsonse)
print("%s" % result['translateResult'][0][0]['tgt'])
def main():
list_trans = translate(text)
get_reuslt(list_trans)
if __name__ == '__main__':
main()
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
保存的圖片如下:
打印結果如下:
寫完了,看明白了嗎? 另外很多人在學習Python的過程中,往往因為沒有好的教程或者沒人指導從而導致自己容易放棄,為此我建了個Python交流.裙 :一久武其而而流一思(數字的諧音)轉換下可以找到了,里面有最新Python教程項目可拿,不懂的問題多跟里面的人交流,都會解決哦!
————————————————
版權聲明:本文的文字及圖片來源于網絡加上自己的想法,僅供學習、交流使用,不具有任何商業用途,版權歸原作者所有,如有問題請及時聯系我們以作處理。
總結
以上是生活随笔為你收集整理的python做图像识别该学什么_Python实现图片识别加翻译【高薪必学】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 泛型约束(转)
- 下一篇: Tomcat非正常退出导致无法再次启动