From 06ecd281e903f0280c2264d29e3f7f526ebbd412 Mon Sep 17 00:00:00 2001 From: Vladisalv Sovrasov Date: Mon, 24 Feb 2025 23:48:25 +0900 Subject: [PATCH 1/3] Sort out bgr rgb problem in samples --- examples/cpp/asynchronous_api/main.cpp | 4 +++- examples/cpp/synchronous_api/main.cpp | 5 +++-- examples/python/asynchronous_api/run.py | 2 +- examples/python/serving_api/run.py | 2 +- examples/python/synchronous_api/run.py | 2 +- examples/python/visual_prompting/run.py | 4 ++-- examples/python/visualization/run.py | 4 +--- examples/python/zsl_visual_prompting/run.py | 6 +++--- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/cpp/asynchronous_api/main.cpp b/examples/cpp/asynchronous_api/main.cpp index acd361a2..f8edc2cc 100644 --- a/examples/cpp/asynchronous_api/main.cpp +++ b/examples/cpp/asynchronous_api/main.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -23,6 +23,8 @@ int main(int argc, char* argv[]) try { } cv::Mat image = cv::imread(argv[2]); + cv::cvtColor(image, image, cv::COLOR_BGR2RGB); + if (!image.data) { throw std::runtime_error{"Failed to read the image"}; } diff --git a/examples/cpp/synchronous_api/main.cpp b/examples/cpp/synchronous_api/main.cpp index ec4ef869..1f79a035 100644 --- a/examples/cpp/synchronous_api/main.cpp +++ b/examples/cpp/synchronous_api/main.cpp @@ -13,8 +13,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -25,6 +24,8 @@ int main(int argc, char* argv[]) try { } cv::Mat image = cv::imread(argv[2]); + cv::cvtColor(image, image, cv::COLOR_BGR2RGB); + if (!image.data) { throw std::runtime_error{"Failed to read the image"}; } diff --git a/examples/python/asynchronous_api/run.py b/examples/python/asynchronous_api/run.py index 27856080..8385b2a9 100644 --- a/examples/python/asynchronous_api/run.py +++ b/examples/python/asynchronous_api/run.py @@ -14,7 +14,7 @@ def main(): if len(sys.argv) != 2: raise RuntimeError(f"Usage: {sys.argv[0]} ") - image = cv2.imread(sys.argv[1]) + image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB) if image is None: raise RuntimeError("Failed to read the image") diff --git a/examples/python/serving_api/run.py b/examples/python/serving_api/run.py index 3c28b178..99299164 100755 --- a/examples/python/serving_api/run.py +++ b/examples/python/serving_api/run.py @@ -14,7 +14,7 @@ def main(): if len(sys.argv) != 2: raise RuntimeError(f"Usage: {sys.argv[0]} ") - image = cv2.imread(sys.argv[1]) + image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB) if image is None: raise RuntimeError("Failed to read the image") diff --git a/examples/python/synchronous_api/run.py b/examples/python/synchronous_api/run.py index 65e71681..3f3d6806 100755 --- a/examples/python/synchronous_api/run.py +++ b/examples/python/synchronous_api/run.py @@ -15,7 +15,7 @@ def main(): if len(sys.argv) != 2: raise RuntimeError(f"Usage: {sys.argv[0]} ") - image = cv2.imread(sys.argv[1]) + image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB) if image is None: raise RuntimeError("Failed to read the image") diff --git a/examples/python/visual_prompting/run.py b/examples/python/visual_prompting/run.py index 6b7258a7..793e1504 100644 --- a/examples/python/visual_prompting/run.py +++ b/examples/python/visual_prompting/run.py @@ -26,7 +26,7 @@ def main(): parser.add_argument("prompts", nargs="+", type=int) args = parser.parse_args() - image = cv2.imread(args.image) + image = cv2.cvtColor(cv2.imread(args.image), cv2.COLOR_BGR2RGB) if image is None: raise RuntimeError("Failed to read the image") @@ -47,7 +47,7 @@ def main(): masked_img = np.where(result.processed_mask[i][..., None], colors[i], image) image = cv2.addWeighted(image, 0.2, masked_img, 0.8, 0) - cv2.imwrite("sam_result.jpg", image) + cv2.imwrite("sam_result.jpg", cv2.cvtColor(image, cv2.COLOR_RGB2BGR)) if __name__ == "__main__": diff --git a/examples/python/visualization/run.py b/examples/python/visualization/run.py index c31c329f..cea50538 100644 --- a/examples/python/visualization/run.py +++ b/examples/python/visualization/run.py @@ -6,7 +6,6 @@ import argparse from argparse import Namespace -import cv2 import numpy as np from PIL import Image @@ -19,8 +18,7 @@ def main(args: Namespace): model = Model.create_model(args.model) - image_array = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) - predictions = model(image_array) + predictions = model(np.array(image)) visualizer = Visualizer() if args.output: diff --git a/examples/python/zsl_visual_prompting/run.py b/examples/python/zsl_visual_prompting/run.py index d4b4fed1..439c1765 100644 --- a/examples/python/zsl_visual_prompting/run.py +++ b/examples/python/zsl_visual_prompting/run.py @@ -28,11 +28,11 @@ def main(): parser.add_argument("-t", "--threshold", type=float, default=0.65) args = parser.parse_args() - image = cv2.imread(args.image_source) + image = cv2.cvtColor(cv2.imread(args.image_source), cv2.COLOR_BGR2RGB) if image is None: raise RuntimeError("Failed to read the source image") - image_target = cv2.imread(args.image_target) + image_target = cv2.cvtColor(cv2.imread(args.image_target), cv2.COLOR_BGR2RGB) if image_target is None: raise RuntimeError("Failed to read the target image") @@ -64,7 +64,7 @@ def main(): image_target, prompt_point, radius=0, color=(0, 0, 255), thickness=5 ) - cv2.imwrite("zsl_sam_result.jpg", image_target) + cv2.imwrite("zsl_sam_result.jpg", cv2.cvtColor(image_target, cv2.COLOR_RGB2BGR)) if __name__ == "__main__": From 297cfc140b0fb7df0cda799c764ddda63ccaf1ce Mon Sep 17 00:00:00 2001 From: Vladisalv Sovrasov Date: Mon, 24 Feb 2025 23:56:28 +0900 Subject: [PATCH 2/3] Add a label for samples --- .github/labeler.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/labeler.yml b/.github/labeler.yml index 278856a6..65fb6ef0 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -29,3 +29,8 @@ build: - ".pre-commit-config.yaml" - "pyproject.toml" - "**/CMakeLists.txt" + +samples: + - changed-files: + - any-glob-to-any-file: + - examples/** \ No newline at end of file From 62d728b7a55b848dffb4612c4fbe3572bac03770 Mon Sep 17 00:00:00 2001 From: Vladisalv Sovrasov Date: Tue, 25 Feb 2025 00:02:29 +0900 Subject: [PATCH 3/3] Fix ruff --- .github/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index 65fb6ef0..5ce7d831 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -33,4 +33,4 @@ build: samples: - changed-files: - any-glob-to-any-file: - - examples/** \ No newline at end of file + - examples/**