|
1 | 1 | #pragma once |
2 | 2 |
|
3 | | -#include <string> |
4 | 3 | #include <opencv2/opencv.hpp> |
5 | 4 | #include <openvino/openvino.hpp> |
| 5 | +#include <string> |
| 6 | + |
6 | 7 | #include "adapters/inference_adapter.h" |
7 | 8 | #include "tasks/detection/ssd.h" |
8 | 9 | #include "tasks/results.h" |
9 | | -#include "utils/vision_pipeline.h" |
10 | 10 | #include "utils/tiling.h" |
| 11 | +#include "utils/vision_pipeline.h" |
11 | 12 |
|
12 | 13 | class DetectionModel { |
13 | 14 | public: |
14 | 15 | std::unique_ptr<Pipeline<DetectionResult>> pipeline; |
15 | 16 |
|
16 | | - DetectionModel(std::unique_ptr<SSD> algorithm, const ov::AnyMap& configuration): algorithm(std::move(algorithm)) { |
| 17 | + DetectionModel(std::unique_ptr<SSD> algorithm, const ov::AnyMap& configuration) : algorithm(std::move(algorithm)) { |
17 | 18 | auto config = this->algorithm->adapter->getModelConfig(); |
18 | 19 | if (configuration.count("tiling") && configuration.at("tiling").as<bool>()) { |
19 | 20 | if (!utils::config_contains_tiling_info(config)) { |
20 | 21 | throw std::runtime_error("Model config does not contain tiling properties."); |
21 | 22 | } |
22 | | - pipeline = std::make_unique<TilingPipeline<DetectionResult>>(this->algorithm->adapter, |
| 23 | + pipeline = std::make_unique<TilingPipeline<DetectionResult>>( |
| 24 | + this->algorithm->adapter, |
23 | 25 | utils::get_tiling_info_from_config(config), |
24 | | - [&](cv::Mat image) { return preprocess(image);}, |
25 | | - [&](InferenceResult result) { return postprocess(result);}, |
26 | | - [&](DetectionResult& result, const cv::Rect& coord) { return postprocess_tile(result, coord);}, |
27 | | - [&](const std::vector<DetectionResult>& tiles_results, const cv::Size& image_size, const std::vector<cv::Rect>& tile_coords, const utils::TilingInfo& tiling_info) { return merge_tiling_results(tiles_results, image_size, tile_coords, tiling_info);} |
28 | | - ); |
| 26 | + [&](cv::Mat image) { |
| 27 | + return preprocess(image); |
| 28 | + }, |
| 29 | + [&](InferenceResult result) { |
| 30 | + return postprocess(result); |
| 31 | + }, |
| 32 | + [&](DetectionResult& result, const cv::Rect& coord) { |
| 33 | + return postprocess_tile(result, coord); |
| 34 | + }, |
| 35 | + [&](const std::vector<DetectionResult>& tiles_results, |
| 36 | + const cv::Size& image_size, |
| 37 | + const std::vector<cv::Rect>& tile_coords, |
| 38 | + const utils::TilingInfo& tiling_info) { |
| 39 | + return merge_tiling_results(tiles_results, image_size, tile_coords, tiling_info); |
| 40 | + }); |
29 | 41 | } else { |
30 | | - pipeline = std::make_unique<VisionPipeline<DetectionResult>>(this->algorithm->adapter, |
31 | | - [&](cv::Mat image) { return preprocess(image);}, |
32 | | - [&](InferenceResult result) { return postprocess(result);} |
33 | | - ); |
| 42 | + pipeline = std::make_unique<VisionPipeline<DetectionResult>>( |
| 43 | + this->algorithm->adapter, |
| 44 | + [&](cv::Mat image) { |
| 45 | + return preprocess(image); |
| 46 | + }, |
| 47 | + [&](InferenceResult result) { |
| 48 | + return postprocess(result); |
| 49 | + }); |
34 | 50 | } |
35 | 51 | } |
36 | 52 |
|
37 | 53 | InferenceInput preprocess(cv::Mat); |
38 | 54 | DetectionResult postprocess(InferenceResult); |
39 | 55 | DetectionResult postprocess_tile(DetectionResult& result, const cv::Rect& coord); |
40 | | - DetectionResult merge_tiling_results(const std::vector<DetectionResult>& tiles_results, const cv::Size& image_size, const std::vector<cv::Rect>& tile_coords, const utils::TilingInfo& tiling_info); |
41 | | - ov::Tensor merge_saliency_maps(const std::vector<DetectionResult>& tiles_results, const cv::Size& image_size, const std::vector<cv::Rect>& tile_coords, const utils::TilingInfo& tiling_info); |
| 56 | + DetectionResult merge_tiling_results(const std::vector<DetectionResult>& tiles_results, |
| 57 | + const cv::Size& image_size, |
| 58 | + const std::vector<cv::Rect>& tile_coords, |
| 59 | + const utils::TilingInfo& tiling_info); |
| 60 | + ov::Tensor merge_saliency_maps(const std::vector<DetectionResult>& tiles_results, |
| 61 | + const cv::Size& image_size, |
| 62 | + const std::vector<cv::Rect>& tile_coords, |
| 63 | + const utils::TilingInfo& tiling_info); |
42 | 64 |
|
43 | 65 | static DetectionModel load(const std::string& model_path, const ov::AnyMap& configuration = {}); |
44 | 66 |
|
|
0 commit comments