Images API Python with google cloud storage - python

Has someone a working example how to serve images dynamically without Blobstore ? Blobstore is deprecated and I would like to use the Images API in order to crop, resize and serve images which are stored in a google cloud bucket.
At the moment I am using cloud-storage in order to serve images but it was not possible to include the Images API. An example url looks like: https://storage.googleapis.com/orbital-views.appspot.com/blabla2.png?Signature=OHLKMc64WzThGSOU3Rv8MMWz919Pjl%2FYs9Nhw4abqVTX04h4aYniC%2B%2FCtMIeh2stA70KJFdKY1YNuwhBWxDQ4CaiXy0Onn3Fy7tkW1kXw0P5EhDhKQQ27ufgUmOkYxOULo65YkfdW7fVoVeruwdTahk3I94ac4Et3Bvs4nXHW4PQqk31dLVKwYLlTkAvUArg3oiaWsAwAZUKWjfYfw9z8i68QrZubDIB8zski%2FAukPgbT5c%2B8eq8BBPbdkcS1YiL9Wz6Yl1y8VCJxM%2BVMg81IIwCfF9qoJk8Cus20PBXrDYyO7sLvLx5Dy%2BfdMxqmi%2BIZZ2JAhfdjM3oZul5cj%2B9%2Bg%3D%3D&GoogleAccessId=orbital-views%40appspot.gserviceaccount.com&Expires=1504477278
This url is generated using a signed url approach. https://cloud.google.com/storage/docs/access-control/create-signed-urls-program
My aim is to serve an image with the Images API Python.
I tried the following methods but without success.
url = images.get_serving_url(None,filename=’/gs/xxx.appspot.com/’)
blobstore_filename = '/gs{}'.format(filename)
blob_key = blobstore.create_gs_key(blobstore_filename)
url2 = images.get_serving_url(blob_key)

Related

How to upload to google cloud storage an image using Python, without saving the image on my local disk?

storage_client = storage.Client.from_service_account_json('service-account-file.json')
bucket = storage_client.get_bucket(my_bucket)
blob = bucket.blob(my_blob)
blob.upload_from_string(img)
It depends from where you are uploading the image or in better explanation from where you store the image... if you wan to get the image from specific link from the web you can scrape using python module selinium or scrapy depends from where you do ... if you want upload using code you might more read the documentation and use the api key to upload ..
I see your code you may need to use scrapy instead of javascript ...

Where does Custom Vision store training images

I developed an Image Classification Model in CustomVision.AI
I want to download all of the training images used to train the model
I used the training API and was able to retrieve the "HTML" location of all the images however I'd like to use a script to actually download the image to a local drive from the HTML location but am not great with writing scripts as much as running them.
I was also trying to figure out if the images are stored in an azure resource or are custom vision uses its own load storage the images, I'd like to move the images over to an azure blob.
I'm not really a "Programmer" really more of a high-level technology manager but I am comfortable in running scripts and some python code.
I was also trying to figure out if the images are stored in an azure
resource
I suppose it's , cause the images are stored in blob after I checked the image uri. You could use browser developer tool(F12) directly to check the picture uri. The uri format is blob url with image id.
If you want to get all images uri you could use this api: GetTaggedImages and GetUntaggedImages, it will return all images information including the uri.

How to upload images to Blogger Blogspot posts?

I'm using the API given here from Google, https://developers.google.com/blogger/docs/3.0/using . It allows managing the Blogger blogs easily. The problem is that the content that this API accepts is an HTML content. So, I must provide it with.
title
Hello, how are you doing today
...
So, to integrate an image on the post I must upload it to another image uploader service then get the URL and add it to a tag.
In contrast, if I want to upload the image directly to the Blogger UI, the image will be uploaded to Google servers.
My question is: How can I upload images to google servers as the Blogger UI do, then integrate them into my posts?
I too have been trying to work around this issue. What I did in the end is to use Google Drive API to upload the image and then get a shareable URL and embed it in the blog post.
This comes with its drawbacks, the photos are slower to load on the blog and is not accessible to crawlers. But works as far as the requirement is concerned.
If you find any way to get it done through Blogger API or through Google Photos API, please do let me know.

using google storage and google vision API

I have the follow function that passes a image url to google vision service and returns the letters and numbers (characters) in the image. It works fine with general web urls but I'm calling it to access files stored in Google storage, it doesn't work. How can i get this to work? I've looked at examples from googling but I cant work out how to do this?
If its not possible to use google storage, is there a way you can just upload the image rather than storing in on a file system? I have no need for storing the image, all i care about is the returned characters.
def detect_text_uri(uri):
"""Detects text in the file located in Google Cloud Storage or on the Web.
"""
from google.cloud import vision
client = vision.ImageAnnotatorClient()
image = vision.types.Image()
image.source.image_uri = uri
image.source.gcs_image_uri = uri
response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')
for text in texts:
print('\n"{}"'.format(text.description))
vertices = (['({},{})'.format(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices])
print('bounds: {}'.format(','.join(vertices)))
return texts
{
This line doesn't work which should read an image I've placed in google storage, all thats returned is a blank responce:
detect_text_uri("'source': {'image_uri': 'gs://ocr_storage/meter_reader.jpg'}")
This line works fine :
detect_text_uri('https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Transparent_Electricity_Meter_found_in_Israel.JPG/220px-Transparent_Electricity_Meter_found_in_Israel.JPG')
Your function is just expecting the gcs uri
detect_text_uri('gs://ocr_storage/meter_reader.jpg')
What that function is waiting for, is the URI from google storage. But before running that cell you need to log in with the json file which contains your credentials:
os.environ['GOOGLE_APPLICATION_CREDENTIALS']=r"credentials.json"
You can use a similar function to read text from a local image.
The code is in this link: https://cloud.google.com/vision/docs/ocr#vision_text_detection_gcs-python

obtaining the url of a video with its blob key

I tried the code below to get the serving url for a video saved on app engine's cloud storage. It threw TransformationError.
public_url = images.get_serving_url(blob_key)
I'm using python 2.7. Is there a solution?
The images API is for processing photos/still images, not videos. Feeding it a video is very likely the reason why you're getting TransformationError.
It is possible to serve/stream videos as well, plenty of related SO material: https://stackoverflow.com/search?q=[google-app-engine]+video+streaming

Categories