Skip to content

Commit 49822df

Browse files
Add visualization example for VisionAPI
Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 2bb0423 commit 49822df

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Visualization Example
2+
3+
This example demonstrates how to use the Visualizer in VisionAPI.
4+
5+
## Prerequisites
6+
7+
Install Model API from source. Please refer to the main [README](../../../README.md) for details.
8+
9+
## Run example
10+
11+
To run the example, please execute the following command:
12+
13+
```bash
14+
python run.py --image <path_to_image> --model <path_to_model>.xml --output <path_to_output_image>
15+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Visualization Example."""
2+
3+
# Copyright (C) 2025 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
import argparse
7+
from argparse import Namespace
8+
9+
import cv2
10+
import numpy as np
11+
from PIL import Image
12+
13+
from model_api.models import Model
14+
from model_api.visualizer import Visualizer
15+
16+
17+
def main(args: Namespace):
18+
image = Image.open(args.image)
19+
20+
model = Model.create_model(args.model)
21+
22+
image_array = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
23+
predictions = model(image_array)
24+
visualizer = Visualizer()
25+
26+
if args.output:
27+
visualizer.save(image=image, result=predictions, path=args.output)
28+
else:
29+
visualizer.show(image=image, result=predictions)
30+
31+
32+
if __name__ == "__main__":
33+
parser = argparse.ArgumentParser()
34+
parser.add_argument("--image", type=str, required=True)
35+
parser.add_argument("--model", type=str, required=True)
36+
parser.add_argument("--output", type=str, required=False)
37+
args = parser.parse_args()
38+
main(args)

0 commit comments

Comments
 (0)