Giter Club home page Giter Club logo

ocr_space's Introduction

OCR.SPACE Gem Version

OcrSpace

Simple API wrapper for OCR.Space, An awesome free API for converting images to text. Register here for free api key.

Installation

Add this line to your application's Gemfile:

gem 'ocr_space'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ocr_space

Hosted at rubygems.org

ENV Variables (Optional)

Setting env variables with API key is optional but for command line interface to work you will have to set ENV variable 'ocr_api_key' to your API key. For more details on the command line interface, scroll to the bottom of this page.

$ export ocr_api_key='YOUR API KEY'

Usage

Nicola Tesla

Instantiate OcrSpace resource with API key

require 'ocr_space'

resource = OcrSpace::Resource.new(apikey: "YOUR API KEY")
#By default it picks up ocr_api_key='YOUR API KEY' from your env variables

To convert images from URL

result = resource.convert url: "http://bit.ly/2ih9aXt"

puts result
=>  #[{"TextOverlay"=>{"Lines"=>[], "HasOverlay"=>false, "Message"=>"Text overlay is not provided as it is not requested"}, "FileParseExitCode"=>1, "ParsedText"=>"If you want to find the secrets of the \r\nuniverse, think in terms of energy, \r\nfrequency and vibration. \r\nAZ QUOTES \r\n", "ErrorMessage"=>"", "ErrorDetails"=>""}]

result = resource.clean_convert url: "http://bit.ly/2ih9aXt"

puts result

=> #If you want to find the secrets of the universe, think in terms of energy, frequency and vibration. AZ QUOTES

To convert images from file upload

result = resource.convert file: "/Users/suyesh/Desktop/nicola_tesla.jpg"

puts result #Raw result

=>  #{"TextOverlay"=>{"Lines"=>[], "HasOverlay"=>false, "Message"=>"Text overlay is not provided as it is not requested"}, "FileParseExitCode"=>1, "ParsedText"=>"If you want to find the secrets of the \r\nuniverse, think in terms of energy, \r\nfrequency and vibration. \r\nAZ QUOTES \r\n", "ErrorMessage"=>"", "ErrorDetails"=>""}

result = resource.clean_convert file: "/Users/suyesh/Desktop/nicola_tesla.jpg"

puts result

=> #If you want to find the secrets of the universe, think in terms of energy, frequency and vibration. AZ QUOTES

Command line interface BONUS

You can run ocr_space through shell to get quick result from a image using file path or URL.

$ ocr_space /Users/suyesh/Desktop/nicola_tesla.jpg

=> If you want to find the secrets of the universe, think in terms of energy, frequency and vibration. AZ QUOTES

Optional

You can also pass in Optional attributes

isOverlayRequired:
#[Optional] Default = False Allows you to specify if the image/pdf text overlay is required. Overlay could be #used to show the text over the image

language:
#Czech = ce; Danish = dan; Dutch = dut; English = eng; Finnish = fin; French = fre; German = ger;Hungarian=hun;
#Italian = ita; Norwegian = nor; Polish = pol; Portuguese = por; Spanish = spa; Swedish = swe; #ChineseSimplified = chs; Greek = gre; Japanese = jpn; Russian = rus; Turkish = tur; ChineseTraditional = cht; #Korean = kor

ocr_space's People

Contributors

pschfr avatar suyesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ocr_space's Issues

Problem with convert images from file upload

require 'ocr_space'

resource = OcrSpace::Resource.new(apikey: "MyApiKey")   #My actual api key

results = resource.clean_convert file: "/Users/Example/Desktop/image.jpg"  #the path is correct
puts results
Traceback (most recent call last):
        1: from ./ruby.rb:5:in `<main>'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ocr_space-2.3.7/lib/ocr_space/convert.rb:33:in `clean_convert': undefined method `[]' for nil:NilClass (NoMethodError)

I've got some problems when I try to convert an image from file upload, but when I convert it from url it works perfectly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.