Skip to content

Commit

Permalink
retuning all values recognized by API in web and label recognition in…
Browse files Browse the repository at this point in the history
… an array to be used in an alg to compare for similarities and read only the similar ones
  • Loading branch information
NadaRadwan committed Feb 18, 2018
1 parent 293f935 commit c8f7f52
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
Binary file modified __pycache__/getImage.cpython-36.pyc
Binary file not shown.
Binary file modified snapShot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 28 additions & 30 deletions testAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,37 @@
from getImage import capture
from textToSpeech import speak

def sendWebRequest(readType, image_url):
def sendWebRequest(image_url):
url = 'https://vision.googleapis.com/v1p1beta1/images:annotate?key=AIzaSyC5FQW1UL-jZ9xq7ibfh1ZcfCP_6G0XpUA'
if readType == "text":
type = "TEXT_DETECTION"
elif readType == "image":
type = "WEB_DETECTION"
elif readType == "label":
type = "LABEL_DETECTION"
types = ["WEB_DETECTION", "LABEL_DETECTION"]
v_aReadings=[]

data = '''{
"requests": [
{
"image": {
"content": "'''+ image_url + '''"
},
"features": [
# send request to google vision api to get WEB_DETECTION and LABEL_DETECTION
for type in types:
data = '''{
"requests": [
{
"type": "'''+ type + '''"
"image": {
"content": "'''+ image_url + '''"
},
"features": [
{
"type": "'''+ type + '''"
}
]
}
]
}
]
}'''
}'''
response = requests.post(url, data=data)

print (data)
response = requests.post(url, data=data)
if(response.ok):
jData = json.loads(response.content)
# print (jData)
if readType == "text":
return (jData['responses'][0]['textAnnotations'][0]['description'])
elif readType == "image":
return (jData['responses'][0]['webDetection']['webEntities'][0]['description'])
elif readType == "label":
return (jData['responses'][0]['labelAnnotations'][0]['description']+ " and "+jData['responses'][0]['labelAnnotations'][2]['description'])
if type == "WEB_DETECTION":
v_aReadings+=(jData['responses'][0]['webDetection']['webEntities'])
elif type == "LABEL_DETECTION":
v_aReadings+=(jData['responses'][0]['labelAnnotations'])

return v_aReadings

if __name__ == '__main__':
capture()
Expand All @@ -56,6 +51,9 @@ def sendWebRequest(readType, image_url):
length = len(encoded_image_string)

clean_string = encoded_image_string[2:(length-1)]
image_desc = sendWebRequest("label", clean_string)
print (image_desc)
speak("You are looking at "+ image_desc)
v_aReadings = sendWebRequest(clean_string)

for i in v_aReadings:
print (i['description'])
# print (image_desc)
# speak("You are looking at "+ image_desc)

0 comments on commit c8f7f52

Please sign in to comment.