4

I am clipping images in Python 2.7 on Windows 10 and would like to send them to Google's Cloud Vision API. For images saved locally, I can send them using the google.cloud python module like this:

                blob.upload_from_filename(filename=path)                        

Documented here

I would rather not save each crop to file, just to send the numpy arrays directly. I could change the numpy arrays to str objects and use

blob.upload_from_string()

but then Cloud Vision API would not be able to read them in my bucket. Is there any way to pipe from python to cloud storage bucket without wasting time/space saving them as an intermediate temporary object?

bw4sz
  • 2,237
  • 2
  • 29
  • 53

2 Answers2

2

Unfortunately there is not. I am sorry!

James
  • 1,928
  • 3
  • 13
  • 30
  • Note that Google Cloud Storage does allow uploading from a stream, but the gcloud python library doesn't currently support doing this. Both boto and github.com/google/apitools support uploading from a stream. – Mike Schwartz Jul 20 '17 at 22:14
0

you can convert your numpy array to json and then

filename = "file_name_required on cloud"
json_object = [] # your array

and then do

blob = BUCKET.blob(filename)
blob.upload_from_string(data=json.dumps(json_object),content_type='application/json')
umang garg
  • 41
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 21 '23 at 11:10