I have a code that gets an input - a picture of the game "where is waldo" and outputs the picture with waldo marked. The code works with a drive path to the picture but shows the following problem when I insert the picture itself and not the path:
st.title("Where's Waldo?")
uploaded_picture = st.file_uploader("Upload a picture of the following game: Where's Waldo?", type=['png', 'jpg'])
img = uploaded_picture
img_array = asarray(img)
output_array = np.zeros((int(img.height / 64), int(img.width / 64)))
*it's not the full code it is just the part that doesn't work
When I run the code: AttributeError: 'UploadedFile' object has no attribute 'height'
uploaded picture is the picture from the game and it is obtained from a website created by streamlit.
Thank you for any help!
CodePudding user response:
As shown in the documentation for st.file_uploader
, that widget returns a UploadedFile
class object. Depending on what you would like to do with that object, you have several methods available to you. I would guess that an image processing library wants the raw bytes, which would be:
bytes_data = img.getvalue()
CodePudding user response:
from your code : img = uploaded_picture
img is not a picture object yet. You need to open it by adding,
from PIL import Image
img = Image.open(uploaded_files)
#then you can display it with st.image(img)