ryouchinsa / sam-cpp-macos

Segment Anything Model 2 CPP Wrapper for macOS and Ubuntu CPU/GPU
MIT License
76 stars 5 forks source link

multiple boxes #8

Closed sctrueew closed 5 days ago

sctrueew commented 6 days ago

Hi, thank you for your support. When I use multiple boxes, I get unexpected results. However, when using a single box, everything works fine. Could you please help me identify and resolve this issue?

multi boxes: image

a box: image

ryouchinsa commented 5 days ago

Thanks for writing the issue.

We added getMaskBatch() so that you can input multiple boxes and obtain the mask result.

cv::Rect rect1 = cv::Rect(1215 * inputSize.width / imageSize.width,
                            125 * inputSize.height / imageSize.height,
                            508 * inputSize.width / imageSize.width,
                            436 * inputSize.height / imageSize.height);
cv::Rect rect2 = cv::Rect(890 * inputSize.width / imageSize.width,
                          85 * inputSize.height / imageSize.height,
                          315 * inputSize.width / imageSize.width,
                          460 * inputSize.height / imageSize.height);
rects.push_back(rect1);
rects.push_back(rect2);
sam.setRectsLabels(rects, &inputPointValues, &inputLabelValues);
int batchNum = (int)rects.size();
mask = sam.getMaskBatch(inputPointValues, inputLabelValues, batchNum, imageSize);
cv::imwrite("mask_box_batch.png", mask);
inputPointValues.resize(0);
inputLabelValues.resize(0);
rects.resize(0);

david-tomaseti-Vw2HZQ1FGjU-unsplash

mask_box_batch

sctrueew commented 5 days ago

Hi, thank you for the response.