Michael Levit | 06fcf75 | 2022-01-12 11:53:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 Arm Limited. All rights reserved. |
| 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | #include "DetectionUseCaseUtils.hpp" |
| 18 | #include "UseCaseCommonUtils.hpp" |
| 19 | #include "InputFiles.hpp" |
| 20 | #include <inttypes.h> |
| 21 | |
| 22 | |
| 23 | void DisplayDetectionMenu() |
| 24 | { |
| 25 | printf("\n\n"); |
| 26 | printf("User input required\n"); |
| 27 | printf("Enter option number from:\n\n"); |
| 28 | printf(" %u. Run detection on next ifm\n", common::MENU_OPT_RUN_INF_NEXT); |
| 29 | printf(" %u. Run detection ifm at chosen index\n", common::MENU_OPT_RUN_INF_CHOSEN); |
| 30 | printf(" %u. Run detection on all ifm\n", common::MENU_OPT_RUN_INF_ALL); |
| 31 | printf(" %u. Show NN model info\n", common::MENU_OPT_SHOW_MODEL_INFO); |
| 32 | printf(" %u. List ifm\n\n", common::MENU_OPT_LIST_IFM); |
| 33 | printf(" Choice: "); |
| 34 | fflush(stdout); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | bool image::PresentInferenceResult(hal_platform& platform, |
| 39 | const std::vector<arm::app::DetectionResult>& results) |
| 40 | { |
| 41 | return PresentInferenceResult(platform, results, false); |
| 42 | } |
| 43 | |
| 44 | bool image::PresentInferenceResult(hal_platform &platform, |
| 45 | const std::vector<arm::app::DetectionResult> &results, |
| 46 | const time_t infTimeMs) |
| 47 | { |
| 48 | return PresentInferenceResult(platform, results, true, infTimeMs); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | bool image::PresentInferenceResult(hal_platform &platform, |
| 53 | const std::vector<arm::app::DetectionResult> &results, |
| 54 | bool profilingEnabled, |
| 55 | const time_t infTimeMs) |
| 56 | { |
| 57 | constexpr uint32_t dataPsnTxtStartX1 = 150; |
| 58 | constexpr uint32_t dataPsnTxtStartY1 = 30; |
| 59 | |
| 60 | |
| 61 | if(profilingEnabled) |
| 62 | { |
| 63 | platform.data_psn->set_text_color(COLOR_YELLOW); |
| 64 | |
| 65 | /* If profiling is enabled, and the time is valid. */ |
| 66 | info("Final results:\n"); |
| 67 | info("Total number of inferences: 1\n"); |
| 68 | if (infTimeMs) |
| 69 | { |
| 70 | std::string strInf = |
| 71 | std::string{"Inference: "} + |
| 72 | std::to_string(infTimeMs) + |
| 73 | std::string{"ms"}; |
| 74 | platform.data_psn->present_data_text( |
| 75 | strInf.c_str(), strInf.size(), |
| 76 | dataPsnTxtStartX1, dataPsnTxtStartY1, 0); |
| 77 | } |
| 78 | } |
| 79 | platform.data_psn->set_text_color(COLOR_GREEN); |
| 80 | |
| 81 | if(!profilingEnabled) { |
| 82 | info("Final results:\n"); |
| 83 | info("Total number of inferences: 1\n"); |
| 84 | } |
| 85 | |
| 86 | for (uint32_t i = 0; i < results.size(); ++i) { |
| 87 | |
| 88 | if(profilingEnabled) { |
| 89 | info("%" PRIu32 ") (%f) -> %s {x=%d,y=%d,w=%d,h=%d}\n", i, |
| 90 | results[i].m_normalisedVal, "Detection box:", |
| 91 | results[i].m_x0, results[i].m_y0, results[i].m_w, results[i].m_h ); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | info("%" PRIu32 ") (%f) -> %s {x=%d,y=%d,w=%d,h=%d}\n", i, |
| 96 | results[i].m_normalisedVal, "Detection box:", |
| 97 | results[i].m_x0, results[i].m_y0, results[i].m_w, results[i].m_h ); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | |