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([0], "rb").read)

# Stuff we need
api_key = "<YOUR_GOOGLE_API_KEY>"
content_type = "Content-Type: application/json"
url = "{api_key}"
data = {
  "requests": [
      "image": {
        "content": b64_data
      "features": [
          "type": "TEXT_DETECTION",
          "maxResults": 1

# Make the request
url = URI(url)
req =, initheader = {'Content-Type' =>'application/json'})
req.body = data
res =, 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"]

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: []( - New Google Spreadsheet: []( - New Google Presentation: [](

Have fun documenting :)

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

Price at []( 35 US dollars.

Price at []( 99.99 GB pounds. <img style="float:none;text-align:left;"src="" width="320" height="151" alt="chromecast-uk">

What the fuck, Amazon?