agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 1 | /** |
| 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 |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 | * USA. |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | // STL |
| 24 | #include <condition_variable> |
| 25 | #include <cstdint> |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 26 | #include <map> |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 27 | #include <memory> |
| 28 | #include <mutex> |
| 29 | #include <thread> |
| 30 | #include <vector> |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 31 | // Filters |
| 32 | #include "pluginInference.h" |
| 33 | // AvFrame |
| 34 | extern "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 | |
| 43 | namespace jami { |
| 44 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 45 | class PluginProcessor |
| 46 | { |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 47 | public: |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 48 | PluginProcessor(const std::string& dataPath); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 49 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 50 | 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); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 57 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 58 | /** |
| 59 | * @brief computePredictions |
| 60 | * Uses the model to compute the predictions and store them in |
| 61 | * computedPredictions |
| 62 | */ |
| 63 | void computePredictions(); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 64 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 65 | 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); |
agsantos | 9dcf430 | 2020-09-01 18:21:48 -0400 | [diff] [blame] | 75 | bool hasBackground() const; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 76 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 77 | // Output predictions |
| 78 | std::vector<float> computedMask; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 79 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 80 | cv::Mat previousMasks[2]; |
| 81 | cv::Mat backgroundImage; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 82 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 83 | cv::Size kSize; |
| 84 | float scaleX = 0; |
| 85 | float scaleY = 0; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 86 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 87 | PluginInference pluginInference; |
| 88 | std::string backgroundPath; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 89 | |
| 90 | private: |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame^] | 91 | // Frame |
| 92 | cv::Mat frame; |
| 93 | int backgroundRotation = 0; |
agsantos | 9dcf430 | 2020-09-01 18:21:48 -0400 | [diff] [blame] | 94 | bool hasBackground_ = false; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 95 | }; |
| 96 | } // namespace jami |