You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed some unexpected behavior, when I was trying to make the selection box persistant.
I used the return_Type="both" option in the st_cropper function to get the coordinates, than stored them is an st_session_state variable, with the goal to use them in the default_coords option.
I also had to do some conversions to match the output coordinates with the input coordinates in convert_coordinates_dict_to_tuple.
When I do this the selection box seems to be stuck every second time I move the box. I expected the cropper function to take the stored coordinates as the coordinates to place the box. So I'm kind of stuck here and have no idea, why it works every second time.
Background: I do some manipulations on the image thats meant to be cropped. When the image changes, the st_cropper functions gets called again and resets the coordinates.
Also I'm kind if new to programming, so it might be that I just overlooked something here. Also this is my first Issue on GitHub. So just let me know if I could improve.
Thank you for your support.
Here is the code example to reproduce the behavior:
importstreamlitasstfromstreamlit_cropperimportst_cropperfromPILimportImagedefconvert_coordinates_dict_to_tuple(data):
left=data['left'] +2top=data['top'] +2width=data['width']
height=data['height']
right=left+width+4bottom=top+height+4return (left, right, top, bottom)
# Upload an image and set some options for demo purposesst.header("Cropper Demo")
image=st.file_uploader("Upload Your Image", type=['jpg', 'png', 'jpeg'], accept_multiple_files=False)
ifimage:
img_file=Image.open(image)
# check if coordinates already available, if not use cropper box algorythmif'coordinates'inst.session_state:
print("coordinates already available")
print("before moving",st.session_state.coordinates)
cropped_img, st.session_state.coordinates=st_cropper(img_file, realtime_update=True, box_color='#0000FF', return_type="both", default_coords=st.session_state.coordinates)
st.session_state.coordinates=convert_coordinates_dict_to_tuple(st.session_state.coordinates)
print("after moving ", st.session_state.coordinates)
else:
print("no coordinates")
cropped_img, st.session_state.coordinates=st_cropper(img_file, realtime_update=True, box_color='#0000FF', return_type="both")
st.session_state.coordinates=convert_coordinates_dict_to_tuple(st.session_state.coordinates)
print("new coordinates", st.session_state.coordinates)
st.image(cropped_img)
The text was updated successfully, but these errors were encountered:
Hello streamlit-cropper team,
I noticed some unexpected behavior, when I was trying to make the selection box persistant.
I used the
return_Type="both"
option in thest_cropper
function to get the coordinates, than stored them is anst_session_state
variable, with the goal to use them in thedefault_coords
option.I also had to do some conversions to match the output coordinates with the input coordinates in
convert_coordinates_dict_to_tuple
.When I do this the selection box seems to be stuck every second time I move the box. I expected the cropper function to take the stored coordinates as the coordinates to place the box. So I'm kind of stuck here and have no idea, why it works every second time.
Background: I do some manipulations on the image thats meant to be cropped. When the image changes, the
st_cropper
functions gets called again and resets the coordinates.Also I'm kind if new to programming, so it might be that I just overlooked something here. Also this is my first Issue on GitHub. So just let me know if I could improve.
Thank you for your support.
Here is the code example to reproduce the behavior:
The text was updated successfully, but these errors were encountered: