Posts for Tag: google

OCR using the open Google Cloud Vision API

Just create a new api key in the developer console, replace it in the code below and it should work. Then you can call "whatever_you_call_the_file.rb /Downloads/some_image_with_text.jpg" and google will OCR-it and the script will print out the recognized text.
require "base64"
require 'net/http'
require 'json'

# Base 64 the input image
b64_data = Base64.encode64(File.open(ARGV[0], "rb").read)

# Stuff we need
api_key = "<YOUR_GOOGLE_API_KEY>"
content_type = "Content-Type: application/json"
url = "https://vision.googleapis.com/v1/images:annotate?key=#{api_key}"
data = {
  "requests": [
    {
      "image": {
        "content": b64_data
      },
      "features": [
        {
          "type": "TEXT_DETECTION",
          "maxResults": 1
        }
      ]
    }
  ]
}.to_json

# Make the request
url = URI(url)
req = Net::HTTP::Post.new(url, initheader = {'Content-Type' =>'application/json'})
req.body = data
res = Net::HTTP.new(url.host, url.port)
res.use_ssl = true

# res.set_debug_output $stderr

detected_text = ""
res.start do |http| 
  puts "Querying Google for image: #{ARGV[0]}"
  resp = http.request(req)
  # puts resp
  json = JSON.parse(resp.body)
  # puts json
  if json && json["responses"] && json["responses"][0]["textAnnotations"] && json["responses"][0]["textAnnotations"][0]["description"]
    detected_text = json["responses"][0]["textAnnotations"][0]["description"]
  end
end

puts "Google says the image is: #{detected_text}"

'Google Drive new document bookmark'

Here's a neat trick: Bookmarks to create all sorts of Google Drive documents. This way you don't have to first access Google Drive and click on new, you can just have the appropriate bookmarks in your browser's toolbar. Just add these links:

- New Google Document: [https://drive.google.com/document/?action=new](https://drive.google.com/document/?action=new) - New Google Spreadsheet: [https://drive.google.com/spreadsheet/?action=new](https://drive.google.com/spreadsheet/?action=new) - New Google Presentation: [https://drive.google.com/presentation/?action=new](https://drive.google.com/presentation/?action=new)

Have fun documenting :)

'Google Chromecast US and UK. What the hell?'

Price at [amazon.com](http://www.amazon.com/Google-Chromecast-Streaming-Media-Player/dp/B00DR0PDNE/ref=sr_1_1?ie=UTF8&qid=1377531080&sr=8-1&keywords=chromcast): 35 US dollars.

Price at [amazon.co.uk](http://www.amazon.co.uk/Google-Chromecast-Streaming-Media-Player/dp/B00DR0PDNE/ref=sr_1_10?ie=UTF8&qid=1377531052&sr=8-10&keywords=chromecast): 99.99 GB pounds. <img style="float:none;text-align:left;"src="http://farm6.staticflickr.com/5349/9600870678_97a990b366_n.jpg" width="320" height="151" alt="chromecast-uk">

What the fuck, Amazon?