-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestimato_gcp.py
40 lines (28 loc) · 1.1 KB
/
estimato_gcp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from picamera import PiCamera
import io
import google.auth
from google.cloud import vision
from fuzzywuzzy import process
from fuzzywuzzy import fuzz
import time
camera = PiCamera()
list_of_vegetables = ["onion", "tomato", "bell pepper", "cucumber", "lemon"]
FUZZY_THRESHOLD = 60
def findMostProbableVegetable(labels):
for label in labels:
print label.description," ",label.score
extractedVegetable = process.extractOne(label.description, list_of_vegetables, scorer=fuzz.token_sort_ratio)
if (extractedVegetable[1] > FUZZY_THRESHOLD):
return extractedVegetable[0]
return "None"
credentials, project = google.auth.default()
"""Detects labels in the file."""
vision_client = vision.Client(credentials=credentials)
name = str(time.time()).split('.')[0]
image_path = './image_' + name + '.jpg'
camera.capture(image_path)
with io.open(image_path, 'rb') as image_file:
content = image_file.read()
image = vision_client.image(content=content)
labels = image.detect_labels()
print str(findMostProbableVegetable(labels))