BaiduOcr
百度OCR文字识别API For Ruby
Installation
Add this line to your application's Gemfile:
gem 'baidu_ocr', :git => 'https://github.com/rudyboy/baidu_ocr'
or
gem install baidu_ocr
And then execute:
$ bundle
Usage
require 'baidu_ocr'
# 参数说明
# 1. detectType
# LocateRecognize: 整图文字检测、识别,以行为单位(默认)
# Locate:整图文字行定位
# Recognize:整图文字识别
# SingleCharRecognize:单字图像识别
# 2. languageType
# CHN_ENG(中英)(默认)
# ENG(英文)
# JAP(日文)
# KOR(韩文)
# local image && imagetype = 1
BaiduOcr.init_baidu_ocr(apikey: 'your api',
image: 'bit.jpg',
imagetype: 1)
puts BaiduOcr.recognize
# local image && imagetype = 2
BaiduOcr.init_baidu_ocr(apikey: 'your api',
image: 'bit.jpg',
imagetype: 2)
puts BaiduOcr.recognize
# image from web && imagetype = 1
BaiduOcr.init_baidu_ocr(apikey: 'your api',
image: 'https://raw.githubusercontent.com/rudyboy/baidu_ocr/master/examples/bit.jpg',
imagetype: 1)
puts BaiduOcr.recognize
# image from web && imagetype = 2
BaiduOcr.init_baidu_ocr(apikey: 'your api',
image: 'https://raw.githubusercontent.com/rudyboy/baidu_ocr/master/examples/bit.jpg',
imagetype: 2)
puts BaiduOcr.recognize
# 完全自定义参数
BaiduOcr.init_baidu_ocr(fromdevice:'your device',
clientip: 'your clientip',
detecttype: 'your detecttype',
languagetype: 'your languagetype',
imagetype: 'your imagetype',
image: 'your image path',
apikey: 'your api'
)
puts BaiduOcr.recognize
结果对比
- 测试结果(截图百度百科,原文字图片好些效果更佳):
2 这个测试结果的正确率相当高
Contributing
- Fork it ( https://github.com/rudyboy/baidu_ocr/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
LICENSE
The MIT License (MIT) Copyright (c) 2015 rudyboy
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.