|
1 | 1 | /*
|
2 |
| -// Copyright (C) 2018-2022 Intel Corporation |
| 2 | +// Copyright (C) 2018-2023 Intel Corporation |
3 | 3 | //
|
4 | 4 | // Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | // you may not use this file except in compliance with the License.
|
|
32 | 32 | #include <models/input_data.h>
|
33 | 33 | #include <models/results.h>
|
34 | 34 |
|
| 35 | +int main(int argc, char* argv[]) try { |
| 36 | + if (argc != 3) { |
| 37 | + throw std::runtime_error(std::string{"Usage: "} + argv[0] + " <path_to_model> <path_to_image>"); |
| 38 | + } |
35 | 39 |
|
36 |
| -int main(int argc, char* argv[]) { |
37 |
| - try { |
38 |
| - if (argc != 3) { |
39 |
| - std::cerr << "Usage : " << argv[0] << " <path_to_model> <path_to_image>" |
40 |
| - << std::endl; |
41 |
| - return EXIT_FAILURE; |
42 |
| - } |
43 |
| - |
44 |
| - cv::Mat image = cv::imread(argv[2]); |
45 |
| - if (!image.data) { |
46 |
| - throw std::runtime_error{"Failed to read the image"}; |
47 |
| - } |
| 40 | + cv::Mat image = cv::imread(argv[2]); |
| 41 | + if (!image.data) { |
| 42 | + throw std::runtime_error{"Failed to read the image"}; |
| 43 | + } |
48 | 44 |
|
49 |
| - // Instantiate Object Detection model |
50 |
| - auto model = DetectionModel::create_model(argv[1]); // works with SSD models. Download it using Python Model API |
| 45 | + // Instantiate Object Detection model |
| 46 | + auto model = DetectionModel::create_model(argv[1]); // works with SSD models. Download it using Python Model API |
51 | 47 |
|
52 |
| - // Run the inference |
53 |
| - auto result = model->infer(image); |
| 48 | + // Run the inference |
| 49 | + auto result = model->infer(image); |
54 | 50 |
|
55 |
| - // Process detections |
56 |
| - for (auto& obj : result->objects) { |
| 51 | + // Process detections |
| 52 | + for (auto& obj : result->objects) { |
57 | 53 | std::cout << " " << std::left << std::setw(9) << obj.label << " | " << std::setw(10) << obj.confidence
|
58 |
| - << " | " << std::setw(4) << int(obj.x) << " | " << std::setw(4) << int(obj.y) << " | " |
59 |
| - << std::setw(4) << int(obj.x + obj.width) << " | " << std::setw(4) << int(obj.y + obj.height) |
60 |
| - << std::endl; |
61 |
| - } |
62 |
| - |
63 |
| - } catch (const std::exception& error) { |
64 |
| - std::cerr << error.what() << std::endl; |
65 |
| - return 1; |
66 |
| - } catch (...) { |
67 |
| - std::cerr << "Unknown/internal exception happened." << std::endl; |
68 |
| - return 1; |
| 54 | + << " | " << std::setw(4) << int(obj.x) << " | " << std::setw(4) << int(obj.y) << " | " |
| 55 | + << std::setw(4) << int(obj.x + obj.width) << " | " << std::setw(4) << int(obj.y + obj.height) << "\n"; |
69 | 56 | }
|
70 |
| - |
71 |
| - return 0; |
| 57 | +} catch (const std::exception& error) { |
| 58 | + std::cerr << error.what() << '\n'; |
| 59 | + return 1; |
| 60 | +} catch (...) { |
| 61 | + std::cerr << "Non-exception object thrown\n"; |
| 62 | + return 1; |
72 | 63 | }
|
0 commit comments