add dragcheckbox, fix transition plugin title, sams opencv icons, drop libipp in...
[goodguy/history.git] / cinelerra-5.1 / plugins / findobj / findobj.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
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, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22
23
24 // This is mainly a test for object tracking
25
26
27
28
29 #ifndef FINDOBJ_H
30 #define FINDOBJ_H
31
32 //#include "config.h"
33
34 #include <math.h>
35 #include <stdint.h>
36 #include <string.h>
37
38 #include "affine.inc"
39 #include "bccmodels.h"
40 #include "bchash.inc"
41 #include "filexml.inc"
42 #include "keyframe.inc"
43 #include "findobj.inc"
44 #include "overlayframe.inc"
45 #include "pluginvclient.h"
46 #include "vframe.inc"
47
48 #define Mutex CvMutex
49 #include "opencv2/core/types.hpp"
50 #include "opencv2/core/mat.hpp"
51 #include "opencv2/imgproc/imgproc.hpp"
52 #include "opencv2/xfeatures2d.hpp"
53 #include "opencv2/calib3d.hpp"
54 #include "opencv2/flann/defines.h"
55 #include "opencv2/flann/params.h"
56 #undef Mutex
57
58 #include <vector>
59
60 using namespace std;
61 using namespace cv;
62 using namespace cv::xfeatures2d;
63 using namespace cvflann;
64
65 // enabled detectors
66 #define _SIFT
67 #define _SURF
68 #define _ORB
69 #define _AKAZE
70 #define _BRISK
71
72 // Limits of global range in percent
73 #define MIN_RADIUS 1
74 #define MAX_RADIUS 200
75
76 // Limits of block size in percent.
77 #define MIN_BLOCK 1
78 #define MAX_BLOCK 100
79
80 #define MIN_LAYER 0
81 #define MAX_LAYER 255
82
83 #define MIN_BLEND 1
84 #define MAX_BLEND 100
85
86 #define NO_ALGORITHM 0
87 #define ALGORITHM_SIFT  1
88 #define ALGORITHM_SURF  2
89 #define ALGORITHM_ORB   3
90 #define ALGORITHM_AKAZE 4
91 #define ALGORITHM_BRISK 5
92
93 class FindObjConfig
94 {
95 public:
96         FindObjConfig();
97
98         int equivalent(FindObjConfig &that);
99         void copy_from(FindObjConfig &that);
100         void interpolate(FindObjConfig &prev, FindObjConfig &next,
101                 int64_t prev_frame, int64_t next_frame, int64_t current_frame);
102         void boundaries();
103
104         int algorithm, use_flann;
105         int drag_object, drag_scene;
106         float object_x, object_y, object_w, object_h;
107         float scene_x, scene_y, scene_w, scene_h;
108
109         int draw_keypoints;
110         int draw_scene_border;
111         int replace_object;
112         int draw_object_border;
113
114         int object_layer;
115         int replace_layer;
116         int scene_layer;
117         int blend;
118 };
119
120 class FindObjMain : public PluginVClient
121 {
122 public:
123         FindObjMain(PluginServer *server);
124         ~FindObjMain();
125
126         int process_buffer(VFrame **frame, int64_t start_position, double frame_rate);
127 #ifdef _SIFT
128         void set_sift();
129 #endif
130 #ifdef _SURF
131         void set_surf();
132 #endif
133 #ifdef _ORB
134         void set_orb();
135 #endif
136 #ifdef _AKAZE
137         void set_akaze();
138 #endif
139 #ifdef _BRISK
140         void set_brisk();
141 #endif
142         void process_match();
143
144         void draw_vectors(VFrame *frame);
145         int is_multichannel();
146         int is_realtime();
147         void save_data(KeyFrame *keyframe);
148         void read_data(KeyFrame *keyframe);
149         void update_gui();
150
151         PLUGIN_CLASS_MEMBERS2(FindObjConfig)
152
153         AffineEngine *affine;
154         OverlayFrame *overlayer;
155         VFrame *object, *scene, *replace;
156
157         static void draw_line(VFrame *vframe, int x1, int y1, int x2, int y2);
158         static void draw_rect(VFrame *vframe, int x1, int y1, int x2, int y2);
159         static void draw_circle(VFrame *vframe, int x, int y, int r);
160
161         int object_x, object_y, object_w, object_h;
162         int scene_x, scene_y, scene_w, scene_h;
163
164         int w, h;
165         int object_layer;
166         int scene_layer;
167         int replace_layer;
168
169 // Latest coordinates of object in scene
170         int border_x1, border_y1;
171         int border_x2, border_y2;
172         int border_x3, border_y3;
173         int border_x4, border_y4;
174 // Coordinates of object in scene with blending
175         float obj_x1, obj_y1;
176         float obj_x2, obj_y2;
177         float obj_x3, obj_y3;
178         float obj_x4, obj_y4;
179         int init_border;
180
181 //opencv
182         typedef vector<DMatch> DMatchV;
183         typedef vector<DMatchV> DMatches;
184         typedef vector<KeyPoint> KeyPointV;
185         typedef vector<Point2f> ptV;
186
187         BC_CModel cvmodel;
188         Mat object_mat, scene_mat;
189         Mat obj_descrs;  KeyPointV obj_keypts;
190         Mat scn_descrs;  KeyPointV scn_keypts;
191         DMatches pairs;
192
193         static void to_mat(Mat &mat, int mcols, int mrows,
194                 VFrame *inp, int ix,int iy, BC_CModel mcolor_model);
195         void detect(Mat &mat, KeyPointV &keypts, Mat &descrs);
196         void match();
197         void filter_matches(ptV &p1, ptV &p2, double ratio=0.75);
198
199         Ptr<Feature2D> detector;
200         Ptr<DescriptorMatcher> matcher;
201         Ptr<DescriptorMatcher> flann_kdtree_matcher();
202         Ptr<DescriptorMatcher> flann_lshidx_matcher();
203         Ptr<DescriptorMatcher> bf_matcher_norm_l2();
204         Ptr<DescriptorMatcher> bf_matcher_norm_hamming();
205 };
206
207 #endif