Skip to content

Rename Variables #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ find_package(gflags CONFIG REQUIRED)
add_library(sam_cpp_lib SHARED sam.h sam.cpp)
if (WIN32)
set(onnxruntime_lib ${VCPKG_INSTALLED_DIR}/x64-windows/lib/onnxruntime.lib)
target_include_directories(sam_cpp_lib PRIVATE ${VCPKG_INSTALLED_DIR}/x64-windows/include)
else()
set(onnxruntime_lib ${ONNXRUNTIME_ROOT_DIR}/lib/libonnxruntime.so)
target_include_directories(sam_cpp_lib PRIVATE ${ONNXRUNTIME_ROOT_DIR}/include)
Expand Down
18 changes: 9 additions & 9 deletions sam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ cv::Mat Sam::getMask(const std::list<cv::Point>& points, const std::list<cv::Poi
// Just a poor version of
// https://github.com/facebookresearch/segment-anything/blob/main/notebooks/automatic_mask_generator_example.ipynb
cv::Mat Sam::autoSegment(const cv::Size& numPoints, cbProgress cb, const double iouThreshold,
const double minArea, int* numObjects) const {
const double minArea, int* /* numObjects */) const {
if (numPoints.empty()) {
return {};
}
Expand Down Expand Up @@ -347,11 +347,11 @@ cv::Mat Sam::autoSegment(const cv::Size& numPoints, cbProgress cb, const double

int maxContourIndex = 0;
double maxContourArea = 0;
for (int i = 0; i < contours.size(); i++) {
double area = cv::contourArea(contours[i]);
for (int k = 0; k < contours.size(); k++) {
double area = cv::contourArea(contours[k]);
if (area > maxContourArea) {
maxContourArea = area;
maxContourIndex = i;
maxContourIndex = k;
}
}
if (maxContourArea < minArea) {
Expand All @@ -363,17 +363,17 @@ cv::Mat Sam::autoSegment(const cv::Size& numPoints, cbProgress cb, const double
cv::Rect boundingBox = cv::boundingRect(contours[maxContourIndex]);

int index = masksAreas.size() + 1, numPixels = 0;
for (int i = boundingBox.y; i < boundingBox.y + boundingBox.height; i++) {
for (int j = boundingBox.x; j < boundingBox.x + boundingBox.width; j++) {
if (contourMask.at<uchar>(i, j) == 0) {
for (int m = boundingBox.y; m < boundingBox.y + boundingBox.height; m++) {
for (int n = boundingBox.x; n < boundingBox.x + boundingBox.width; n++) {
if (contourMask.at<uchar>(m, n) == 0) {
continue;
}

auto dst = (int)outImage.at<double>(i, j);
auto dst = (int)outImage.at<double>(m, n);
if (dst > 0 && masksAreas[dst - 1] < maxContourArea) {
continue;
}
outImage.at<double>(i, j) = index;
outImage.at<double>(m, n) = index;
numPixels++;
}
}
Expand Down