借助Aspose.OCR ,使用 Python 提取JPG图像文本、将JPG图像转换为Word
<p><img src="https://image.evget.com/attachment/keditor/image/20250806/093728_1.png"></p><p>图像通常包含有价值的文本,但从JPG等格式中提取文本并非易事。本文将学习如何借助<strong><u>Aspose.OCR</u></strong>,使用 Python 提取 JPG 文本,已经如何转换为Word文档。无论您是要自动化文档处理还是数字化印刷材料,此解决方案都能快速准确地为您提供结果。</p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>Aspose.OCR官方正版下载,请联系Aspose官方授权代理商<span style="color: rgba(35, 111, 161, 1)">慧都科技</span></strong></span></p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong><em>加入Aspose技术交流QQ群(</em></strong><em>1041253375</em><strong><em>),与更多小伙伴一起探讨提升开发技能。</em></strong></span></p>
<h2 id="what-is-jpg-text">什么是 JPG 文本?</h2>
<p>.jpgJPG 文本是嵌入在文件或图像文件中的可见文本.jpeg。它可以是以下形式:</p>
<ul>
<li>扫描文件</li>
<li>桌面或移动设备的屏幕截图</li>
<li>标志、标签或收据的照片</li>
<li>名片和手写表格</li>
</ul>
<p>由于 JPG 中的文本以像素形式存储,因此必须使用 OCR(光学字符识别)将其转换为机器可读的文本。从 JPG 图像中提取文本有很多好处。它有助于将纸质文档数字化,自动化表单数据录入,并使图像内容可搜索。您还可以将提取的文本用于代码中,以便进一步分析。借助 OCR 技术,您可以节省时间,并减少任何涉及图像信息任务的手动操作。</p>
<h2 id="asposeocr-jpg-text-extractor">Aspose.OCR:JPG文本提取器</h2>
<p>OCR(光学字符识别)是从 JPG 图像中提取文本的唯一可靠方法。在本篇博文中,我们将使用<strong>Aspose.OCR for Python</strong>提取 JPG 文本。它是一个专为开发人员设计的独立库,具有以下主要优势:</p>
<ul>
<li>内置预处理(倾斜校正、二值化、噪声过滤)</li>
<li>高速、高精度识别</li>
<li>支持多种输出格式:纯文本、JSON、PDF</li>
<li>适用于 Python、Java、.NET 和 C++</li>
</ul>
<p>Aspose.OCR 可自动检测字体、大小,甚至旋转后的文本,无论是简单用例还是高级用例,它都是理想之选。它可以扫描 JPG 图像中的打字或手写文本,检测复杂布局中的文本区域,并从图像中提取多语言内容。</p>
<h2 id="how-to-extract-jpg-text-in-python">如何在 Python 中提取 JPG 文本</h2>
<h3 id="step-1-install-asposeocr">步骤1:安装Aspose.OCR</h3>
<p>使用以下<em>pip命令从</em>PyPI安装库:</p>
<div class="highlight">
<pre class="prettyprint lang-js highlighter-hljs"><code>pip install aspose-ocr-python-net </code></pre>
</div>
<blockquote>
<p>您也可以<strong><u>从</u></strong><strong><u>发布版本</u></strong><strong><u>中下载</u></strong>该软件包。</p>
</blockquote>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>Aspose.OCR官方正版下载,请联系Aspose官方授权代理商<span style="color: rgba(35, 111, 161, 1)">慧都科技</span></strong></span></p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong><em>加入Aspose技术交流QQ群(</em></strong><em>1041253375</em><strong><em>),与更多小伙伴一起探讨提升开发技能。</em></strong></span></p>
<h3 id="step-2-read-jpg-text-with-code">步骤2:使用代码读取JPG文本</h3>
<pre class="prettyprint lang-js highlighter-hljs"><code>import aspose.ocr as ocr
# Instantiate Aspose.OCR API
api = ocr.AsposeOcr()
# Add image to the recognition batch
img = ocr.OcrInput(ocr.InputType.SINGLE_IMAGE)
img.add("sample-with-text.jpg")
# Recognize the image
result = api.recognize(img)
# Print recognition result
print(result.recognition_text)</code></pre>
<p>图像示例:</p>
<p><img src="https://image.evget.com/attachment/keditor/image/20250806/093952_9.jpg"></p>
<p>输出:</p>
<p><img src="https://img2024.cnblogs.com/blog/3659451/202508/3659451-20250806104711571-162816871.png"></p>
<h2 id="convert-jpg-text-to-word-using-python">使用 Python 将 JPG 文本转换为 Word</h2>
<p>您可以按照前面提到的步骤将 JPG 文本直接转换为可编辑的 Microsoft Word 文档。但是,您只需要.docx使用 Python 将提取的文本保存到文件中:</p>
<pre class="prettyprint lang-js highlighter-hljs"><code>import aspose.ocr as ocr
# Instantiate Aspose.OCR API
api = ocr.AsposeOcr()
# Add image to the recognition batch
img = ocr.OcrInput(ocr.InputType.SINGLE_IMAGE)
img.add("sample.jpg")
# Recognize the image
result = api.recognize(img)
# Print recognition result
print(result.recognition_text)
# Save as DOCX
result.save("ImagetoDOCX.docx", ocr.SaveFormat.DOCX, ocr.PdfOptimizationMode.NONE)</code></pre>
<p><img src="https://image.evget.com/attachment/keditor/image/20250806/094351_7.jpg"></p>
<h2 id="conclusion">结论</h2>
<p><strong>使用Aspose.OCR for Python</strong>提取 JPG 文本简单有效。它提供了一个简洁的 API,用于识别和转换图像文件中的文本。您可以轻松地将其集成到现有系统中,以实现自动化、搜索和编辑。</p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong>Aspose.OCR官方正版下载,请联系Aspose官方授权代理商<span style="color: rgba(35, 111, 161, 1)">慧都科技</span></strong></span></p>
<p style="text-align: center"><span style="color: rgba(230, 126, 35, 1)"><strong><em>加入Aspose技术交流QQ群(</em></strong><em>1041253375</em><strong><em>),与更多小伙伴一起探讨提升开发技能。</em></strong></span></p><br><br>
来源:https://www.cnblogs.com/software-Development/p/19024645
頁:
[1]