• Stars
    star
    271
  • Rank 151,221 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP验证码识别[PHP CAPTCHA Recognition]

ImageOCR

php 验证码识别库,对于非粘连字符具有很好的识别效果,对于一般粘连字符也能有较为良好的识别 除噪算法支持孤立点除杂和连通域除噪,分割算法支持等宽分割、连通域分割以及滴水算法分割

示例效果

示例

Install

composer require mohuishou/image-ocr

使用方法

例子详见 example

use docker

docker run --rm -p 8088:8088 mohuishou/image-ocr

点击 http://localhost:8088 查看效果

大致流程:

初始化 -> 灰度化 ---> 二值化 ---> 除噪点 -> 分割 -> 标准化 -> 识别

初始化

对象初始化

$image=new Image($img_path);
$image_ocr=new ImageOCR($image)

初始化二值化阈值

$image_ocr->setMaxGrey(90);
$image_ocr->setMinGrey(10);

初始化标准化图片宽高

$image_ocr->setStandardWidth(13);
$image_ocr->setStandardHeight(20);

开启 Debug

$image_ocr->setDebug(true);

灰度化

try{
    $image_ocr->grey();
}catch (\Exception $e){
    echo $e->getMessage();
}

二值化

注意:这一步的前提是需要先执行上一步灰度化,不然会抛出一个错误

try{
    $image_ocr->hash($max_grey=null,$min_grey=null);
}catch (\Exception $e){
    echo $e->getMessage();
}

二值化支持两种方式,第一种$image_ocr->hash($max_grey=null,$min_grey=null)即为上面那种固定的阈值范围,第二种为hashByBackground($model=self::MAX_MODEL,$max_grey=null,$min_grey=null),通过背景图像的灰度值,动态取阈值,支持三种模式MAX_MODEL,MIN_MODEL,BG_MODEL分别是最大值、最小值和背景模式,最大值模式会用背景的灰度值替换阈值的上限,最小值模式替换下限,背景模式上下限都替换,即为只去除背景

除噪点

前置条件为二值化

孤立点除噪法
try{
    $image_ocr->removeSpots();
}catch (\Exception $e){
    echo $e->getMessage();
}
连通域除噪法

[如果要使用连通域分割法,可以跳过连通域除噪点,分割的同时可以一并除噪]

try{
    //使用之前需要初始化连通域对象
    $image_ocr->setImageConnect();
    //除噪
    $image_ocr->removeSpotsByConnect();
}catch (\Exception $e){
    echo $e->getMessage();
}

分割

非粘连字符串

连通域分割法

try{
    //使用之前需要初始化连通域对象
    $image_ocr->setImageConnect();
    //分割
    $image_ocr->splitByConnect();
}catch (\Exception $e){
    echo $e->getMessage();
}
粘连字符串

滴水算法分割

TODO: 待测试

标准化

try{
    $standard_data=$image_ocr->standard();
}catch (\Exception $e){
    echo $e->getMessage();
}

识别

TODO:待完善

API

ImageOCR::__construct(Image $image)
ImageOCR::saveImage($path)
ImageOCR::grey()
ImageOCR::hash($max_grey=null,$min_grey=null)
ImageOCR::hashByBackground($model=self::MAX_MODEL,$max_grey=null,$min_grey=null)
ImageOCR::removeSpots()
ImageOCR::removeSpotsByConnect()
ImageOCR::standard()
ImageOCR::setImageConnect()
ImageOCR::setImage(Image $image)
ImageOCR::getStandardData()
ImageOCR::setMaxGrey($max_grey)
ImageOCR::setMinGrey($min_grey)
ImageOCR::setStandardWidth($standard_width)
ImageOCR::setStandardHeight($standard_height)

//ImageTool的方法均为静态方法
ImageTool::removeZero($data)
ImageTool::removeZeroColumn($hash_data)
ImageTool::drawBrowser($data)
ImageTool::transposeAndRemoveZero($hash_data)
ImageTool::hashTranspose($hash_data)
ImageTool::img2hash($img)
ImageTool::hash2img($hash_data,$padding=0)

