diff --git a/CMakeLists.txt b/CMakeLists.txt index b9ff3e3..f1d0d9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/sam.cpp b/sam.cpp index 631d968..c73e657 100644 --- a/sam.cpp +++ b/sam.cpp @@ -314,7 +314,7 @@ cv::Mat Sam::getMask(const std::list& points, const std::list maxContourArea) { maxContourArea = area; - maxContourIndex = i; + maxContourIndex = k; } } if (maxContourArea < minArea) { @@ -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(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(m, n) == 0) { continue; } - auto dst = (int)outImage.at(i, j); + auto dst = (int)outImage.at(m, n); if (dst > 0 && masksAreas[dst - 1] < maxContourArea) { continue; } - outImage.at(i, j) = index; + outImage.at(m, n) = index; numPixels++; } }