翻译|使用教程|编辑:李显亮|2021-06-18 10:03:54.803|阅读 252 次
概述:使用 OCR,可以将图像转换为可搜索和可编辑的 Word 文档。为此,本文将教您如何使用 C++ 将图像转换为 Word 文档。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
图像和扫描的文档可能包含您可能需要进一步处理的文本信息。可能已经使用智能手机拍摄了文本文档的图片,并将其转换为可编辑的文档。为此,对图像执行 OCR 可以证明是有帮助的。使用 OCR,可以将图像转换为可搜索和可编辑的 Word 文档。为此,本文将教您 如何使用 C++ 将图像转换为 Word 文档。
Aspose.OCR 是一种光学字符识别 API,可以从图像中提取文本。该 API 还使您能够将图像转换为 Word 文档和文本文件。如果你还没有用过Aspose.OCR可以点击这里下载最新版测试。
通常您可能需要搜索或编辑图像中的文本,但您无法这样做。通过对此类图像执行 OCR 并将其转换为 Word 文档,您可以根据需要搜索和编辑文本。为此,请按照以下步骤操作。
以下示例代码显示了如何使用 C++ 将图像转换为 Word 文档:
// Source file path std::string image_path = "SourceDirectory\\sample.png"; // Prepare buffer for result (in symbols, len_byte = len * sizeof(wchar_t)) const size_t len = 4096; wchar_t buffer[len] = { 0 }; // Set the recognition settings RecognitionSettings settings; settings.save_format = file_format::docx; // Perform the OCR operation and save the output file. asposeocr_page_save(image_path.c_str(), "OutputDirectory\\ImageToDocx.Docx", settings);
图像和扫描的文档有时会倾斜。使用 Aspose.OCR for C++ API,您可以对倾斜的图像执行 OCR。以下是将倾斜图像转换为 Word 文档的步骤:
以下示例代码显示了如何使用 C++ 将倾斜图像转换为 Word 文档:
// Source file path std::string image_path = "SourceDirectory\\skewSample.png"; // Prepare buffer for result (in symbols, len_byte = len * sizeof(wchar_t)) const size_t len = 4096; wchar_t buffer[len] = { 0 }; // Calculate skew angle std::double_t angle = asposeocr_get_skew(image_path.c_str()); // Set the recognition settings RecognitionSettings settings; settings.save_format = file_format::docx; settings.skew = angle; // Perform the OCR operation and save the output file. asposeocr_page_save(image_path.c_str(), "OutputDirectory\\SkewedImageToDocx.docx", settings);
如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com