Analysing URL's using Google Cloud Vision - Python -


is there anyway can analyse url's using google cloud vision. know how analyse images store locally, can't seem analyse jpg's exist on internet:

import argparse import base64 import httplib2 googleapiclient.discovery import build import collections import time import datetime import pyodbc  time_start = datetime.datetime.now()  def main(photo_file):     '''run label request on single image'''      api_discovery_file = 'https://vision.googleapis.com/$discovery/rest?version=v1'     http = httplib2.http()      service = build('vision', 'v1', http, discoveryserviceurl=api_discovery_file, developerkey=insert api key here)      open(photo_file, 'rb') image:         image_content = base64.b64encode(image.read())         service_request = service.images().annotate(             body={                 'requests': [{                     'image': {                         'content': image_content                     },                     'features': [{                         'type': 'logo_detection',                         'maxresults': 10,                     }]                 }]             })         response = service_request.execute()          try:             logo_description = response['responses'][0]['logoannotations'][0]['description']             logo_description_score = response['responses'][0]['logoannotations'][0]['score']             print logo_description             print logo_description_score          except keyerror:             print "logo nonexistent"              pass          print time_start  if __name__ == '__main__':     main("c:\users\kvadher\desktop\image_file1.jpg") 

is there anyway can analyse url , answer whether there logo's in them?

i figured out how it. re-wrote code , added used urllib open image , passed through base64 , google cloud vision logo recognition api:

import argparse import base64 import httplib2 googleapiclient.discovery import build import collections import time import datetime import pyodbc import urllib import urllib2 time_start = datetime.datetime.now()   #api , developer key details api_discovery_file = 'https://vision.googleapis.com/$discovery/rest?version=v1' http = httplib2.http() service = build('vision', 'v1', http, discoveryserviceurl=api_discovery_file, developerkey=insert developer key here)  url = "http://www.lcbo.com/content/dam/lcbo/products/218040.jpg/jcr:content/renditions/cq5dam.web.1280.1280.jpeg" opener = urllib.urlopen(url)  #with open(photo_file) image: image_content = base64.b64encode(opener.read()) service_request = service.images().annotate(     body={         'requests': [{             'image': {                 'content': image_content             },             'features': [{                 'type': 'logo_detection',                 'maxresults': 10,             }]         }]     }) response = service_request.execute()  try:     logo_description = response['responses'][0]['logoannotations'][0]['description']     logo_description_score = response['responses'][0]['logoannotations'][0]['score']     print logo_description     print logo_description_score  except keyerror:     print "logo nonexistent"      pass      print time_start 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -