opencv_trail_effect.cpp: hardcode V4L2 VideoCapture backend on linux
[experiments/opencv_trail_effect.git] / Frame.hpp
1 /*
2  * openvc_trail_effect - experiments about video trail effects
3  *
4  * Copyright (C) 2015  Antonio Ospite <ao2@ao2.it>
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 2 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, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef FRAME_HPP
21 #define FRAME_HPP
22
23 #include <opencv2/opencv.hpp>
24
25 class Frame {
26 private:
27         cv::Mat data;
28         cv::Mat mask;
29
30 public:
31         Frame(cv::Size size)
32         {
33                 data = cv::Mat::zeros(size, CV_8UC3);
34                 mask = cv::Mat::zeros(size, CV_8UC1);
35         }
36
37         Frame(const cv::Mat& frame_data)
38         {
39                 frame_data.copyTo(data);
40         }
41
42         Frame(const cv::Mat& frame_data, const cv::Mat& frame_mask)
43         {
44                 frame_data.copyTo(data);
45                 frame_mask.copyTo(mask);
46         }
47
48         ~Frame()
49         {
50         }
51
52         void copyTo(cv::Mat& destination)
53         {
54                 cv::Mat converted_data;
55
56                 data.convertTo(converted_data, destination.type());
57                 converted_data.copyTo(destination, mask);
58         }
59
60         void zero()
61         {
62                 data.setTo(cv::Scalar(0));
63                 mask.setTo(cv::Scalar(0));
64         }
65
66         cv::Mat getMasked()
67         {
68                 cv::Mat masked_frame;
69
70                 data.copyTo(masked_frame, mask);
71                 return masked_frame;
72         }
73
74         cv::Mat getData() { return data; }
75         cv::Mat getMask() { return mask; }
76 };
77
78 #endif // FRAME_HPP