我们很高兴地宣布发布 Spire.OCR for Python 2.1.0 版本。该版本实现了云端 AI 模型(包括豆包、通义千问和 DeepSeek)与 Spire.OCR for Python 的无缝集成。这些模型有助于提高图像中文字识别的准确性和增强识别效果。
新功能:
- 支持接入云端 AI 模型(如豆包、千问、DeepSeek 等)进行图片文本识别。(注:用户需自行在 AI 平台获取 API Key)
def _run_ai_test(self):
filename = "1.png"
output_file = "scan.txt"
file_path = r"F:\3.3.0AI\AI\ocr.xml"
model = "AIModel"
api_key = "ApiKey"
api_url = "ApiUrl"
self._update_ocr_config(file_path, model, api_key, api_url)
self._scan_img(filename, output_file)
def _scan_img(self, filename, output_file):
scanner = OcrScanner()
configure_options = ConfigureOptions()
configure_options.ModelPath = r"F:\3.3.0AI\AI"
configure_options.Language = "Japanese"
scanner.ConfigureDependencies(configure_options)
scanner.Scan(filename)
text = scanner.Text.ToString()
with open(output_file, "w", encoding="utf-8") as f:
f.write(text)
def _update_ocr_config(self, file_path, model, api_key, api_url):
tree = ET.parse(file_path)
root = tree.getroot()
model_node = root.find('./configs/model')
api_key_node = root.find('./configs/apiKey')
api_url_node = root.find('./configs/apiUrl')
if model_node is not None:
model_node.text = model
if api_key_node is not None:
api_key_node.text = api_key
if api_url_node is not None:
api_url_node.text = api_url
tree.write(file_path, encoding='utf-8', xml_declaration=True)
print("XML更新成功!")
获取 Spire.OCR for Python 2.1.0 请点击:






