In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to achieve character recognition in Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Environment and configuration requirements
As a whole, it is implemented in Python, and the third-party libraries that need to be used include aip, PIL, keyboard and pyinstaller. If it is not installed, you can install it in CMD using the pip install Baidu-AIP/pillow/keyboard/pyinstaller instruction.
Baidu interface
Open https://cloud.baidu.com/
If you are not registered, please register first, then log in to the management console, click on the left product services → artificial intelligence → character recognition, click to create an application, enter an application name such as Baidu_OCR, select a purpose such as study office, and finally make a simple application description, you can click to create now.
A list of applications appears, including AppID, API Key, Secret Key, and so on, which will be used later.
Open the steps to implement the specific steps
The general idea of the whole program is, after using the screenshot software to get the screenshot, give it to the Baidu interface to identify and return the result, of course, it can also be the local picture recognition. I use the QQ screenshot software, the shortcut key CTRL+ALT+An is used to open the screenshot, after selecting the screenshot area, press the Enter key to save it to the pasteboard, or you can use other screenshot software.
① gets screenshot
The keyboard class library is used to listen for keyboard movements, so after a shortcut key is pressed, there will be a corresponding action. And use the ImageGrab in PIL to get the picture in the clipboard and generate the local picture file.
# 1. Screenshot
Keyboard.wait ('ctrl+alt+a')
Print ('start screenshot')
Keyboard.wait ('enter')
Print ('Save Screenshot')
Time.sleep (0.1)
# 2. Save pictures
Image = ImageGrab.grabclipboard ()
Image.save ('img.png')
② calls Baidu aip to recognize and print text
First initialize the application with the AppID, API Key and Secret Key generated at the time of registration, then read the saved picture and print the recognized text.
With open ('img.png',' rb') as fp:
Image = fp.read ()
Text_list = client.basicAccurate (image) ['words_result']
For text in text_list:
Print (text ['words'])
The running result is shown in the figure:
This is how to achieve character recognition in the Python shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.