Hi all, lately I have a little conundrum because I want my streamlit app to create a bouning box image when I upload an image next to it.
I tested the solution in jupyter notebook and the code works correctly however for some reason it does not draw on the streamlit application.
MY CODE:
uploaded_files = tab3.file_uploader(“Choose a IMG file”, accept_multiple_files=False)
col18,col19 = tab3.columns(2)
if uploaded_files is not None:
image = Image.open(uploaded_files)
col18.image(image, caption=‘Your image’)
facetracker = load_model(‘models/facetracker.h5’)
if uploaded_files is not None:
img = Image.open(uploaded_files)
img = tf.convert_to_tensor(img)
img = tf.image.resize(img,(128,128))
img = img//255
img = img.numpy()
img = img.reshape((1,128,128,3))
yhat = facetracker.predict(img)
img = Image.open(uploaded_files)
height, width = img.size
x = int(yhat[1][0][0] * width * round(width / 128))
y = int(yhat[1][0][1] * height * round(height / 128))
w = int(yhat[1][0][2] * width * round(width / 128))
h = int(yhat[1][0][3] * height * round(height / 128))
draw = ImageDraw.Draw(img)
draw.rectangle([x, y, x+w, y+h], outline="red", width=2)
col19.image(img, caption='Your image with bounding rectangle')
Results on streamlit: