Richard Burton | ef90497 | 2022-04-27 17:24:36 +0100 | [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 "DetectorPreProcessing.hpp" |
| 18 | #include "ImageUtils.hpp" |
| 19 | #include "log_macros.h" |
| 20 | |
| 21 | namespace arm { |
| 22 | namespace app { |
| 23 | |
| 24 | DetectorPreProcess::DetectorPreProcess(TfLiteTensor* inputTensor, bool rgb2Gray, bool convertToInt8) |
| 25 | : m_inputTensor{inputTensor}, |
| 26 | m_rgb2Gray{rgb2Gray}, |
| 27 | m_convertToInt8{convertToInt8} |
| 28 | {} |
| 29 | |
| 30 | bool DetectorPreProcess::DoPreProcess(const void* data, size_t inputSize) { |
| 31 | if (data == nullptr) { |
| 32 | printf_err("Data pointer is null"); |
| 33 | } |
| 34 | |
| 35 | auto input = static_cast<const uint8_t*>(data); |
| 36 | |
| 37 | if (this->m_rgb2Gray) { |
| 38 | image::RgbToGrayscale(input, this->m_inputTensor->data.uint8, this->m_inputTensor->bytes); |
| 39 | } else { |
| 40 | std::memcpy(this->m_inputTensor->data.data, input, inputSize); |
| 41 | } |
| 42 | debug("Input tensor populated \n"); |
| 43 | |
| 44 | if (this->m_convertToInt8) { |
| 45 | image::ConvertImgToInt8(this->m_inputTensor->data.data, this->m_inputTensor->bytes); |
| 46 | } |
| 47 | |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | } /* namespace app */ |
| 52 | } /* namespace arm */ |