ruby識別圖片中的英文

需安裝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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章