Analysing URL's using Google Cloud Vision - Python
Question: Is there anyway I can analyse URL's using Google Cloud Vision. I know how to
analyse images that I store locally, but I can't seem to analyse jpg's that
exist on the internet:

    
    
    import argparse
    import base64
    import httplib2
    from googleapiclient.discovery import build
    import collections
    import time
    import datetime
    import pyodbc
    
    time_start = datetime.datetime.now()
    
    def main(photo_file):
        '''Run a label request on a 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)
    
        with open(photo_file, 'rb') as 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 I can analyse a URL and get an answer as to whether there are
any logo's in them?


Answer: I figured out how to do it. Re-wrote my code and added used urllib to open the
image and then I passed it through base64 and the google cloud vision logo
recognition api:

    
    
    import argparse
    import base64
    import httplib2
    from googleapiclient.discovery import build
    import collections
    import time
    import datetime
    import pyodbc
    import urllib
    import urllib2
    time_start = datetime.datetime.now()
    
    
    #API AND 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) as 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
    

