blob: 528988fd6e48cd24badf78c26f61b938801f9528 [file] [log] [blame]
agsantos5aa39652020-08-11 18:18:04 -04001/**
2 * Copyright (C) 2020 Savoir-faire Linux Inc.
3 *
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// STL
24#include <condition_variable>
25#include <cstdint>
agsantosac1940d2020-09-17 10:18:40 -040026#include <map>
agsantos5aa39652020-08-11 18:18:04 -040027#include <memory>
28#include <mutex>
29#include <thread>
30#include <vector>
agsantos5aa39652020-08-11 18:18:04 -040031// Filters
32#include "pluginInference.h"
33// AvFrame
34extern "C" {
35#include <libavutil/frame.h>
36}
37// Plugin
38#include <plugin/jamiplugin.h>
39#include <plugin/mediahandler.h>
40// Frame scaler for frame transformations
41#include <framescaler.h>
42
43namespace jami {
44
agsantosac1940d2020-09-17 10:18:40 -040045class PluginProcessor
46{
agsantos5aa39652020-08-11 18:18:04 -040047public:
agsantosac1940d2020-09-17 10:18:40 -040048 PluginProcessor(const std::string& dataPath);
agsantos5aa39652020-08-11 18:18:04 -040049
agsantosac1940d2020-09-17 10:18:40 -040050 void initModel();
51 /**
52 * @brief feedInput
53 * Takes a frame and feeds it to the model storage for predictions
54 * @param frame
55 */
56 void feedInput(const cv::Mat& frame);
agsantos5aa39652020-08-11 18:18:04 -040057
agsantosac1940d2020-09-17 10:18:40 -040058 /**
59 * @brief computePredictions
60 * Uses the model to compute the predictions and store them in
61 * computedPredictions
62 */
63 void computePredictions();
agsantos5aa39652020-08-11 18:18:04 -040064
agsantosac1940d2020-09-17 10:18:40 -040065 void printMask();
66 void drawMaskOnFrame(cv::Mat& frame,
67 cv::Mat& frameReduced,
68 std::vector<float> computedMask,
69 int lineSize,
70 int angle);
71 int getBackgroundRotation();
72 void setBackgroundRotation(int angle);
73 void setBackgroundImage(const std::string& backgroundPath);
74 void rotateFrame(int angle, cv::Mat& mat);
agsantos9dcf4302020-09-01 18:21:48 -040075 bool hasBackground() const;
agsantos5aa39652020-08-11 18:18:04 -040076
agsantosac1940d2020-09-17 10:18:40 -040077 // Output predictions
78 std::vector<float> computedMask;
agsantos5aa39652020-08-11 18:18:04 -040079
agsantosac1940d2020-09-17 10:18:40 -040080 cv::Mat previousMasks[2];
81 cv::Mat backgroundImage;
agsantos5aa39652020-08-11 18:18:04 -040082
agsantosac1940d2020-09-17 10:18:40 -040083 cv::Size kSize;
84 float scaleX = 0;
85 float scaleY = 0;
agsantos5aa39652020-08-11 18:18:04 -040086
agsantosac1940d2020-09-17 10:18:40 -040087 PluginInference pluginInference;
88 std::string backgroundPath;
agsantos5aa39652020-08-11 18:18:04 -040089
90private:
agsantosac1940d2020-09-17 10:18:40 -040091 // Frame
92 cv::Mat frame;
93 int backgroundRotation = 0;
agsantos9dcf4302020-09-01 18:21:48 -040094 bool hasBackground_ = false;
agsantos5aa39652020-08-11 18:18:04 -040095};
96} // namespace jami