I am trying to write an app that will receive image from my system and detcted the faces in the picture, when i upload image and try to process it, i have this error which is referencin streamlit imghdr.
as shown below
File β/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/ScriptRunner.pyβ, line 322, in _run_script
exec(code, module.dict)
File β/root/face/apps.pyβ, line 86, in
main()
File β/root/face/apps.pyβ, line 29, in main
st.image(result)
File β/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/DeltaGenerator.pyβ, line 121, in wrapped_method
return dg._enqueue_new_element_delta(marshall_element, delta_type, last_index)
File β/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/DeltaGenerator.pyβ, line 342, in _enqueue_new_element_delta
rv = marshall_element(msg.delta.new_element)
File β/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/DeltaGenerator.pyβ, line 119, in marshall_element
return method(dg, element, *args, **kwargs)
File β/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/DeltaGenerator.pyβ, line 1492, in image
image, caption, width, element.imgs, clamp, channels, format
File β/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/elements/image_proto.pyβ, line 230, in marshall_images
(data, mimetype) = _normalize_to_bytes(data, width, format)
File β/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/elements/image_proto.pyβ, line 101, in _normalize_to_bytes
ext = imghdr.what(None, data)
File β/usr/lib/python3.6/imghdr.pyβ, line 19, in what
location = file.tell()
this is my code
# import the needed pacakages
import streamlit as st
from PIL import Image # ImageEnhance
import numpy as np
import cv2
config_path = "deploy.prototxt.txt"
weight_path = "res10_300x300_ssd_iter_140000.caffemodel"
def main():
""" This is face recognition place site """
st.title("Face App")
st.text(" Streamlit Face App with Opencv")
activities = ["Image", "Video"]
choice = st.sidebar.selectbox("Select the app to run", activities)
image_file = st.file_uploader("Upload Image", type=['jpg', 'png', 'jpeg'])
if image_file is not None:
image = Image.open(image_file)
st.text("original Image")
st.image(image)
if choice == 'Image':
if st.button("process"):
result = image_face(image)
st.image(result)
if choice == 'Video':
None # video_face()
def image_face(image):
net = cv2.dnn.readNetFromCaffe(config_path, weight_path)
image = np.array(image)
(h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)),
1.0, (300, 300), (104.0, 177.0, 123.0))
net.setInput(blob)
detections = net.forward()
# loop over the detections
for i in range(0, detections.shape[2]):
confidence = detections[0, 0, i, 2]
if confidence > 0.5:
# compute the (x, y)-coordinates of the bounding box for the
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int")
# draw the bounding box of the face along with the associated
text = "{:.2f}%".format(confidence * 100)
y = startY - 10 if startY - 10 > 10 else startY + 10
cv2.rectangle(image, (startX, startY), (endX, endY),
(0, 0, 255), 2)
cv2.putText(image, text, (startX, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
# def video_face():
if __name__ == '__main__':
main()