{"id":18556960,"url":"https://github.com/mohuishou/imageocr","last_synced_at":"2025-04-05T09:09:28.678Z","repository":{"id":57019105,"uuid":"57899354","full_name":"mohuishou/ImageOCR","owner":"mohuishou","description":"PHP验证码识别[PHP CAPTCHA Recognition]","archived":false,"fork":false,"pushed_at":"2019-06-12T07:10:23.000Z","size":99,"stargazers_count":273,"open_issues_count":2,"forks_count":68,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-29T08:09:46.962Z","etag":null,"topics":["captcha","image","imageocr","ocr","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/mohuishou.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}},"created_at":"2016-05-02T15:19:32.000Z","updated_at":"2024-12-20T05:15:29.000Z","dependencies_parsed_at":"2022-08-22T20:20:15.292Z","dependency_job_id":null,"html_url":"https://github.com/mohuishou/ImageOCR","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohuishou%2FImageOCR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohuishou%2FImageOCR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohuishou%2FImageOCR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohuishou%2FImageOCR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohuishou","download_url":"https://codeload.github.com/mohuishou/ImageOCR/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312082,"owners_count":20918344,"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":["captcha","image","imageocr","ocr","php"],"created_at":"2024-11-06T21:33:59.602Z","updated_at":"2025-04-05T09:09:28.644Z","avatar_url":"https://github.com/mohuishou.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ImageOCR\n\n\u003e php 验证码识别库，对于非粘连字符具有很好的识别效果，对于一般粘连字符也能有较为良好的识别\n\u003e 除噪算法支持孤立点除杂和连通域除噪，分割算法支持等宽分割、连通域分割以及滴水算法分割\n\n## 示例效果\n\n![示例](./img/1.png)\n\n## Install\n\n```\ncomposer require mohuishou/image-ocr\n```\n\n## 使用方法\n\n例子详见 [example](./example)\n\n### use docker\n\n```bash\ndocker run --rm -p 8088:8088 mohuishou/image-ocr\n```\n\n点击 http://localhost:8088 查看效果\n\n### 大致流程：\n\n```\n初始化 -\u003e 灰度化 ---\u003e 二值化 ---\u003e 除噪点 -\u003e 分割 -\u003e 标准化 -\u003e 识别\n```\n\n#### 初始化\n\n对象初始化\n\n```php\n$image=new Image($img_path);\n$image_ocr=new ImageOCR($image)\n```\n\n初始化二值化阈值\n\n```php\n$image_ocr-\u003esetMaxGrey(90);\n$image_ocr-\u003esetMinGrey(10);\n```\n\n初始化标准化图片宽高\n\n```php\n$image_ocr-\u003esetStandardWidth(13);\n$image_ocr-\u003esetStandardHeight(20);\n```\n\n#### 开启 Debug\n\n```php\n$image_ocr-\u003esetDebug(true);\n```\n\n#### 灰度化\n\n```php\ntry{\n    $image_ocr-\u003egrey();\n}catch (\\Exception $e){\n    echo $e-\u003egetMessage();\n}\n```\n\n#### 二值化\n\n注意：这一步的前提是需要先执行上一步灰度化，不然会抛出一个错误\n\n```php\ntry{\n    $image_ocr-\u003ehash($max_grey=null,$min_grey=null);\n}catch (\\Exception $e){\n    echo $e-\u003egetMessage();\n}\n```\n\n二值化支持两种方式，第一种`$image_ocr-\u003ehash($max_grey=null,$min_grey=null)`即为上面那种固定的阈值范围，第二种为`hashByBackground($model=self::MAX_MODEL,$max_grey=null,$min_grey=null)`，通过背景图像的灰度值，动态取阈值，支持三种模式`MAX_MODEL`,`MIN_MODEL`,`BG_MODEL`分别是最大值、最小值和背景模式，最大值模式会用背景的灰度值替换阈值的上限，最小值模式替换下限，背景模式上下限都替换，即为只去除背景\n\n#### 除噪点\n\n前置条件为二值化\n\n##### 孤立点除噪法\n\n```php\ntry{\n    $image_ocr-\u003eremoveSpots();\n}catch (\\Exception $e){\n    echo $e-\u003egetMessage();\n}\n```\n\n##### 连通域除噪法\n\n_[如果要使用连通域分割法，可以跳过连通域除噪点，分割的同时可以一并除噪]_\n\n```php\ntry{\n    //使用之前需要初始化连通域对象\n    $image_ocr-\u003esetImageConnect();\n    //除噪\n    $image_ocr-\u003eremoveSpotsByConnect();\n}catch (\\Exception $e){\n    echo $e-\u003egetMessage();\n}\n```\n\n#### 分割\n\n##### 非粘连字符串\n\n连通域分割法\n\n```php\ntry{\n    //使用之前需要初始化连通域对象\n    $image_ocr-\u003esetImageConnect();\n    //分割\n    $image_ocr-\u003esplitByConnect();\n}catch (\\Exception $e){\n    echo $e-\u003egetMessage();\n}\n```\n\n##### 粘连字符串\n\n滴水算法分割\n\nTODO: 待测试\n\n#### 标准化\n\n```php\ntry{\n    $standard_data=$image_ocr-\u003estandard();\n}catch (\\Exception $e){\n    echo $e-\u003egetMessage();\n}\n```\n\n#### 识别\n\nTODO:待完善\n\n## API\n\n```php\nImageOCR::__construct(Image $image)\nImageOCR::saveImage($path)\nImageOCR::grey()\nImageOCR::hash($max_grey=null,$min_grey=null)\nImageOCR::hashByBackground($model=self::MAX_MODEL,$max_grey=null,$min_grey=null)\nImageOCR::removeSpots()\nImageOCR::removeSpotsByConnect()\nImageOCR::standard()\nImageOCR::setImageConnect()\nImageOCR::setImage(Image $image)\nImageOCR::getStandardData()\nImageOCR::setMaxGrey($max_grey)\nImageOCR::setMinGrey($min_grey)\nImageOCR::setStandardWidth($standard_width)\nImageOCR::setStandardHeight($standard_height)\n\n//ImageTool的方法均为静态方法\nImageTool::removeZero($data)\nImageTool::removeZeroColumn($hash_data)\nImageTool::drawBrowser($data)\nImageTool::transposeAndRemoveZero($hash_data)\nImageTool::hashTranspose($hash_data)\nImageTool::img2hash($img)\nImageTool::hash2img($hash_data,$padding=0)\n```\n\n## CHANGELOG\n\n### 0.2 [2017-4-1]\n\n### 0.1 [2016-10-7]\n\n1. 默认模板保存方式由数据库改为文件，保存路径为./db/db.json\n2. 使用 composer 安装\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohuishou%2Fimageocr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohuishou%2Fimageocr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohuishou%2Fimageocr/lists"}