-
Notifications
You must be signed in to change notification settings - Fork 564
Open
Description
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
- Search the issues already opened: https://github.com/googleapis/google-cloud-ruby/issues
- Search StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby
If you are still having issues, please be sure to include as much information as possible:
Environment details
- OS: MacOS
- Ruby version: 3.3.6
- Gem name and version: google-cloud-vision (1.5.1)
Steps to reproduce
- Call the API and pass an image
- The API call works and I get the response, but the response time is huge (approx 77 seconds). If I use the Rest API, I get very quick response for the same image.
Code example
require "google/cloud/vision"
require "time"
require "base64"
# Initialize the Vision API client
vision = Google::Cloud::Vision.image_annotator
image_path = Rails.root.join("app", "assets", "images", "cookie.png")
image = File.open(image_path, "rb")
# Cloudinary URL of the image
# image_url = "https://res.cloudinary.com/dqstmox0s/image/upload/v1736173018/cookie_zqljqk.png"
# Start measuring time
start_time = Time.now
# Perform text detection (OCR) on the image from the Cloudinary URL
begin
puts "Calling Vision API..."
# Sending image URL for OCR
response = vision.text_detection image: image
# End measuring time
end_time = Time.now
duration = end_time - start_time
# Print the time it took
puts "OCR request took #{duration} seconds."
# The response contains multiple results in 'text_annotations'
if response.responses.any?
# Get the text annotations from the first response
annotations = response.responses.first.text_annotations
# Print the detected text
raw_text = annotations.first.description
split_text = raw_text.split("\n")
text_to_match = split_text[0]
puts "Detected text:"
p text_to_match
else
puts "No text annotations found."
end
rescue StandardError => e
puts "An error occurred: #{e.message}"
end
Full backtrace
Calling Vision API...
OCR request took 76.694712 seconds.
Detected text:
"Image text"
Could there be some kind of configuration issue? I was thinking which endpoint it's calling (Europe or US), but this seems to work properly with the generic endpoint when using the REST API.
Thanks for your help!
Metadata
Metadata
Assignees
Labels
No labels