Baidu Cloud Text recognition technical documents:
Https://cloud.baidu.com/doc/OCR/OCR-Python-SDK.html#.E6.96.B0.E5.BB.BAAipOcr
fromAipImportAipocr#Baidu AIP fromPILImportImagegrab#working with clipboard pictures fromPILImportImageImportPILImportKeyboard#Monitor KeyboardImportSYSImportTime,datetimeImportRandomImportWin32clipboard as W#Handling Shear PlatesImportWin32condefscreenshot ():" "Monitor keyboard events and save pictures" " #Monitor Keyboard, enter QQ default shortcut key ifKeyboard.wait (hotkey='Ctrl+alt+a') ==None: whileTrue:time.sleep (3)#waitim = Imagegrab.grabclipboard ()#get the picture in the Clipboard ifIsinstance (Im,pil. Bmpimageplugin.dibimagefile):#if the contents of the Clipboard can be resolved into a picture #file namei = Datetime.datetime.now (). Strftime ('%y%m%d%h%m%s') R= str (Random.randint (100,1000)) #Save PictureIm.save (i+r+'. PNG') #Baidu Cloud Account Settingsapp_id ="'Api_key="'Secret_key="' #Baidu Cloud API ObjectClient =AIPOCR (app_id, Api_key, Secret_key)#Reading PicturesImage = Get_file_content (i+r+'. PNG') #get the text content in a picturedata =client.basicgeneral (image) Words_result= data['Words_result'] Data="" #what you need to save forWordsinchWords_result:data+=words['words'] Print(data) setText (data)#Reading Picturesdefget_file_content (FilePath): With open (FilePath,'RB') as FP:returnFp.read ()#Writing Clipboard contentsdefSetText (astring): W.openclipboard () W.emptyclipboard () W.setclipboardtext (astring) W.closeclipboard () if __name__=="__main__":#For _ in range (sys.maxsize): #修改成在screenShot中用while循环Screenshot ()
Python, using the Baidu API to implement the text in the copy