Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

Commit

Permalink
update various
Browse files Browse the repository at this point in the history
  • Loading branch information
robmarkcole committed Jan 3, 2021
1 parent b43df4e commit d88f911
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# deepstack-ui
UI for working with [Deepstack](https://python.deepstack.cc/). Allows uploading an image and performing object detection with Deepstack. The effect of various parameters can be explored, including filtering the classes of object detected, filtering by minimum confidence, and spatial filtering using a region of interest (ROI).
UI for working with [Deepstack](https://python.deepstack.cc/). Allows uploading an image and performing object detection or face recognition with Deepstack. The effect of various parameters can be explored, including filtering the classes of object detected, filtering by minimum confidence, and spatial filtering using a region of interest (ROI).

<p align="center">
<img src="https://github.com/robmarkcole/deepstack-ui/blob/master/usage.png" width="1000">
Expand Down
Binary file added app/couple.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 25 additions & 7 deletions app/deepstack-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
MIN_CONFIDENCE_THRESHOLD = 0.1
MAX_CONFIDENCE_THRESHOLD = 1.0
OBJECT_TEST_IMAGE = "street.jpg"
FACE_TEST_IMAGE = "idris.jpg"
FACE_TEST_IMAGE = "faces.jpg"
FACE = "Face"
OBJECT = "Object"

Expand Down Expand Up @@ -45,6 +45,7 @@ def process_image_object(pil_image, dsobject):
return predictions


@st.cache
def process_image_face(pil_image, dsface):
image_bytes = utils.pil_image_to_byte_array(pil_image)
predictions = dsface.recognize(image_bytes)
Expand All @@ -54,7 +55,7 @@ def process_image_face(pil_image, dsface):
deepstack_mode = st.selectbox("Select Deepstack mode:", [OBJECT, FACE])

if deepstack_mode == FACE:
st.title("Deepstack Face detection & recogntion")
st.title("Deepstack Face recogntion")

img_file_buffer = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
## Process image
Expand All @@ -64,10 +65,6 @@ def process_image_face(pil_image, dsface):
else:
pil_image = Image.open(FACE_TEST_IMAGE)

st.image(
np.array(pil_image), caption=f"Processed image", use_column_width=True,
)

dsface = ds.DeepstackFace(
ip=DEEPSTACK_IP,
port=DEEPSTACK_PORT,
Expand All @@ -76,8 +73,29 @@ def process_image_face(pil_image, dsface):
min_confidence=MIN_CONFIDENCE_THRESHOLD,
)
predictions = process_image_face(pil_image, dsface)
faces = utils.get_faces(predictions, pil_image.width, pil_image.height)

# Draw object boxes
draw = ImageDraw.Draw(pil_image)
for face in faces:
name = face["name"]
confidence = face["confidence"]
box = face["bounding_box"]
box_label = f"{name}"

utils.draw_box(
draw,
(box["y_min"], box["x_min"], box["y_max"], box["x_max"]),
pil_image.width,
pil_image.height,
text=box_label,
color=const.YELLOW,
)
st.image(
np.array(pil_image), caption=f"Processed image", use_column_width=True,
)
st.subheader("All faces")
st.write(utils.get_faces(predictions))
st.write(faces)


elif deepstack_mode == OBJECT:
Expand Down
15 changes: 13 additions & 2 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,26 @@ def get_objects(predictions: list, img_width: int, img_height: int):
return objects


def get_faces(predictions: list):
def get_faces(predictions: list, img_width: int, img_height: int):
"""Return faces info."""
faces = []
decimal_places = 3
for pred in predictions:
box_width = pred["x_max"] - pred["x_min"]
box_height = pred["y_max"] - pred["y_min"]
name = pred["userid"]
confidence = pred["confidence"]
box = {
"height": round(box_height / img_height, decimal_places),
"width": round(box_width / img_width, decimal_places),
"y_min": round(pred["y_min"] / img_height, decimal_places),
"x_min": round(pred["x_min"] / img_width, decimal_places),
"y_max": round(pred["y_max"] / img_height, decimal_places),
"x_max": round(pred["x_max"] / img_width, decimal_places),
}

faces.append(
{"name": name, "confidence": confidence,}
{"name": name, "confidence": confidence, "bounding_box": box,}
)
return faces

Expand Down

0 comments on commit d88f911

Please sign in to comment.