Skip to content
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

Sort out bgr rgb problem in samples #270

Merged
merged 3 commits into from
Feb 24, 2025
Merged
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
5 changes: 5 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ build:
- ".pre-commit-config.yaml"
- "pyproject.toml"
- "**/CMakeLists.txt"

samples:
- changed-files:
- any-glob-to-any-file:
- examples/**
4 changes: 3 additions & 1 deletion examples/cpp/asynchronous_api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <iomanip>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <openvino/openvino.hpp>
#include <stdexcept>
#include <string>
Expand All @@ -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"};
}
Expand Down
5 changes: 3 additions & 2 deletions examples/cpp/synchronous_api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include <iomanip>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <openvino/openvino.hpp>
#include <stdexcept>
#include <string>
Expand All @@ -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"};
}
Expand Down
2 changes: 1 addition & 1 deletion examples/python/asynchronous_api/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
if len(sys.argv) != 2:
raise RuntimeError(f"Usage: {sys.argv[0]} <path_to_image>")

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")

Expand Down
2 changes: 1 addition & 1 deletion examples/python/serving_api/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
if len(sys.argv) != 2:
raise RuntimeError(f"Usage: {sys.argv[0]} <path_to_image>")

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")

Expand Down
2 changes: 1 addition & 1 deletion examples/python/synchronous_api/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
if len(sys.argv) != 2:
raise RuntimeError(f"Usage: {sys.argv[0]} <path_to_image>")

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")

Expand Down
4 changes: 2 additions & 2 deletions examples/python/visual_prompting/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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__":
Expand Down
4 changes: 1 addition & 3 deletions examples/python/visualization/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import argparse
from argparse import Namespace

import cv2
import numpy as np
from PIL import Image

Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions examples/python/zsl_visual_prompting/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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__":
Expand Down
Loading