gradio
gradio copied to clipboard
can gr.Image with tool="select" optional return selected box coordinates?
- [Y] I have searched to see if a similar issue already exists.
When using gr.Image cropping and zoom tool, I want it not only to return the cropped region but also the bounding box coordinates, which I can use as input in my personalised function.
Is such a feature available in the current version? If not is it possible to have it?
Many thanks!
Not at the moment, but this is something we may consider the in the future!
Thank you for your reply! Good to know you may consider, any chance to know a rough timescale it may be added will be greatly appreciated :)
We'll keep you updated after the next sprint planning when we prioritize our issues.
Thanks for the question! Yeah, that's what I wanted too. As a programming novice, it's hard for me to solve this. Please developers, please help me.
For anyone interested in this feature, a basic workaround is to retrieve the bounding box coordinates afterward using template matching: assume you have your original image in an image
variable and the cropped output of the gr.Image
component in a cropped_image
variable, you can do:
result = cv2.matchTemplate(cropped_image, image, cv2.TM_CCOEFF_NORMED)
height, width = cropped_image.shape[:2]
top, left = np.unravel_index(result.argmax(), result.shape)
bottom, right = top + height, left + width
how about this function? @aliabid94
Has this feature been implemented yet? It's quite important in some deep learning task~
I made something similiar to bounding box for now: #2316#issuecomment-1630058156
We have AnnotatedImage
not certain we need this.