Skip to content

Commit 77eabec

Browse files
authored
Merge pull request #3138 from anzhella-pankratova/segmentation_demo_read_pascal_palette_from_file
segmentation_demo.py: load default Pascal palette from file
2 parents 29873fa + 5a3b4b6 commit 77eabec

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

demos/segmentation_demo/python/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Running the application with the empty list of options yields the usage message
130130
You can use the following command to do inference on CPU on images captured by a camera using a pre-trained network:
131131

132132
```sh
133-
python3 segmentation_demo.py -d CPU -i 0 -m <path_to_model>/semantic-segmentation-adas-0001.xml
133+
python3 segmentation_demo.py -d CPU -i 0 -at segmentation -m <path_to_model>/semantic-segmentation-adas-0001.xml
134134
```
135135

136136
>**NOTE**: If you provide a single image as an input, the demo processes and renders it quickly, then exits. To continuously visualize inference results on the screen, apply the `loop` option, which enforces processing a single image in a loop.
@@ -156,7 +156,7 @@ You can also run this demo with model served in [OpenVINO Model Server](https://
156156
Exemplary command:
157157

158158
```sh
159-
python3 segmentation_demo.py -i 0 -m localhost:9000/models/image_segmentation --adapter ovms
159+
python3 segmentation_demo.py -i 0 -at segmentation -m localhost:9000/models/image_segmentation --adapter ovms
160160
```
161161

162162
## Demo Output

demos/segmentation_demo/python/segmentation_demo.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,14 @@
3939

4040

4141
class SegmentationVisualizer:
42-
pascal_voc_palette = [
43-
(0, 0, 0),
44-
(128, 0, 0),
45-
(0, 128, 0),
46-
(128, 128, 0),
47-
(0, 0, 128),
48-
(128, 0, 128),
49-
(0, 128, 128),
50-
(128, 128, 128),
51-
(64, 0, 0),
52-
(192, 0, 0),
53-
(64, 128, 0),
54-
(192, 128, 0),
55-
(64, 0, 128),
56-
(192, 0, 128),
57-
(64, 128, 128),
58-
(192, 128, 128),
59-
(0, 64, 0),
60-
(128, 64, 0),
61-
(0, 192, 0),
62-
(128, 192, 0),
63-
(0, 64, 128)
64-
]
65-
6642
def __init__(self, colors_path=None):
6743
if colors_path:
6844
self.color_palette = self.get_palette_from_file(colors_path)
6945
log.debug('The palette is loaded from {}'.format(colors_path))
7046
else:
71-
self.color_palette = self.pascal_voc_palette
47+
pascal_palette_path = Path(__file__).resolve().parents[3] /\
48+
'data/palettes/pascal_voc_21cl_colors.txt'
49+
self.color_palette = self.get_palette_from_file(pascal_palette_path)
7250
log.debug('The PASCAL VOC palette is used')
7351
log.debug('Get {} colors'.format(len(self.color_palette)))
7452
self.color_map = self.create_color_map()
@@ -104,7 +82,7 @@ def apply_color_map(self, input):
10482
def render_segmentation(frame, masks, visualiser, resizer, only_masks=False):
10583
output = visualiser.apply_color_map(masks)
10684
if not only_masks:
107-
output = np.floor_divide(frame, 2) + np.floor_divide(output, 2)
85+
output = cv2.addWeighted(frame, 0.5, output, 0.5, 0)
10886
return resizer.resize(output)
10987

11088
def build_argparser():

0 commit comments

Comments
 (0)