I am accepting an image from the user via a streamlit interface. However, I need to crop the image based on certain values. The image is being accepted correctlyThis is my current code to accept the image and pass it to another function where I crop it:
uploaded_image = st.file_uploader("Choose an Image File", type=['jpg', 'jpeg', 'png'])
if uploaded_image is not None:
with open(uploaded_image.name, "wb") as img:
img.write(uploaded_image.getbuffer())
im_name = uploaded_image.name.split(".")[0]
with st.spinner("Processing......."):
text = azure_result(im_name, uploaded_image)
Here's the part of the function where I encounter an error, bbox has valid values.
def azure_result(image_name, image):
img = Image.open(image)
img2 = img.crop((bbox[-1][0], bbox[-1][1], bbox[-1][4], bbox[-1][5]))
The error: File "C:\Repos/frai-main\text_detector.py", line 156, in azure_result img2 = image.crop((bbox[-1][0], bbox[-1][1], bbox[-1][4], bbox[-1][5])) AttributeError: 'UploadedFile' object has no attribute 'crop'
How do I successfully crop the passed image? I'm open to using any alternative to PIL as well.
What I have tried:
Tried using PIL to crop 'image' directly, same error as with using .open() and 'img'.