Spaces:
Sleeping
Sleeping
Pawel_Mar commited on
Commit ·
7998469
1
Parent(s): 3604c28
code fixes
Browse files
app.py
CHANGED
|
@@ -96,11 +96,13 @@ if APPLICATION_MODE == "Take Picture":
|
|
| 96 |
st.sidebar.image(picture, caption="captured_picture")
|
| 97 |
if st.button("Segment!"):
|
| 98 |
## Function to save image
|
|
|
|
| 99 |
save_uploadedfile(picture)
|
| 100 |
st.sidebar.success("Saved File")
|
| 101 |
# captured_picture_img = os.path.join(parent_media_path, "captured_picture.jpg")
|
|
|
|
| 102 |
st.write("Click on **Clear photo** to retake picture")
|
| 103 |
-
|
| 104 |
st.divider()
|
| 105 |
|
| 106 |
elif APPLICATION_MODE == "Upload Picture":
|
|
@@ -133,10 +135,12 @@ results = model(img_file)
|
|
| 133 |
img = cv2.imread(img_file)
|
| 134 |
names_list = []
|
| 135 |
for result in results:
|
| 136 |
-
boxes = result.boxes.cpu().numpy()
|
| 137 |
# segmentation
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
|
| 141 |
numCols = len(masks)
|
| 142 |
if numCols > 0:
|
|
@@ -145,6 +149,7 @@ for result in results:
|
|
| 145 |
print(f"Number of Boxes found: {numCols}")
|
| 146 |
st.warning("Unable to id Distinct items - Please retry with a clearer Image")
|
| 147 |
for mask in masks:
|
|
|
|
| 148 |
mask = cv2.resize(mask, (w, h))
|
| 149 |
img = overlay(img, mask, color=(0, 255, 0), alpha=0.3)
|
| 150 |
# st.image(rect)
|
|
|
|
| 96 |
st.sidebar.image(picture, caption="captured_picture")
|
| 97 |
if st.button("Segment!"):
|
| 98 |
## Function to save image
|
| 99 |
+
|
| 100 |
save_uploadedfile(picture)
|
| 101 |
st.sidebar.success("Saved File")
|
| 102 |
# captured_picture_img = os.path.join(parent_media_path, "captured_picture.jpg")
|
| 103 |
+
img_file = os.path.join(parent_media_path, "captured_picture.jpg")
|
| 104 |
st.write("Click on **Clear photo** to retake picture")
|
| 105 |
+
|
| 106 |
st.divider()
|
| 107 |
|
| 108 |
elif APPLICATION_MODE == "Upload Picture":
|
|
|
|
| 135 |
img = cv2.imread(img_file)
|
| 136 |
names_list = []
|
| 137 |
for result in results:
|
| 138 |
+
# boxes = result.boxes.cpu().numpy()
|
| 139 |
# segmentation
|
| 140 |
+
if result.masks:
|
| 141 |
+
masks = result.masks.data.cpu().numpy() # masks, (N, H, W)
|
| 142 |
+
else:
|
| 143 |
+
masks = []
|
| 144 |
|
| 145 |
numCols = len(masks)
|
| 146 |
if numCols > 0:
|
|
|
|
| 149 |
print(f"Number of Boxes found: {numCols}")
|
| 150 |
st.warning("Unable to id Distinct items - Please retry with a clearer Image")
|
| 151 |
for mask in masks:
|
| 152 |
+
h, w, _ = img.shape
|
| 153 |
mask = cv2.resize(mask, (w, h))
|
| 154 |
img = overlay(img, mask, color=(0, 255, 0), alpha=0.3)
|
| 155 |
# st.image(rect)
|