{"id":14976984,"url":"https://github.com/github30/winocr","last_synced_at":"2025-05-12T14:29:26.262Z","repository":{"id":62589175,"uuid":"374981036","full_name":"GitHub30/winocr","owner":"GitHub30","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-25T04:04:54.000Z","size":35,"stargazers_count":20,"open_issues_count":1,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-12T14:29:16.970Z","etag":null,"topics":["ocr","python","python3","text-recognition","windows","windows-10","windows-11","winrt","winsdk"],"latest_commit_sha":null,"homepage":"https://qiita.com/relu/items/94e35a85c9c64f86f738","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GitHub30.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":"2021-06-08T11:16:45.000Z","updated_at":"2025-01-10T17:17:50.000Z","dependencies_parsed_at":"2024-09-27T23:00:25.121Z","dependency_job_id":"3b6a9ac8-3abc-48fc-a3b5-0c446fe6b1b2","html_url":"https://github.com/GitHub30/winocr","commit_stats":{"total_commits":21,"total_committers":4,"mean_commits":5.25,"dds":"0.23809523809523814","last_synced_commit":"a9c080ee4109cebd8883c7a36e72691862d18a10"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitHub30%2Fwinocr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitHub30%2Fwinocr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitHub30%2Fwinocr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitHub30%2Fwinocr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GitHub30","download_url":"https://codeload.github.com/GitHub30/winocr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253754741,"owners_count":21958902,"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":["ocr","python","python3","text-recognition","windows","windows-10","windows-11","winrt","winsdk"],"created_at":"2024-09-24T13:54:47.879Z","updated_at":"2025-05-12T14:29:26.238Z","avatar_url":"https://github.com/GitHub30.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WinOCR\n[![Python](https://img.shields.io/pypi/pyversions/winocr.svg)](https://badge.fury.io/py/winocr)\n[![PyPI](https://badge.fury.io/py/winocr.svg)](https://badge.fury.io/py/winocr)\n\n# Installation\n```powershell\npip install winocr\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eFull install\u003c/summary\u003e\n  \n  ```powershell\n  pip install winocr[all]\n  ```\n\u003c/details\u003e\n\n# Usage\n\n## Pillow\n\nThe language to be recognized can be specified by the lang parameter (second argument).\n\n```python\nimport winocr\nfrom PIL import Image\n\nimg = Image.open('test.jpg')\n(await winocr.recognize_pil(img, 'ja')).text\n```\n![](https://camo.githubusercontent.com/4e68db4fc3106c03e9919eb4391ce7548c1321429f9dc1a95a6937f51f01d5f6/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f363337383562393633666135643637653966326265316163396534393533353739663463323538342f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663333333733303631333533343633333832643632333533363631326433353333363233383264333636363332333532643336333433333333363333313336333033383338363636313265373036653637)\n\n## OpenCV\n\n```python\nimport winocr\nimport cv2\n\nimg = cv2.imread('test.jpg')\n(await winocr.recognize_cv2(img, 'ja')).text\n```\n![](https://camo.githubusercontent.com/fbbc81dd9fb138032625585dd3cd41a4b14b14621be77c11a15ea8949a3cc8a3/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f616439313337366536316230653332613234336664633932613435383665383763386636383362612f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663635333833303331333336333338333632643631333833333332326433393338333736333264333533373633333832643331333533383335333633353636333433313330333433323265373036653637)\n\n## Connect to local runtime on Colaboratory\n\nCreate a local connection by following [these instructions](https://research.google.com/colaboratory/local-runtimes.html).\n\n```powershell\npip install jupyterlab jupyter_http_over_ws\njupyter serverextension enable --py jupyter_http_over_ws\njupyter notebook --NotebookApp.allow_origin='https://colab.research.google.com' --ip=0.0.0.0 --port=8888 --NotebookApp.port_retries=0\n```\n\n![](https://i.imgur.com/gvj959U.png)\n\n![](https://i.imgur.com/o9e0Fwk.png)\n\nAlso available on Jupyter / Jupyter Lab.\n\n## REPL\n\n```python\nimport cv2\nfrom winocr import recognize_cv2_sync\n\nimg = cv2.imread('testocr.png')\nrecognize_cv2_sync(img)['text']\n'This is a lot of 12 point text to test the ocr code and see if it works on all types of file format. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox.'\n```\n\n```python\nfrom PIL import Image\nfrom winocr import recognize_pil_sync\n\nimg = Image.open('testocr.png')\nrecognize_pil_sync(img)['text']\n'This is a lot of 12 point text to test the ocr code and see if it works on all types of file format. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox.'\n```\n\n## Multi-Processing\n\n```python\nfrom PIL import Image\nimport concurrent.futures\nfrom winocr import recognize_pil_sync\n\nimages = [Image.open('testocr.png') for i in range(1000)]\n\nwith concurrent.futures.ProcessPoolExecutor() as executor:\n  results = list(executor.map(recognize_pil_sync, images))\nprint(results)\n```\n\n## Web API\n\nRun server\n```powershell\npip install winocr[api]\nwinocr_serve\n```\n\n### curl\n\n```bash\ncurl localhost:8000?lang=ja --data-binary @test.jpg\n```\n![](https://camo.githubusercontent.com/658ff5e7ff505281fc464f642579ab8dac1a7e9120a0345c0eeaf0f46995c404/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f396463623138383330656665343832643962626231633861393064383032303566373131313265642f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663636363433313338333433353636363332643635333633343337326433303634333736363264333533333336363532643336333436353333363333303332363336333338363133313265373036653637)\n\n### Python\n\n```python\nimport requests\n\nbytes = open('test.jpg', 'rb').read()\nrequests.post('http://localhost:8000/?lang=ja', bytes).json()['text']\n```\n\n![](https://camo.githubusercontent.com/fb338aadf3f057e14c4b6474f4802b6958f9264aff634fdf22d7d5b321747bd5/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f303438353362653766613263333839623339323161653461303938663165343161626162316136372f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663634333733313632333333353331333632643332363436363635326436313634333933313264363236363631333532643636333433373636333736323338333636333332363336333265373036653637)\n\nYou can run OCR with the Colaboratory runtime with `./ngrok http 8000`\n\n```python\nfrom PIL import Image\nfrom io import BytesIO\n\nimg = Image.open('test.jpg')\n# Preprocessing\nbuf = BytesIO()\nimg.save(buf, format='JPEG')\nrequests.post('https://15a5fabf0d78.ngrok.io/?lang=ja', buf.getvalue()).json()['text']\n```\n![](https://camo.githubusercontent.com/61adc7eb41c54bedfd19ab3ce2e55dd7b0c865a22c0ab787439296a0afc75d7a/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f656538343938663932656566303336333262623064336162623236646531323639393730393030632f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663333333933303634333933353339333732643331363433353335326433353634333136333264333833353332333032643331333536333334363133383331333133383634363436343265373036653637)\n\n```python\nimport cv2\nimport requests\n\nimg = cv2.imread('test.jpg')\n# Preprocessing\nrequests.post('https://15a5fabf0d78.ngrok.io/?lang=ja', cv2.imencode('.jpg', img)[1].tobytes()).json()['text']\n```\n![](https://camo.githubusercontent.com/a303dc95a4df7dbef67143a983b7792172b3d1b1837b0be7e7fa3c8a92b728d7/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f653566346530626630353338623835316464643532353837393630306137313261336365393738612f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663339363133333634363133353334363132643336333636343336326433393631333833323264333733303338363632643634363433343337363333323338333233313339333033303265373036653637)\n\n### JavaScript\n\nIf you only need to recognize Chrome and English, you can also consider the Text Detection API.\n\n```javascript\n// File\nconst file = document.querySelector('[type=file]').files[0]\nawait fetch('http://localhost:8000/', {method: 'POST', body: file}).then(r =\u003e r.json())\n\n// Blob\nconst blob = await fetch('https://image.itmedia.co.jp/ait/articles/1706/15/news015_16.jpg').then(r=\u003er.blob())\nawait fetch('http://localhost:8000/?lang=ja', {method: 'POST', body: blob}).then(r =\u003e r.json())\n```\n\nIt is also possible to run OCR Server on Windows Server.\n\n# Information that can be obtained\nYou can get **angle**, **text**, **line**, **word**, **BoundingBox**.\n\n```python\nimport pprint\n\nresult = await winocr.recognize_pil(img, 'ja')\npprint.pprint({\n    'text_angle': result.text_angle,\n    'text': result.text,\n    'lines': [{\n        'text': line.text,\n        'words': [{\n            'bounding_rect': {'x': word.bounding_rect.x, 'y': word.bounding_rect.y, 'width': word.bounding_rect.width, 'height': word.bounding_rect.height},\n            'text': word.text\n        } for word in line.words]\n    } for line in result.lines]\n})\n```\n![](https://camo.githubusercontent.com/c0715ad500369e6b1b498293335bd8844e38baee7ead335a7047128947f0b9b6/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f636561393234303738393733346663323734383663363265666563373936623633393764376433352f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663633363633353334333736323331333132643331333033383634326436333633333533333264363533383633333332643331333636363333333736353634333233383631363333353265373036653637)\n\n# Language installation\n```powershell\n# Run as Administrator\nAdd-WindowsCapability -Online -Name \"Language.OCR~~~en-US~0.0.1.0\"\nAdd-WindowsCapability -Online -Name \"Language.OCR~~~ja-JP~0.0.1.0\"\n\n# Search for installed languages\nGet-WindowsCapability -Online -Name \"Language.OCR*\"\n# State: Not Present language is not installed, so please install it if necessary.\nName         : Language.OCR~~~hu-HU~0.0.1.0\nState        : NotPresent\nDisplayName  : ハンガリー語の光学式文字認識\nDescription  : ハンガリー語の光学式文字認識\nDownloadSize : 194407\nInstallSize  : 535714\n\nName         : Language.OCR~~~it-IT~0.0.1.0\nState        : NotPresent\nDisplayName  : イタリア語の光学式文字認識\nDescription  : イタリア語の光学式文字認識\nDownloadSize : 159875\nInstallSize  : 485922\n\nName         : Language.OCR~~~ja-JP~0.0.1.0\nState        : Installed\nDisplayName  : 日本語の光学式文字認識\nDescription  : 日本語の光学式文字認識\nDownloadSize : 1524589\nInstallSize  : 3398536\n\nName         : Language.OCR~~~ko-KR~0.0.1.0\nState        : NotPresent\nDisplayName  : 韓国語の光学式文字認識\nDescription  : 韓国語の光学式文字認識\nDownloadSize : 3405683\nInstallSize  : 7890408\n```\n\nIf you hate Python and just want to recognize it with PowerShell, click [here](https://gist.github.com/GitHub30/8bc1e784148e4f9801520c7e7ba191ea)\n\n# Multi-Processing\n\nBy processing in parallel, it is 3 times faster. You can make it even faster by increasing the number of cores!\n\n```python\nfrom PIL import Image\n\nimages = [Image.open('testocr.png') for i in range(1000)]\n```\n\n### 1 core(elapsed 48s)\n\nThe CPU is not used up.\n![](https://camo.githubusercontent.com/a9003bdc7db7d8c0524fd8f9ef2394eac4a7ad68ba618954f518ed81a12738e8/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f633963393931656231343733313337383636666238363933656231643462656637623661646466632f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663636363133323633333236363335333232643339363633383336326436343334333533323264363433323633333732643631363233333633333036353330363136363338333736343265373036653637)\n\n```python\nimport winocr\n\n[(await winocr.recognize_pil(img)).text for img in images]\n```\n![](https://camo.githubusercontent.com/5e965ce96d5b3fdb5220c619ceb1597d09fea8d34df5f3a7a0b5388a8286a034/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f356261623862393830666565333764363632663733383933646632613463306234623439346464312f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663635363536353336363336333332333032643337363636333335326433373634363233373264333833343634363232643633363136353631363533323634363536363631333933393265373036653637)\n\n### 4 cores(elapsed 16s)\n\nI'm using 100% CPU.\n\n![](https://camo.githubusercontent.com/9bc7fc8bbf5c1e5cc9a89e4fb2233900867b6f79019ee530fe36e5d36c896ad9/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f323732326136303261313930616335653534646637313634623965336366373134636234386434322f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663337363336353635363236363331363532643636333233323636326433353330363533353264333933363335363132643334333033323636363636333337333833363334333536323265373036653637)\n\nCreate a worker module.\n```python\n%%writefile worker.py\nimport winocr\nimport asyncio\n\nasync def ensure_coroutine(awaitable):\n    return await awaitable\n\ndef recognize_pil_text(img):\n    return asyncio.run(ensure_coroutine(winocr.recognize_pil(img))).text\n```\n\n```python\nimport worker\nimport concurrent.futures\n\nwith concurrent.futures.ProcessPoolExecutor() as executor:\n  # https://stackoverflow.com/questions/62488423\n  results = executor.map(worker.recognize_pil_text, images)\nlist(results)\n```\n\n![](https://camo.githubusercontent.com/cd21e01dd05a064986c764e0b86aa98f3b25ad3b346ff5bdfee3d1dd7dbae132/68747470733a2f2f63616d6f2e716969746175736572636f6e74656e742e636f6d2f653137323531336435386531306339616436646464313438656562373865316263313132663632342f36383734373437303733336132663266373136393639373436313264363936643631363736353264373337343666373236353265373333333265363137303264366536663732373436383635363137333734326433313265363136643631376136663665363137373733326536333666366432663330326633323330333833333336333332663631333733313336333733353337333132643631363133353634326436333632333133353264363136343631333132643631333236343332333033303635333533383635363233383265373036653637)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub30%2Fwinocr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub30%2Fwinocr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub30%2Fwinocr/lists"}