Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fedingo/MCPS-FridgePI
Browse files Browse the repository at this point in the history
  • Loading branch information
silviaseverini committed May 25, 2018
2 parents a477d44 + 4d91723 commit 037452c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
9 changes: 9 additions & 0 deletions WebServer/ImageRec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Mask_RCNN.model as modellib
import Mask_RCNN.coco as coco
import Mask_RCNN.visualize as visualize
import os.path

class InferenceConfig(coco.CocoConfig):
# Set batch size to 1 since we'll be running inference on
Expand Down Expand Up @@ -29,6 +31,9 @@ class ImageRec:
def __init__(self):
model_path = "Mask_RCNN/mask_rcnn_coco.h5"

if not os.path.isfile(model_path):
raise ValueError(500, "Mask-RCNN missing image segmentation model")

configuration = InferenceConfig()

# Create model object in inference mode.
Expand All @@ -44,6 +49,10 @@ def recognize(self, image):
result = self.model.detect([image], verbose=1)[0]
result['objects'] = []

r = result
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'],
self.class_names, r['scores'])

for i in result['class_ids']:
result['objects'].append(self.class_names[i])

Expand Down
10 changes: 7 additions & 3 deletions WebServer/Mask_RCNN/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import matplotlib.lines as lines
from matplotlib.patches import Polygon
import IPython.display
from PIL import Image

import utils
import Mask_RCNN.utils


############################################################
Expand Down Expand Up @@ -143,8 +144,11 @@ def display_instances(image, boxes, masks, class_ids, class_names,
p = Polygon(verts, facecolor="none", edgecolor=color)
ax.add_patch(p)
ax.imshow(masked_image.astype(np.uint8))
plt.show()

im = Image.fromarray(masked_image.astype(np.uint8))
im.save("received.jpeg")
#plt.show()
#plt.imsave(fname = "matplot.jpg", arr = masked_image.astype(np.uint8))


def draw_rois(image, rois, refined_rois, mask, class_ids, class_names, limit=10):
"""
Expand Down
6 changes: 5 additions & 1 deletion WebServer/Recipes_Finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def findRecipes(username, password, max_results):
ingred_params = ""

for item in ingredients:
ingred_params += item + ","
string = item.replace(' ','')
ingred_params += string + ","

ingred = ingred_params[:-1]

Expand All @@ -33,3 +34,6 @@ def findRecipes(username, password, max_results):
response = urlopen(request).read().decode()

return json.loads(response)['recipes'][0:max_results]


# http://food2fork.com/api/search?key=42fdbda9d0108cfcc9793dcc8051cd7f&q=tuna,beans,pasta

0 comments on commit 037452c

Please sign in to comment.