facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
47.87k stars 5.66k forks source link

How can I use python to achieve the effect demonstrated by the demo, so that the mask of the corresponding area appears when hovering? #727

Closed Bruce337f closed 5 months ago

Bruce337f commented 7 months ago

When I use the demo for image segmentation: Demo url: [https://segment-anything.com/demo]() It shows very good results.

But when I use SamAutomaticMaskGenerator and SamPredictor, I need to enter each coordinate separately to obtain the mask map of the corresponding area.But this is too inefficient.

Is there any way to return the corresponding coordinates and mask map of the divided area, or can it only be achieved through the front end and Vue?

This is the best practice for image segmentation!

heyoeyo commented 7 months ago

This repo contains an example of hovering and getting a masked area, inside of the demo folder. It also uses the browser/javascript, but uses react, in case that's something you're familiar with.

In general that hover + masking effect will require some sort of UI library, and can be a lot of code to implement. If you wanted to do it directly from Python, then OpenCV actually contains enough UI support (through window callbacks) to do it, but it's a lot of fiddly code to set up. Using the browser for handling UI is likely the most popular option, and there are existing repos that do this (like sam-webui) which might be worth checking out.

Bruce337f commented 5 months ago

Sorry I just saw your answer now,

Thanks for your suggestion, I will try it!!