日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python实现截图范围框跟随_教你用Python实现截图和文字识别,就是这么简单

發布時間:2023/12/10 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python实现截图范围框跟随_教你用Python实现截图和文字识别,就是这么简单 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

@Author: By Runsen

keyboard是一個監控鍵盤輸入的庫

安裝:pip install keyborad

import keyboardimport timefrom PIL import ImageGrabdef screen(): print('開始截圖') # 使用微信的截圖熱鍵 keyboard.wait(hotkey='alt+a') # 保存 keyboard.wait(hotkey='enter') # 圖片保存需要時間 time.sleep(0.5) # 讀取剪切板的圖片 image = ImageGrab.grabclipboard() # 保存圖片 image.save('screen.jpg') print('圖片保存完成')screen()

當在鍵盤敲ctrl+a來得到圖片

截取的圖片

下面我使用百度云來進行識別

為什么用百度云,因為百度的技術,阿里的運營,騰訊的產品

技術當然選百度云

要安裝百度的接口

官方的教程

https://cloud.baidu.com/doc/OCR/OCR-Python-SDK.html#.E6.8E.A5.E5.8F.A3.E8.AF.B4.E6.98.8E

from aip import AipOcr""" 你的 APPID AK SK """APP_ID = ''API_KEY = ''SECRET_KEY = ''client = AipOcr(APP_ID, API_KEY, SECRET_KEY)"""讀取圖片"""def get_file_content(filepath): with open(filepath,'rb') as f: return f.read()def get_img_content(img): image_content='' content = client.basicAccurate(image=img) # print(content) for words in content['words_result']: print(words) # 字典 image_content += words['words'] print(image_content)

下面,封裝全代碼

# -*- coding:utf-8 -*-# time :2019/5/2 23:02# author: 毛利import keyboardimport timefrom PIL import ImageGrabdef screen(): print('開始截圖') # 使用微信的截圖熱鍵 keyboard.wait(hotkey='alt+a') # 保存 keyboard.wait(hotkey='enter') # 圖片保存需要時間 time.sleep(0.5) # 讀取剪切板的圖片 image = ImageGrab.grabclipboard() # 保存圖片 image.save('screen.jpg')# 使用百度云中的文字識別from aip import AipOcr""" 你的 APPID AK SK """APP_ID = '' #你的賬號的idAPI_KEY = ''SECRET_KEY = ''client = AipOcr(APP_ID, API_KEY, SECRET_KEY)"""讀取圖片"""def get_file_content(filepath): with open(filepath,'rb') as f: return f.read()def get_img_content(img): image_content='' content = client.basicAccurate(image=img) # print(content) for words in content['words_result']: # print(words) # 字典 image_content += words['words'] print(image_content)if __name__ == '__main__': screen() img = get_file_content('screen.jpg') get_img_content(img)

使用:

就是這么簡單,不知道你學會了沒有。

總結

以上是生活随笔為你收集整理的python实现截图范围框跟随_教你用Python实现截图和文字识别,就是这么简单的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。