sams icons, changed with-findobj to with-opencv, added plugins flowobj, gaborobj
[goodguy/history.git] / cinelerra-5.1 / plugins / flowobj / flowobj.h
1 /*
2  * CINELERRA
3  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #ifndef FLOWOBJ_H
21 #define FLOWOBJ_H
22
23 #include "pluginvclient.h"
24 #include "loadbalance.h"
25 #include "overlayframe.h"
26
27 #include "opencv2/core/types.hpp"
28 #include "opencv2/core/mat.hpp"
29 #include "opencv2/calib3d.hpp"
30 #include "opencv2/video/video.hpp"
31
32 #include <vector>
33
34 using namespace std;
35 using namespace cv;
36
37 //#define _RANSAC
38 #ifdef _RANSAC
39 #include <opencv2/videostab/motion_core.hpp>
40 #include <opencv2/videostab/global_motion.hpp>
41
42 using namespace videostab;
43 #endif
44
45 class FlowObjConfig;
46 class FlowObjRemapPackage;
47 class FlowObjRemapEngine;
48 class FlowObjRemapUnit;
49 class FlowObj;
50
51
52 class FlowObjConfig
53 {
54 public:
55         FlowObjConfig();
56
57         int equivalent(FlowObjConfig &that);
58         void copy_from(FlowObjConfig &that);
59         void interpolate(FlowObjConfig &prev, FlowObjConfig &next, 
60                 long prev_frame, long next_frame, long current_frame);
61         void limits();
62         int draw_vectors;
63         int do_stabilization;
64         int settling_speed;
65 // percent
66         int block_size;
67         int search_radius;
68 };
69
70 class FlowObjRemapPackage : public LoadPackage
71 {
72 public:
73         FlowObjRemapPackage();
74
75         int row1, row2;
76 };
77
78 class FlowObjRemapEngine : public LoadServer
79 {
80 public:
81         FlowObjRemapEngine(FlowObj *plugin, int cpus);
82         ~FlowObjRemapEngine();
83
84         void init_packages();
85         LoadClient* new_client();
86         LoadPackage* new_package();
87
88         FlowObj *plugin;
89 };
90
91 class FlowObjRemapUnit : public LoadClient
92 {
93 public:
94         FlowObjRemapUnit(FlowObjRemapEngine *engine, FlowObj *plugin);
95         ~FlowObjRemapUnit();
96
97         void process_package(LoadPackage *pkg);
98         void process_remap(FlowObjRemapPackage *pkg);
99
100         FlowObjRemapEngine *engine;
101         FlowObj *plugin;
102 };
103
104 class FlowObj : public PluginVClient
105 {
106 public:
107         FlowObj(PluginServer *server);
108         ~FlowObj();
109 // required for all realtime plugins
110         PLUGIN_CLASS_MEMBERS2(FlowObjConfig)
111         int is_realtime();
112         void update_gui();
113         void save_data(KeyFrame *keyframe);
114         void read_data(KeyFrame *keyframe);
115         int process_buffer(VFrame *frame, int64_t start_position, double frame_rate);
116         void to_mat(Mat &mat, int mcols, int mrows,
117                 VFrame *inp, int ix,int iy, int mcolor_model);
118         void from_mat(VFrame *out, int ox, int oy, int ow, int oh,
119                 Mat &mat, int mcolor_model);
120
121         long prev_position, next_position;
122         int width, height, color_model;
123         VFrame *input, *output, *accum;
124
125         Mat *flow_mat;
126         FlowObjRemapEngine *flow_engine;
127         OverlayFrame *overlay;
128
129 //opencv
130         typedef vector<Point2f> ptV;
131
132         BC_CModel cvmodel;
133         Mat accum_matrix;
134         double accum_matrix_mem[9];
135         double x_accum, y_accum, angle_accum;
136         Mat prev_mat, next_mat;
137         ptV *prev_corners, *next_corners;
138 };
139
140 #endif