Skip to content

Commit 082a7b7

Browse files
authored
Sort out bgr rgb problem in samples (#270)
* Sort out bgr rgb problem in samples * Add a label for samples * Fix ruff
1 parent 060f658 commit 082a7b7

File tree

9 files changed

+20
-14
lines changed

9 files changed

+20
-14
lines changed

.github/labeler.yml

+5
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ build:
2929
- ".pre-commit-config.yaml"
3030
- "pyproject.toml"
3131
- "**/CMakeLists.txt"
32+
33+
samples:
34+
- changed-files:
35+
- any-glob-to-any-file:
36+
- examples/**

examples/cpp/asynchronous_api/main.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <iomanip>
1313
#include <iostream>
1414
#include <opencv2/core.hpp>
15-
#include <opencv2/imgproc.hpp>
15+
#include <opencv2/imgcodecs.hpp>
1616
#include <openvino/openvino.hpp>
1717
#include <stdexcept>
1818
#include <string>
@@ -23,6 +23,8 @@ int main(int argc, char* argv[]) try {
2323
}
2424

2525
cv::Mat image = cv::imread(argv[2]);
26+
cv::cvtColor(image, image, cv::COLOR_BGR2RGB);
27+
2628
if (!image.data) {
2729
throw std::runtime_error{"Failed to read the image"};
2830
}

examples/cpp/synchronous_api/main.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
#include <iomanip>
1414
#include <iostream>
1515
#include <opencv2/core.hpp>
16-
#include <opencv2/highgui.hpp>
17-
#include <opencv2/imgproc.hpp>
16+
#include <opencv2/imgcodecs.hpp>
1817
#include <openvino/openvino.hpp>
1918
#include <stdexcept>
2019
#include <string>
@@ -25,6 +24,8 @@ int main(int argc, char* argv[]) try {
2524
}
2625

2726
cv::Mat image = cv::imread(argv[2]);
27+
cv::cvtColor(image, image, cv::COLOR_BGR2RGB);
28+
2829
if (!image.data) {
2930
throw std::runtime_error{"Failed to read the image"};
3031
}

examples/python/asynchronous_api/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def main():
1414
if len(sys.argv) != 2:
1515
raise RuntimeError(f"Usage: {sys.argv[0]} <path_to_image>")
1616

17-
image = cv2.imread(sys.argv[1])
17+
image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB)
1818
if image is None:
1919
raise RuntimeError("Failed to read the image")
2020

examples/python/serving_api/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def main():
1414
if len(sys.argv) != 2:
1515
raise RuntimeError(f"Usage: {sys.argv[0]} <path_to_image>")
1616

17-
image = cv2.imread(sys.argv[1])
17+
image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB)
1818
if image is None:
1919
raise RuntimeError("Failed to read the image")
2020

examples/python/synchronous_api/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def main():
1515
if len(sys.argv) != 2:
1616
raise RuntimeError(f"Usage: {sys.argv[0]} <path_to_image>")
1717

18-
image = cv2.imread(sys.argv[1])
18+
image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB)
1919
if image is None:
2020
raise RuntimeError("Failed to read the image")
2121

examples/python/visual_prompting/run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
parser.add_argument("prompts", nargs="+", type=int)
2727
args = parser.parse_args()
2828

29-
image = cv2.imread(args.image)
29+
image = cv2.cvtColor(cv2.imread(args.image), cv2.COLOR_BGR2RGB)
3030
if image is None:
3131
raise RuntimeError("Failed to read the image")
3232

@@ -47,7 +47,7 @@ def main():
4747
masked_img = np.where(result.processed_mask[i][..., None], colors[i], image)
4848
image = cv2.addWeighted(image, 0.2, masked_img, 0.8, 0)
4949

50-
cv2.imwrite("sam_result.jpg", image)
50+
cv2.imwrite("sam_result.jpg", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
5151

5252

5353
if __name__ == "__main__":

examples/python/visualization/run.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import argparse
77
from argparse import Namespace
88

9-
import cv2
109
import numpy as np
1110
from PIL import Image
1211

@@ -19,8 +18,7 @@ def main(args: Namespace):
1918

2019
model = Model.create_model(args.model)
2120

22-
image_array = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
23-
predictions = model(image_array)
21+
predictions = model(np.array(image))
2422
visualizer = Visualizer()
2523

2624
if args.output:

examples/python/zsl_visual_prompting/run.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def main():
2828
parser.add_argument("-t", "--threshold", type=float, default=0.65)
2929
args = parser.parse_args()
3030

31-
image = cv2.imread(args.image_source)
31+
image = cv2.cvtColor(cv2.imread(args.image_source), cv2.COLOR_BGR2RGB)
3232
if image is None:
3333
raise RuntimeError("Failed to read the source image")
3434

35-
image_target = cv2.imread(args.image_target)
35+
image_target = cv2.cvtColor(cv2.imread(args.image_target), cv2.COLOR_BGR2RGB)
3636
if image_target is None:
3737
raise RuntimeError("Failed to read the target image")
3838

@@ -64,7 +64,7 @@ def main():
6464
image_target, prompt_point, radius=0, color=(0, 0, 255), thickness=5
6565
)
6666

67-
cv2.imwrite("zsl_sam_result.jpg", image_target)
67+
cv2.imwrite("zsl_sam_result.jpg", cv2.cvtColor(image_target, cv2.COLOR_RGB2BGR))
6868

6969

7070
if __name__ == "__main__":

0 commit comments

Comments
 (0)