0

Google vision is throwing me the following error on ruby on rails which had me baffled.

Unable to convert "image_path" to an Image

However, I am able to display each image form it's respective path if I use the image_tag method for rails. Please advise as I am new to this, thank you.

<% @uploads.each do |u| %>
<% require "google/cloud/vision"
   vision = Google::Cloud::Vision.new(
   project: "first-ocr-project",
   keyfile: JSON.parse(ENV['GOOGLECLOUD_API_KEY'])
   )

   #Error Unable to convert "image_path" to an Image
   raw_data = vision.image(u.photos[0])
%>

#Able to displays all photos from path
<%= image_tag u.photos[0] %></br>

<% end %>
  • Have you checked what input google requires for doing OCR. Because mostly it takes content instead of direct images. – Mohammed Jamali Apr 03 '18 at 11:06
  • You need to pass the specific filepath as in [this example](https://github.com/GoogleCloudPlatform/ruby-docs-samples/blob/master/vision/quickstart.rb#L26). I would recommend to add some logging to see what does `u.photos[0]` contain. – Guillem Xercavins Apr 10 '18 at 11:54

1 Answers1

0

This means that u.photos[0] doesn't exist in the path you mentioned. The file may not be available for various reasons.

Antony
  • 1,608
  • 1
  • 20
  • 27