需安装gem httpclient
http://www.newocr.com 挺不错的,不过识别不会太准确
使用 ruby xxx.rb demo.jpg
1 #!/usr/local/bin/ruby
2
3 require "rubygems"
4 require "httpclient"
5
6 res = HTTPClient.post("http://www.newocr.com/process.php", { :action => "/process.php","userfile"=> File.new(ARGV[0]), "l" => "eng", "r" => "0" } )
7
8 url = res.send("header").inspect.scan(/http\:\/\/[a-z 0-9 A-Z \. \/ \-]+[^\"]/).first
9
10 code = url.scan(/([0-9 a-z A-Z]*)\-/).first.first
11
12 result = HTTPClient.get("http://www.newocr.com/eng-0-1-" + code + ".txt")
13
14 p result.body
2
3 require "rubygems"
4 require "httpclient"
5
6 res = HTTPClient.post("http://www.newocr.com/process.php", { :action => "/process.php","userfile"=> File.new(ARGV[0]), "l" => "eng", "r" => "0" } )
7
8 url = res.send("header").inspect.scan(/http\:\/\/[a-z 0-9 A-Z \. \/ \-]+[^\"]/).first
9
10 code = url.scan(/([0-9 a-z A-Z]*)\-/).first.first
11
12 result = HTTPClient.get("http://www.newocr.com/eng-0-1-" + code + ".txt")
13
14 p result.body
转载于:https://blog.51cto.com/andyss/264771