在做一個資料標注程序中人工需要識別文字,
想了想寫了一個小腳本,
大致程序這樣的,
截圖功能寫了好久也沒寫明白,索性直接呼叫第三方的截圖工具了,在采用qq或者微信截圖時,截圖完成后保存大致保存在剪切板所以直接抽取了剪切板中的檔案,
使用 PIL 中ImageGrab獲取剪切板檔案,并保存在當前目錄
1 image = ImageGrab.grabclipboard() 2 s= 'xxx.png' 3 image.save(s)
呼叫百度圖片文字識別介面,取出輸出的文字資訊,可參考見百度ocr檔案文字識別OCR (baidu.com)
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic" f = open(s, 'rb') img = base64.b64encode(f.read()) params = {"image": img} access_token = 'xxx' request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/x-www-form-urlencoded'} response = requests.post(request_url, data=https://www.cnblogs.com/t-dashuai/p/params, headers=headers) if response: for i in response.json()['words_result']: print(i['words'])
使用tkinter模塊設計一個視窗
# 設定視窗 window = Tk() window.title('qcc_nw0.1') # 設定視窗大小 window.geometry('500x800') # lable標簽 l = Label(window, text='識圖2.0', bg='green', fg='white', font=('Arial', 12), width=30, height=2) l.pack() # 設定文本輸出欄的文本框 E1 = Text(window,width='100',height='100') E1.insert("insert", txt') E1.pack(side=RIGHT) # 定義按鈕 img_txt = Button(window, text='識圖嗎寶貝', font=('Arial', 10), width=15, height=1, command=s) img_txt.pack() window.mainloop()
完成;
看下完成后的效果

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/285749.html
標籤:其他
