gradio icon indicating copy to clipboard operation
gradio copied to clipboard

can gr.Image with tool="select" optional return selected box coordinates?

Open lxasqjc opened this issue 2 years ago • 4 comments

  • [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!

lxasqjc avatar Jul 19 '22 22:07 lxasqjc

Not at the moment, but this is something we may consider the in the future!

abidlabs avatar Jul 20 '22 02:07 abidlabs

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 :)

lxasqjc avatar Jul 20 '22 09:07 lxasqjc

We'll keep you updated after the next sprint planning when we prioritize our issues.

aliabid94 avatar Jul 20 '22 10:07 aliabid94

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.

syu-kwsk avatar Sep 09 '22 00:09 syu-kwsk

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

ListIndexOutOfRange avatar Feb 21 '23 11:02 ListIndexOutOfRange

how about this function? @aliabid94

AItechnology avatar Apr 26 '23 08:04 AItechnology

Has this feature been implemented yet? It's quite important in some deep learning task~

lizhogn avatar Jul 13 '23 06:07 lizhogn

I made something similiar to bounding box for now: #2316#issuecomment-1630058156

joytsay avatar Jul 14 '23 07:07 joytsay

We have AnnotatedImage not certain we need this.

pngwn avatar Nov 20 '23 14:11 pngwn