blob: 87e483932b725c4467fb9ef632bca68fc6b28366 [file] [log] [blame]
agsantos5aa39652020-08-11 18:18:04 -04001/**
Sébastien Blincb783e32021-02-12 11:34:10 -05002 * Copyright (C) 2020-2021 Savoir-faire Linux Inc.
agsantos5aa39652020-08-11 18:18:04 -04003 *
4 * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
agsantosac1940d2020-09-17 10:18:40 -040018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA.
agsantos5aa39652020-08-11 18:18:04 -040020 */
21
22#pragma once
23
24#include "TFInference.h"
25
26// OpenCV headers
27#include <opencv2/core.hpp>
28// STL
29#include <array>
agsantos5aa39652020-08-11 18:18:04 -040030#include <iostream>
agsantosac1940d2020-09-17 10:18:40 -040031#include <tuple>
32#include <vector>
agsantos5aa39652020-08-11 18:18:04 -040033
34namespace jami {
35
agsantosac1940d2020-09-17 10:18:40 -040036class PluginInference : public TensorflowInference
37{
agsantos5aa39652020-08-11 18:18:04 -040038public:
agsantosac1940d2020-09-17 10:18:40 -040039 /**
40 * @brief PluginInference
41 * Is a type of supervised learning where we detect objects in images
42 * Draw a bounding boxes around them
43 * @param model
44 */
45 PluginInference(TFModel model);
46 ~PluginInference();
agsantos5aa39652020-08-11 18:18:04 -040047
48#ifdef TFLITE
agsantosac1940d2020-09-17 10:18:40 -040049 /**
50 * @brief getInput
51 * Returns the input where to fill the data
52 * Use this method if you know what you are doing, all the necessary checks
53 * on dimensions must be done on your part
54 * @return std::tuple<uint8_t *, std::vector<int>>
55 * The first element in the tuple is the pointer to the storage location
56 * The second element is a dimensions vector that will helps you make
57 * The necessary checks to make your data size match the input one
58 */
59 std::pair<uint8_t*, std::vector<int>> getInput();
agsantos5aa39652020-08-11 18:18:04 -040060
61#else
agsantosac1940d2020-09-17 10:18:40 -040062 void ReadTensorFromMat(const cv::Mat& image);
agsantos5aa39652020-08-11 18:18:04 -040063
agsantosac1940d2020-09-17 10:18:40 -040064#endif // TFLITE
agsantos5aa39652020-08-11 18:18:04 -040065
agsantosac1940d2020-09-17 10:18:40 -040066 std::vector<float> masksPredictions() const;
agsantos5aa39652020-08-11 18:18:04 -040067
agsantosac1940d2020-09-17 10:18:40 -040068 /**
69 * @brief setExpectedImageDimensions
70 * Sets imageWidth and imageHeight from the sources
71 */
72 void setExpectedImageDimensions();
agsantos5aa39652020-08-11 18:18:04 -040073
agsantosac1940d2020-09-17 10:18:40 -040074 // Getters
75 int getImageWidth() const;
76 int getImageHeight() const;
77 int getImageNbChannels() const;
agsantos5aa39652020-08-11 18:18:04 -040078
79private:
agsantosac1940d2020-09-17 10:18:40 -040080 int imageWidth = 0;
81 int imageHeight = 0;
82 int imageNbChannels = 0;
agsantos5aa39652020-08-11 18:18:04 -040083};
84} // namespace jami