CHANGELOG

0.2 [2017-4-1]

0.1 [2016-10-7]

  1. 默认模板保存方式由数据库改为文件,保存路径为./db/db.json
  2. 使用 composer 安装

More Repositories

1

go-design-pattern

golang design pattern go 设计模式实现,包含 23 种常见的设计模式实现,同时这也是极客时间-设计模式之美 的笔记
Go
1,924
star
2

scuplus-wechat

We川大小程序[scuplus] 使用wepy开发的完善的校园综合小程序, 40+页面,前后端开源,包括成绩、课表、失物招领、图书馆、新闻资讯等等常见校园场景功能
Vue
665
star
3

utools

utools 插件,utools api, chrome历史记录搜索、vscode历史项目搜索、otp两步验证,iconfont图标搜索下载、语雀搜索等
TypeScript
291
star
4

protoc-gen-go-gin

从 protobuf 文件中生成使用 gin 的 http rpc 服务 (protobuf to gin code)
Go
109
star
5

scuplus-go

We川大小程序后端
Go
105
star
6

blog-code

https://lailin.xyz 博客代码
Go
39
star
7

PaperDownload

知网/万方 论文/期刊批量检索下载
Go
24
star
8

go-algorithm

【更新中】Go 数据结构与算法系列文章,本系列文章主要会包括常见的数据结构与算法实现,同时会包括 Go 标准库代码的分析理解,讲到对应章节的时候优先学习分析 Go 的源码实现,例如 slice、list、sort 等,然后可能会有一些常见的案例实现,同时这也是 极客时间-数据结构与算法之美 的课程笔记
Go
21
star
9

siyuan-sync-github

思源笔记挂件块,同步 markdown 笔记文件为 到 github,支持迁移笔记到图床
TypeScript
19
star
10

notion-blog-actions

convert notion database pages to markdown files for hexo or hugo
JavaScript
18
star
11

ATool

通过调用安卓加速度传感器,绘制曲线图,导出为文本文件,并且计算交通工具的舒适程度
Java
15
star
12

cet

免证四六级查询
C
14
star
13

gen-const-msg

提取源码文件中的常量注释,生成对应的 msg 信息,常用于err code当中
Go
11
star
14

wxapp-schedule

小程序课程表组件
JavaScript
9
star
15

mohuishou.github.io

Mohuishou's Blog
HTML
9
star
16

apollo-viper-provider

use ctripcorp/apollo as viper's RemoteConfigProvider
Go
9
star
17

go-sort

常用排序算法的golang实现
Go
6
star
18

php-webhook

git自动部署钩子
PHP
6
star
19

mohuishou

Go
5
star
20

goDataStruct

中国大学MOOC数据结构课程学习
Go
4
star
21

autoSign

联通沃贝相关自动签到包
PHP
3
star
22

monitor

web服务监控
Go
3
star
23

sms-notice

短信通知系统
PHP
3
star
24

typecho2hexo

转换typecho数据为hexo格式的md文件,支持附件(图片)下载,附件(图片)上传到七牛
PHP
3
star
25

evaluate-go

四川大学快捷评教
Vue
2
star
26

hugo-action

use github action with hugo
Shell
2
star
27

BabyBuddy-Baby

婴儿智能监护系统app婴儿端,前端。采用appcan平台开发
HTML
1
star
28

leetcode

1
star
29

email

邮件后台发送服务
Go
1
star
30

cloudbase-siyuan-note

使用 腾讯云 云开发一键部署 思源笔记
Python
1
star
31

resume

个人简历
1
star
32

go-test-multi-module

在单个仓库中支持多个 go mod 模块示例
Go
1
star
33

swugpa

西南大学绩点/平均分一键计算
PHP
1
star
34

yzdesign

yzdesign for phpwind
PHP
1
star