xref: /aosp_15_r20/external/armnn/samples/ObjectDetection/include/ImageUtils.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include "DetectedObject.hpp"
8 #include "Types.hpp"
9 
10 #include <opencv2/opencv.hpp>
11 
12 #include <vector>
13 
14 const cv::InterpolationFlags DefaultResizeFlag = cv::INTER_NEAREST;
15 
16 /**
17 * @brief Function to process the decoded results from the inference, and overlay the detail onto the provided frame
18 * @param[in]  decodedResults          the decoded results from the inference output.
19 * @param[in]  inputFrame              the frame to overlay the inference output details onto.
20 * @param[in]  labels                  the label set associated with the trained model used.
21 */
22 void AddInferenceOutputToFrame(od::DetectedObjects& decodedResults,
23                                cv::Mat& inputFrame,
24                                std::vector<std::tuple<std::string, common::BBoxColor>>& labels);
25 
26 /**
27 * @brief Function to resize a frame while keeping aspect ratio.
28 *
29 * @param[in]  frame            the frame we want to resize from.
30 * @param[out]  dest            the frame we want to resize into.
31 * @param[in]  aspectRatio      aspect ratio to use when resizing.
32 */
33 void ResizeFrame(const cv::Mat& frame, cv::Mat& dest, const common::Size& aspectRatio);
34 
35 /**
36 * @brief Function to pad a frame.
37 * @param[in]   src           the frame we want to pad.
38 * @param[out]  dest          the frame we want to store the result.
39 * @param[in]   bottom        padding to use on bottom of the frame.
40 * @param[in]   right         padding to use on the right of the frame.
41 */
42 void PadFrame(const cv::Mat& src, cv::Mat& dest, int bottom, int right);
43 
44 /**
45  * Resize frame to the destination size and pad if necessary to preserve initial frame aspect ratio.
46  *
47  * @param frame input frame to resize
48  * @param dest output frame to place resized and padded result
49  * @param cache operation requires intermediate data container.
50  * @param destSize size of the destination frame
51  */
52 void ResizeWithPad(const cv::Mat& frame, cv::Mat& dest, cv::Mat& cache, const common::Size& destSize);
53 
54 /**
55 * @brief Function to retrieve the cv::scalar color from a RGB tuple.
56 * @param[in]  color            the tuple form of the RGB color
57 */
58 static cv::Scalar GetScalarColorCode(std::tuple<int, int, int> color);