MCPcopy Create free account
hub / github.com/ARM-software/armnn / AddInferenceOutputToFrame

Function AddInferenceOutputToFrame

samples/ObjectDetection/src/ImageUtils.cpp:17–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15}
16
17void AddInferenceOutputToFrame(od::DetectedObjects& decodedResults, cv::Mat& inputFrame,
18 std::vector<std::tuple<std::string, common::BBoxColor>>& labels)
19{
20 for(const od::DetectedObject& object : decodedResults)
21 {
22 int confidence = static_cast<int>(object.GetScore() * 100);
23 int baseline = 0;
24 std::string textStr;
25 std::tuple<int, int, int> colorCode(255, 0, 0); //red
26
27 if (labels.size() > object.GetId())
28 {
29 auto label = labels[object.GetId()];
30 textStr = std::get<0>(label) + " - " + std::to_string(confidence) + "%";
31 colorCode = std::get<1>(label).colorCode;
32 }
33 else
34 {
35 textStr = std::to_string(object.GetId()) + " - " + std::to_string(confidence) + "%";
36 }
37
38 cv::Size textSize = getTextSize(textStr, cv::FONT_HERSHEY_DUPLEX, 1.0, 1, &baseline);
39
40 const od::BoundingBox& bbox = object.GetBoundingBox();
41
42 if (bbox.GetX() + bbox.GetWidth() > inputFrame.cols)
43 {
44 cv::Rect r(bbox.GetX(), bbox.GetY(), inputFrame.cols - bbox.GetX(), bbox.GetHeight());
45
46 cv::rectangle(inputFrame, r, GetScalarColorCode(colorCode), 2, 8, 0);
47 }
48 else if (bbox.GetY() + bbox.GetHeight() > inputFrame.rows)
49 {
50 cv::Rect r(bbox.GetX(), bbox.GetY(), bbox.GetWidth(), inputFrame.rows - bbox.GetY());
51
52 cv::rectangle(inputFrame, r, GetScalarColorCode(colorCode), 2, 8, 0);
53 }
54 else
55 {
56 cv::Rect r(bbox.GetX(), bbox.GetY(), bbox.GetWidth(), bbox.GetHeight());
57
58 cv::rectangle(inputFrame, r, GetScalarColorCode(colorCode), 2, 8, 0);
59 }
60
61 int textBoxY = std::max(0 ,bbox.GetY() - textSize.height);
62
63 cv::Rect text(bbox.GetX(), textBoxY, textSize.width, textSize.height);
64
65 cv::rectangle(inputFrame, text, GetScalarColorCode(colorCode), -1);
66
67 cv::Scalar color;
68
69 if(std::get<0>(colorCode) + std::get<1>(colorCode) + std::get<2>(colorCode) > 127)
70 {
71 color = cv::Scalar::all(0);
72 }
73 else
74 {

Callers 2

ImageUtilsTest.cppFile · 0.85
mainFunction · 0.85

Calls 9

GetScalarColorCodeFunction · 0.85
GetScoreMethod · 0.80
GetIdMethod · 0.80
GetXMethod · 0.80
GetYMethod · 0.80
to_stringFunction · 0.50
sizeMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45

Tested by

no test coverage detected