blob: ea6ba29cf748f02a7ef0e1ca8d33cc4dcacb4f8d [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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#pragma once
22// STL
23#include <condition_variable>
24#include <cstdint>
25#include <memory>
26#include <mutex>
27#include <thread>
28#include <vector>
29#include <map>
30// Filters
31#include "pluginInference.h"
32// AvFrame
33extern "C" {
34#include <libavutil/frame.h>
35}
36// Plugin
37#include <plugin/jamiplugin.h>
38#include <plugin/mediahandler.h>
39// Frame scaler for frame transformations
40#include <framescaler.h>
41
42namespace jami {
43
44class PluginProcessor {
45public:
46 PluginProcessor(const std::string& dataPath);
47
48 void initModel();
49 /**
50 * @brief feedInput
51 * Takes a frame and feeds it to the model storage for predictions
52 * @param frame
53 */
54 void feedInput(const cv::Mat& frame);
55
56 /**
57 * @brief computePredictions
58 * Uses the model to compute the predictions and store them in
59 * computedPredictions
60 */
61 void computePredictions();
62
63 void printMask();
64 void drawMaskOnFrame(cv::Mat& frame, cv::Mat& frameReduced, std::vector<float>computedMask, int lineSize, int angle);
65 int getBackgroundRotation();
66 void setBackgroundRotation(int angle);
67 void setBackgroundImage(const std::string& dataPath, const std::string& value);
68 void rotateFrame(int angle, cv::Mat& mat);
69
70 // Output predictions
71 std::vector<float> computedMask;
72
73 cv::Mat previousMasks[2];
74 cv::Mat backgroundImage;
75
76 cv::Size kSize;
77 float scaleX = 0;
78 float scaleY = 0;
79
80 PluginInference pluginInference;
81 std::string backgroundPath;
82
83private:
84 // Frame
85 cv::Mat frame;
86 int backgroundRotation = 0;
87};
88} // namespace jami