#419·RapidOCR

rapidocr到2.0.7版本时,用TableStructureRec会出现错误

Author: superstyleCreated May 6, 2025Updated Aug 5, 2026

问题描述 / Problem Description

rapidocr到2.0.7版本时,用TableStructureRec会出现如下错误 venv\lib\site-packages\rapidocr\\utils\download_file.py", line 86 ) as progress_bar, ^ SyntaxError: invalid syntax

运行环境 / Runtime Environment

windows 10 python 3.8.10

复现代码 / Reproduction Code

python
from pathlib import Path
from rapidocr import RapidOCR, VisRes
from rapid_table import RapidTable, RapidTableInput, VisTable

# 默认是slanet_plus模型

# 开启onnx-gpu推理
# input_args = RapidTableInput(use_cuda=True)
# table_engine = RapidTable(input_args)

# 使用torch推理版本的unitable模型
# input_args = RapidTableInput(model_type="unitable", use_cuda=True, device="cuda:0")
# table_engine = RapidTable(input_args)

ocr_engine = RapidOCR()
vis_ocr = VisRes()

input_args = RapidTableInput(
    #model_type="ModelType.SLANETPLUS.value",
    #model_path="./models/slanet-plus.onnx",
    use_cuda=False,
    device="cpu"
    )
table_engine = RapidTable(input_args)
viser = VisTable()

img_path = "s:/temp/3.png"

# OCR
rapid_ocr_output = ocr_engine(img_path, return_word_box=True)
ocr_result = list(
  zip(rapid_ocr_output.boxes, rapid_ocr_output.txts, rapid_ocr_output.scores)
)
# 使用单字识别
# word_results = rapid_ocr_output.word_results
# ocr_result = [
#     [word_result[2], word_result[0], word_result[1]] for word_result in word_results
# ]

table_results = table_engine(img_path, ocr_result)
table_html_str, table_cell_bboxes = table_results.pred_html, table_results.cell_bboxes
# Save
save_dir = Path("outputs")
save_dir.mkdir(parents=True, exist_ok=True)

save_html_path = save_dir / f"{Path(img_path).stem}.html"
save_drawed_path = save_dir / f"{Path(img_path).stem}_table_vis{Path(img_path).suffix}"
save_logic_points_path = save_dir / f"{Path(img_path).stem}_table_col_row_vis{Path(img_path).suffix}"

# Visualize table rec result
vis_imged = viser(img_path, table_results, save_html_path, save_drawed_path, save_logic_points_path)

print(f"The results has been saved {save_dir}")

可能解决方案 / Possible solutions