dinglufe / segment-anything-cpp-wrapper

MIT License
221 stars 34 forks source link

How to get all objects in picture without given a point? #10

Closed happybear1015 closed 1 year ago

dinglufe commented 1 year ago

Are you referring to this feature (auto segmentation, Issue #3 )?

cv::Mat maskAuto = sam.autoSegment({10, 10}); // input: number of points each side

Calling function like this can obtain an image where different pixel values belong to different objects.

happybear1015 commented 1 year ago

Are you referring to this feature (auto segmentation, Issue #3 )?

cv::Mat maskAuto = sam.autoSegment({10, 10}); // input: number of points each side

Calling function like this can obtain an image where different pixel values belong to different objects.

thanks for your reply before. I tried it.

But,how to get and save each subject's mask picture,rather than show all masks in original picture. And it's too slow to infer a picture,maybe mobile Sam would be a good choice.

Could you please help me, thanks!

dinglufe commented 1 year ago

The output image of autoSegment has a data type of CV_64FC1, but the actual type information is stored using integers. So you can separate the output image into different layers based on the pixel values.

MobileSAM is indeed much faster and can be directly used in this project by loading its model using Sam::Parameter param("mobile_sam_preprocess.onnx", "mobile_sam.onnx", std::thread::hardware_concurrency());