{"id":20977038,"url":"https://github.com/githubharald/htrpipeline","last_synced_at":"2025-05-14T14:31:46.797Z","repository":{"id":107433409,"uuid":"604286867","full_name":"githubharald/HTRPipeline","owner":"githubharald","description":"Detect and read handwritten words on scanned pages.","archived":false,"fork":false,"pushed_at":"2023-07-20T15:52:59.000Z","size":3578,"stargazers_count":118,"open_issues_count":0,"forks_count":36,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-02T19:11:19.477Z","etag":null,"topics":["deep-learning","handwritten-text-recognition","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/githubharald.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-02-20T18:25:57.000Z","updated_at":"2025-03-20T23:01:59.000Z","dependencies_parsed_at":"2024-11-19T22:36:38.561Z","dependency_job_id":null,"html_url":"https://github.com/githubharald/HTRPipeline","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/githubharald%2FHTRPipeline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/githubharald%2FHTRPipeline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/githubharald%2FHTRPipeline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/githubharald%2FHTRPipeline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/githubharald","download_url":"https://codeload.github.com/githubharald/HTRPipeline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254160648,"owners_count":22024574,"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","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":["deep-learning","handwritten-text-recognition","ocr","text-detection"],"created_at":"2024-11-19T04:57:07.754Z","updated_at":"2025-05-14T14:31:46.791Z","avatar_url":"https://github.com/githubharald.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Detect and Read Handwritten Words\n\nThis is a **handwritten text recognition (HTR) pipeline** that operates on **scanned pages** and applies the following\noperations:\n\n* Detect words\n* Read words\n\n![example](./doc/example.png)\n\n## Installation\n\n* Download the zipped [model weights](https://www.dropbox.com/s/j1hl6bppecug0sz/models.zip?dl=0)\n* Unzip\n* Copy the files (reader.onnx, reader.json, detector.onnx) into the folder `htr_pipeline/models`\n* Go to the root level of the repository (where `setup.py` is located)\n* Execute `pip install .`\n\n## Usage\n\n### Run demo\n\n* Additionally install matplotlib for plotting: `pip install matplotlib`\n* Go to `scripts/`\n* Run `python demo.py`\n* The output should look like the plot shown above\n\n### Run web demo (gradio)\n\n* Additionally install gradio: `pip install gradio`\n* Go to the root directory of the repository\n* Run `python scripts/gradio_demo.py`\n* Open the URL shown in the output\n\n![example](./doc/gradio.png)\n\n### Use Python package\n\nImport the function `read_page` to detect and read text.\n\n````python\nimport cv2\nfrom htr_pipeline import read_page, DetectorConfig, LineClusteringConfig\n\n# read image\nimg = cv2.imread('data/sample_1.png', cv2.IMREAD_GRAYSCALE)\n\n# detect and read text\nread_lines = read_page(img, \n                       DetectorConfig(scale=0.4, margin=5), \n                       line_clustering_config=LineClusteringConfig(min_words_per_line=2))\n\n# output text\nfor read_line in read_lines:\n    print(' '.join(read_word.text for read_word in read_line))\n````\n\n## Selection of parameters\n\nConfiguration is done by passing instances of these dataclasses to the `read_page` function:\n* `DetectorConfig`: configure the word detector\n* `LineClusteringConfig`: configure the line clustering algorithm\n* `ReaderConfig`: configure the text reader\n\nThe most important parameter for the detector is the scale.\nThe detector works best for text of height 50px. \nSetting a scale != 1 automatically resizes the image before applying te detector.\nExample: Text height h is 100px in the original image. Set the scale to 0.5 so that detection happens at the ideal text size.\n\n![scale](./doc/scale.png)\n\nThe second most important parameter for the detector is the margin. \nIt allows adding a few pixels (blue) around the detected words (red) which might improve reading quality.\n\n![scale](./doc/margin.png)\n\nFor the line clustering algorithm the minimum number of words can be set with the parameter `min_words_per_line`.\nLines which contain fewer words will be ignored.\nExample: it is known that all lines contain 2 or more words. Then set the parameter to 2 to ignore false positive detections that form lines with only a single word.\n\n## Future work\n* Better documentation of all the features (e.g., how to use a dictionary) - for now please have a look into the demo scripts to learn about the features of this package\n* Add special characters like \".\", \"?\", ...\n* Optionally, read the whole line instead of single words\n* Improve inference speed","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithubharald%2Fhtrpipeline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithubharald%2Fhtrpipeline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithubharald%2Fhtrpipeline/lists"}