add auto zoombar/status color, fix 3 batchrender boobies, rotate plugin tweaks, add...
[goodguy/cinelerra.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 "opencv2/core/types_c.h"
33 #include <opencv2/calib3d/calib3d_c.h>
34
35 #include <vector>
36
37 using namespace std;
38 using namespace cv;
39
40 //#define _RANSAC
41 #ifdef _RANSAC
42 #include <opencv2/videostab/motion_core.hpp>
43 #include <opencv2/videostab/global_motion.hpp>
44
45 using namespace videostab;
46 #endif
47
48 class FlowObjConfig;
49 class FlowObjRemapPackage;
50 class FlowObjRemapEngine;
51 class FlowObjRemapUnit;
52 class FlowObj;
53
54
55 class FlowObjConfig
56 {
57 public:
58         FlowObjConfig();
59
60         int equivalent(FlowObjConfig &that);
61         void copy_from(FlowObjConfig &that);
62         void interpolate(FlowObjConfig &prev, FlowObjConfig &next, 
63                 long prev_frame, long next_frame, long current_frame);
64         void limits();
65         int draw_vectors;
66         int do_stabilization;
67         int settling_speed;
68 // percent
69         int block_size;
70         int search_radius;
71 };
72
73 class FlowObjRemapPackage : public LoadPackage
74 {
75 public:
76         FlowObjRemapPackage();
77
78         int row1, row2;
79 };
80
81 class FlowObjRemapEngine : public LoadServer
82 {
83 public:
84         FlowObjRemapEngine(FlowObj *plugin, int cpus);
85         ~FlowObjRemapEngine();
86
87         void init_packages();
88         LoadClient* new_client();
89         LoadPackage* new_package();
90
91         FlowObj *plugin;
92 };
93
94 class FlowObjRemapUnit : public LoadClient
95 {
96 public:
97         FlowObjRemapUnit(FlowObjRemapEngine *engine, FlowObj *plugin);
98         ~FlowObjRemapUnit();
99
100         void process_package(LoadPackage *pkg);
101         void process_remap(FlowObjRemapPackage *pkg);
102
103         FlowObjRemapEngine *engine;
104         FlowObj *plugin;
105 };
106
107 class FlowObj : public PluginVClient
108 {
109 public:
110         FlowObj(PluginServer *server);
111         ~FlowObj();
112 // required for all realtime plugins
113         PLUGIN_CLASS_MEMBERS2(FlowObjConfig)
114         int is_realtime();
115         void update_gui();
116         void save_data(KeyFrame *keyframe);
117         void read_data(KeyFrame *keyframe);
118         int process_buffer(VFrame *frame, int64_t start_position, double frame_rate);
119         void to_mat(Mat &mat, int mcols, int mrows,
120                 VFrame *inp, int ix,int iy, int mcolor_model);
121         void from_mat(VFrame *out, int ox, int oy, int ow, int oh,
122                 Mat &mat, int mcolor_model);
123
124         long prev_position, next_position;
125         int width, height, color_model;
126         VFrame *input, *output, *accum;
127
128         Mat *flow_mat;
129         FlowObjRemapEngine *flow_engine;
130         OverlayFrame *overlay;
131
132 //opencv
133         typedef vector<Point2f> ptV;
134
135         BC_CModel cvmodel;
136         Mat accum_matrix;
137         double accum_matrix_mem[9];
138         double x_accum, y_accum, angle_accum;
139         Mat prev_mat, next_mat;
140         ptV *prev_corners, *next_corners;
141 };
142
143 #endif