日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

一直在寫東西,有時候會遇到這種需求,就是把圖片上的文字拷貝到自己的文章中,所以寫了這個小工具。

百度API OCR小工具

 

配合Snipaste使用天衣無縫,所有的東西都在剪切板里交換,即Snipaste截取的圖片在剪切板里面,OCR直接識別后生成的文字也在剪切板里面,只要在ctrl+v就可以復(fù)制到文章里面了。

百度API OCR小工具

 

Snipaste 截圖的快捷鍵是Ctrl+Q,設(shè)置這個OCR的快捷鍵為Ctrl+shift+O。

百度API OCR小工具

 

通過白嫖百度API的文字識別功能,具體可以參照百度API。

百度API OCR小工具

 

直接上程序

# encoding:utf-8
import requests
import base64
from PIL import Image
from PIL import ImageGrab
import pyperclip
from io import BytesIO
import sys
import win32clipboard as w
import win32con
'''
通用文字識別(高精度版)
'''
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
# 二進制方式打開圖片文件
def get_token():
  # client_id 為官網(wǎng)獲取的AK, client_secret 為官網(wǎng)獲取的SK
  host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=xxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxx'
  response = requests.get(host)
  if response:
  	return response.json()['access_token']
def encode_image_from_clip():
  picture_format = 'png'
  image = ImageGrab.grabclipboard()
  if not isinstance(image, Image.Image):
  # tkinter.messagebox.showinfo("picture2base64", "not a image in clipboard.")
  	print("not a image in clipboard.")
  sys.exit(1)
  img_buffer = BytesIO()
  image.save(img_buffer, format=picture_format, optimize=True, quality=40)
  byte_data = img_buffer.getvalue()
  base64_byte = base64.b64encode(byte_data)
  return base64_byte
def setClipboard(Str):
  w.OpenClipboard()
  w.EmptyClipboard()
  w.SetClipboardData(win32con.CF_UNICODETEXT, Str)
  w.CloseClipboard()
img = encode_image_from_clip()
params = {"image":img}
access_token = get_token()
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)
if response:
	results = response.json()['words_result']
results_display = ''
for result in results:
	results_display = results_display + result['words'] + 'n' 
print(results_display)
setClipboard(results_display)

然后通過pyinstaller 打包成exe就可以了。

分享到:
標簽:OCR
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定