Hướng dẫn convert image to text with python - chuyển đổi hình ảnh thành văn bản với python
Show
Trong hướng dẫn này, chúng tôi sẽ khám phá cách trích xuất văn bản từ hình ảnh bằng PythonẢnh của Ian Schneider trên unplashMục lục
Giới thiệuHình ảnh mẫu Trích xuất văn bản từ một hình ảnh duy nhất bằng Python Trích xuất văn bản từ nhiều hình ảnh bằng Python
Để tiếp tục làm theo hướng dẫn này, chúng tôi sẽ cần: Tesseractpytesseract library which is a wrapper for Tesseract engine. pytesseractpillow library which adds image processing capabilities to Python. cái gối Tesseract là một công cụ OCR (Nhận dạng ký tự quang học) nguồn mở cho phép trích xuất văn bản từ hình ảnh. pip install pytesseract Hình ảnh mẫuTrích xuất văn bản từ một hình ảnh duy nhất bằng Python Trích xuất văn bản từ nhiều hình ảnh bằng Python Sự kết luậnTrích xuất văn bản từ hình ảnh là một nhiệm vụ rất phổ biến trong các đơn vị hoạt động của doanh nghiệp (trích xuất thông tin từ hóa đơn và biên lai) cũng như trong các lĩnh vực khác. Trích xuất văn bản từ một hình ảnh duy nhất bằng PythonTrích xuất văn bản từ nhiều hình ảnh bằng Python Sự kết luậnsampletext1-ocr.png Trích xuất văn bản từ hình ảnh là một nhiệm vụ rất phổ biến trong các đơn vị hoạt động của doanh nghiệp (trích xuất thông tin từ hóa đơn và biên lai) cũng như trong các lĩnh vực khác. OCR (Nhận dạng ký tự quang học) là một cách tiếp cận dựa trên máy tính điện tử để chuyển đổi hình ảnh của văn bản thành văn bản được mã hóa bằng máy, sau đó có thể được trích xuất và sử dụng ở định dạng văn bản.Để tiếp tục làm theo hướng dẫn này, chúng tôi sẽ cần:images and the code resides in main.py Tesseract pytesseracttessaract.exe which was created after the installation. On Windows it should reside in: C:\Program Files\Tesseract-OCR\tesseract.exe cái gối Tesseract là một công cụ OCR (Nhận dạng ký tự quang học) nguồn mở cho phép trích xuất văn bản từ hình ảnh. Sample Text 1 Trích xuất văn bản từ nhiều hình ảnh bằng PythonSự kết luận Trích xuất văn bản từ hình ảnh là một nhiệm vụ rất phổ biến trong các đơn vị hoạt động của doanh nghiệp (trích xuất thông tin từ hóa đơn và biên lai) cũng như trong các lĩnh vực khác.images and the code resides in main.py OCR (Nhận dạng ký tự quang học) là một cách tiếp cận dựa trên máy tính điện tử để chuyển đổi hình ảnh của văn bản thành văn bản được mã hóa bằng máy, sau đó có thể được trích xuất và sử dụng ở định dạng văn bản. Để tiếp tục làm theo hướng dẫn này, chúng tôi sẽ cần:os library we can access all of the file names in a given directory. Tesseractimages folder, we will iterate over them and extract text from each image using Python: Tesseract là một công cụ OCR (Nhận dạng ký tự quang học) nguồn mở cho phép trích xuất văn bản từ hình ảnh. Sample Text 1 Để sử dụng nó trong Python, chúng tôi cũng sẽ cần thư viện PyTesseract, một trình bao bọc cho động cơ Tesseract. Sự kết luậnTrích xuất văn bản từ hình ảnh là một nhiệm vụ rất phổ biến trong các đơn vị hoạt động của doanh nghiệp (trích xuất thông tin từ hóa đơn và biên lai) cũng như trong các lĩnh vực khác. OCR (Nhận dạng ký tự quang học) là một cách tiếp cận dựa trên máy tính điện tử để chuyển đổi hình ảnh của văn bản thành văn bản được mã hóa bằng máy, sau đó có thể được trích xuất và sử dụng ở định dạng văn bản. Xem thảo luận Cải thiện bài viết Lưu bài viết Xem thảo luận Cải thiện bài viết Lưu bài viết Đọc Bàn luận
Examples: Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..." Mã: Mã Python để chuyển đổi văn bản thành bài phát biểu
Sample Text 1 1
Sample Text 1 3import Sample Text 1 5Sample Text 1 6Sample Text 1 7 Sample Text 1 8Sample Text 1 9Sample Text 1 0Sample Text 1 1Sample Text 1 2Sample Text 1 3Sample Text 1 4Sample Text 1 5Sample Text 1 7Sample Text 1 7 Sample Text 1 8Sample Text 1 7 Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..."0 Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..."1 Sample Text 1 9Sample Text 1 0Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..."4 Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..."5 Sample Text 1 7Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..."7 Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..."8 Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..."9 import 0
Input : We Have an image with some text Output: THE TEXT FROM THE IMAGE IS EXTRACTED AND A VOICE WILL SPEAK THE TEXT This is the first line of this text example. This is the second line of the same text. Translated(src=en, dest=de, text=Dies ist die erste Zeile von Dieses Textbeispiel. Dies ist die zweite Zeile desselben Textes., pronunciation=None, extra_data="{'translat..."9 import 3
Sample Text 1 3import 6
Sample Text 1 7 import 9
Sample Text 1 7pytesseract 4pytesseract 5Sample Text 1 3pytesseract 7
Sample Text 1 7 from 0
Lưu ý: Chúng tôi có thể chuyển đổi văn bản thành bất kỳ ngôn ngữ mong muốn nào. Ví dụ, Nhật Bản, Nga, tiếng Hindi. Nhưng điều kiện duy nhất là googletrans nên nhận ra ngôn ngữ đích. Ngoài ra, pyttsx3 sẽ chỉ nói các ngôn ngữ được nó công nhận. We can convert the text into any desired language. For Example Japanese, Russian, Hindi. But the only condition is that the googletrans should recognize the destination language. Also, pyttsx3 will speak only the languages which are recognized by it. Bạn có thể chuyển đổi một hình ảnh thành văn bản không?Có những chương trình sử dụng nhận dạng ký tự quang (OCR) để phân tích các chữ cái và từ trong một hình ảnh và sau đó chuyển đổi chúng thành văn bản. Có một số lý do tại sao bạn có thể muốn sử dụng công nghệ OCR để sao chép văn bản từ hình ảnh hoặc pdf.. There are a number of reasons why you might want to use OCR technology to copy text from an image or PDF.
Làm cách nào để sử dụng OCR trong Python?Bạn có thể cài đặt trình bao bọc Python cho Tesseract sau đó bằng PIP.Thư viện Tesseract được vận chuyển với một công cụ dòng lệnh tiện dụng gọi là Tesseract.Chúng ta có thể sử dụng công cụ này để thực hiện OCR trên hình ảnh và đầu ra được lưu trữ trong tệp văn bản.install the python wrapper for tesseract after this using pip. Tesseract library is shipped with a handy command-line tool called tesseract. We can use this tool to perform OCR on images and the output is stored in a text file.
Làm cách nào để phiên âm văn bản từ một hình ảnh?Cách phiên âm hình ảnh thành văn bản.. Bước 1: Tạo tệp PDF từ tệp hình ảnh..... Bước 2: Thực hiện OCR trên tệp đã chuyển đổi..... Bước 3: (Tùy chọn) - Thực hiện các thay đổi đối với dữ liệu được chuyển đổi văn bản..... Bước 4: Chuyển đổi thành định dạng đầu ra đã chọn .. Python có tốt để nhận dạng hình ảnh không?Python là một trong những ngôn ngữ lập trình được sử dụng rộng rãi cho mục đích này.Các thư viện và công cụ tuyệt vời của nó giúp đạt được nhiệm vụ xử lý hình ảnh rất hiệu quả.Its amazing libraries and tools help in achieving the task of image processing very efficiently. |