Skip to content

Commit c7ae922

Browse files
authored
Merge pull request #59 from Sevenarth/master
Add save to image capability to example
2 parents faa6a87 + fcd0fd3 commit c7ae922

File tree

2 files changed

+53
-23
lines changed
  • perception/camera_obstacle_detection/yolo_v2_tiny/tensorflow_fp32_coco

2 files changed

+53
-23
lines changed

perception/camera_obstacle_detection/yolo_v2_tiny/tensorflow_fp32_coco/README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,33 @@ $ cp ${MODEL_DIR}/model_files/labels.txt ${MODEL_DIR}/example_pipeline/build/
5252
$ cp ${MODEL_DIR}/model_files/anchors.csv ${MODEL_DIR}/example_pipeline/build/
5353
```
5454

55-
run the detection pipeline inside a docker container. X draw calls are forwarded
56-
to the host so the detection results can be displayed in a X11 window.
57-
58-
```bash
59-
$ docker run \
60-
-it --rm \
61-
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
62-
-v ${HOME}/.Xauthority:${HOME}/.Xauthority:rw \
63-
-e XAUTHORITY=${HOME}/.Xauthority \
64-
-e DISPLAY=$DISPLAY \
65-
--net=host \
66-
-v ${MODEL_DIR}:${MODEL_DIR} \
67-
-w ${MODEL_DIR}/example_pipeline/build \
68-
--entrypoint "" \
69-
autoware/model-zoo-tvm-cli:latest \
70-
./example_pipeline
71-
```
55+
run the detection pipeline inside a docker container. The output result can be obtained in two ways:
56+
- **Save as an image**: saves the result of the pipeline as an image file in the build directory, the filename `output.jpg` can be changed in the command if needed:
57+
```bash
58+
$ docker run \
59+
-it --rm \
60+
--net=host \
61+
-v ${MODEL_DIR}:${MODEL_DIR} \
62+
-w ${MODEL_DIR}/example_pipeline/build \
63+
--entrypoint "" \
64+
autoware/model-zoo-tvm-cli:latest \
65+
./example_pipeline output.jpg
66+
```
67+
- **Display in a X11 window**: X draw calls are forwarded to the host so the detection results can be displayed in a X11 window.
68+
```bash
69+
$ docker run \
70+
-it --rm \
71+
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
72+
-v ${HOME}/.Xauthority:${HOME}/.Xauthority:rw \
73+
-e XAUTHORITY=${HOME}/.Xauthority \
74+
-e DISPLAY=$DISPLAY \
75+
--net=host \
76+
-v ${MODEL_DIR}:${MODEL_DIR} \
77+
-w ${MODEL_DIR}/example_pipeline/build \
78+
--entrypoint "" \
79+
autoware/model-zoo-tvm-cli:latest \
80+
./example_pipeline
81+
```
7282

7383
For more information about getting the TVM docker image, see the TVM CLI
7484
[documentation](../../../../scripts/tvm_cli/README.md).

perception/camera_obstacle_detection/yolo_v2_tiny/tensorflow_fp32_coco/example_pipeline/main.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
2+
// Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
33
//
44
// SPDX-License-Identifier: Apache-2.0
55
//
@@ -60,6 +60,17 @@
6060
#define DISPLAY_WINDOW_NAME "YOLO Output"
6161

6262
int main(int argc, char const *argv[]) {
63+
bool save_as_image = false;
64+
65+
if (argc == 2) {
66+
save_as_image = true;
67+
} else if (argc > 2) {
68+
std::cerr << "Too many arguments have been provided. Please use "
69+
<< "only one argument to save the result of the pipeline as "
70+
<< "an image, or none to display it to an X11 window." << std::endl;
71+
return 1;
72+
}
73+
6374
// load compiled functions
6475
tvm::runtime::Module mod =
6576
tvm::runtime::Module::LoadFromFile(network_module_path);
@@ -289,12 +300,21 @@ int main(int argc, char const *argv[]) {
289300
}
290301
}
291302

292-
// show in a pop up window the detection results
293-
cv::namedWindow(DISPLAY_WINDOW_NAME, cv::WINDOW_AUTOSIZE);
294-
cv::imshow(DISPLAY_WINDOW_NAME, image);
303+
if (save_as_image) {
304+
// save the detection results as an image
305+
try {
306+
cv::imwrite(argv[1], image);
307+
} catch(cv::Exception& e) {
308+
std::cerr << "An error has occurred while saving to file: " << e.err << std::endl;
309+
}
310+
} else {
311+
// show in a pop up window the detection results
312+
cv::namedWindow(DISPLAY_WINDOW_NAME, cv::WINDOW_AUTOSIZE);
313+
cv::imshow(DISPLAY_WINDOW_NAME, image);
295314

296-
// wait for user to close the window
297-
cv::waitKey(0);
315+
// wait for user to close the window
316+
cv::waitKey(0);
317+
}
298318

299319
// usually the detection results would be filtered again by a non-maximum
300320
// supression algorithm. It is omitted here for simplicity.

0 commit comments

Comments
 (0)