{"id":16881500,"url":"https://github.com/swhl/textdetmetric","last_synced_at":"2025-10-12T00:45:11.527Z","repository":{"id":183364801,"uuid":"669640657","full_name":"SWHL/TextDetMetric","owner":"SWHL","description":"Compute the metric of text detection algorithm.","archived":false,"fork":false,"pushed_at":"2024-10-31T00:30:26.000Z","size":6639,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-21T06:55:24.921Z","etag":null,"topics":["h-mean","ocr","text-detection"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SWHL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-23T00:22:11.000Z","updated_at":"2024-11-20T08:08:18.000Z","dependencies_parsed_at":"2024-10-13T16:02:55.135Z","dependency_job_id":"428ba838-5e4f-42ec-a451-1363d2198e62","html_url":"https://github.com/SWHL/TextDetMetric","commit_stats":null,"previous_names":["swhl/textdetmetric"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/SWHL/TextDetMetric","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTextDetMetric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTextDetMetric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTextDetMetric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTextDetMetric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SWHL","download_url":"https://codeload.github.com/SWHL/TextDetMetric/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTextDetMetric/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009511,"owners_count":26084609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["h-mean","ocr","text-detection"],"created_at":"2024-10-13T16:02:52.509Z","updated_at":"2025-10-12T00:45:11.504Z","avatar_url":"https://github.com/SWHL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cdiv align=\"center\"\u003e\n    \u003ch1\u003e\u003cb\u003eText Detect Metric\u003c/b\u003e\u003c/h1\u003e\n  \u003c/div\u003e\n\n\u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/python-\u003e=3.6,\u003c3.12-aff.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/text_det_metric/\"\u003e\u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/text_det_metric\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pepy.tech/project/text_det_metric\"\u003e\u003cimg src=\"https://static.pepy.tech/personalized-badge/text_det_metric?period=total\u0026units=abbreviation\u0026left_color=grey\u0026right_color=blue\u0026left_text=Downloads \"\u003e\u003c/a\u003e\n\u003ca href=\"https://semver.org/\"\u003e\u003cimg alt=\"SemVer2.0\" src=\"https://img.shields.io/badge/SemVer-2.0-brightgreen\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/psf/black\"\u003e\u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"\u003e\u003c/a\u003e\n\n\u003c/div\u003e\n\n### 简介\n\n该库用于计算`Precision`、`Recall`和`H-mean`三个指标，用来快速评测文本检测算法效果，与[text_det_test_dataset](https://huggingface.co/datasets/SWHL/text_det_test_dataset)配套使用。\n\n指标计算代码参考：[PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR/blob/b13f99607653c220ba94df2a8650edac086b0f37/ppocr/metrics/eval_det_iou.py) 和 [DB](https://github.com/MhLiao/DB/blob/3c32b808d4412680310d3d28eeb6a2d5bf1566c5/concern/icdar2015_eval/detection/iou.py#L8)\n\n### 整体框架\n\n```mermaid\nflowchart LR\n\nA([Text Detect Algorithm]) --get_pred_txt.py--\u003e B([pred_txt])\nB --compute_metric.py--\u003e C([TextDetMetric]) --\u003e D([Precision])\nC --\u003e E([Recall])\nC --\u003e F([H-mean])\n```\n\n### 指定数据集上评测\n\n如果想要评测其他文本检测算法，需要将预测结果写入`pred.txt`中，格式为`预测框坐标\\t真实框坐标\\t耗时`，详细可参考[link](./pred.txt)。示例如下：\n\n```text\n[[[85.0, 43.0], [164.0, 44.0], [164.0, 72.0], [85.0, 70.0]]] [[[473.36082474226805, 271.2938144329896], [520.7835051546391, 290.8814432989691]]] 0.14536070823669434\n```\n\n### 示例（评测`rapidocr_onnxruntime==1.3.16`）\n\n1. 安装运行环境\n\n    ```bash\n    pip install rapidocr_onnxruntime==1.3.16\n    pip install datasets\n    pip install text_det_metric\n    ```\n\n2. 获得`pred.txt`文本文件\n\n    ```python\n    from pathlib import Path\n    import cv2\n    import numpy as np\n    from datasets import load_dataset\n    from rapidocr_onnxruntime import RapidOCR\n    from tqdm import tqdm\n\n    engine = RapidOCR()\n\n    dataset = load_dataset(\"SWHL/text_det_test_dataset\")\n    test_data = dataset[\"test\"]\n\n    content = []\n    for i, one_data in enumerate(tqdm(test_data)):\n        img = np.array(one_data.get(\"image\"))\n        img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)\n\n        dt_boxes, elapse = engine(img, use_det=True, use_cls=False, use_rec=False)\n\n        dt_boxes = [] if dt_boxes is None else dt_boxes\n        elapse = 0 if elapse is None else elapse[0]\n\n        gt_boxes = [v[\"points\"] for v in one_data[\"shapes\"]]\n        content.append(f\"{dt_boxes}\\t{gt_boxes}\\t{elapse}\")\n\n    with open(\"pred.txt\", \"w\", encoding=\"utf-8\") as f:\n        for v in content:\n            f.write(f\"{v}\\n\")\n    ```\n\n3. 计算指标\n\n    ```python\n    from text_det_metric import TextDetMetric\n\n    metric = TextDetMetric()\n    pred_path = \"pred.txt\"\n    metric = metric(pred_path)\n    print(metric)\n\n    ```\n\n4. 得到结果\n\n    ```bash\n    {'precision': 0.8301, 'recall': 0.8659, 'hmean': 0.8476, 'avg_elapse': 0.2246}\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswhl%2Ftextdetmetric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswhl%2Ftextdetmetric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswhl%2Ftextdetmetric/lists"}