add lens default interp for opengl
[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 #include "opencv2/core/types.hpp"
49 #include "opencv2/core/mat.hpp"
50 #include "opencv2/imgproc/imgproc.hpp"
51 #include "opencv2/xfeatures2d.hpp"
52 #include "opencv2/calib3d.hpp"
53 #include "opencv2/flann/defines.h"
54 #include "opencv2/flann/params.h"
55
56 #include <vector>
57
58 using namespace std;
59 using namespace cv;
60 using namespace cv::xfeatures2d;
61 using namespace cvflann;
62
63 // enabled detectors
64 #define _SIFT
65 #define _SURF
66 #define _ORB
67 #define _AKAZE
68 #define _BRISK
69
70 // Limits of global range in percent
71 #define MIN_RADIUS 1
72 #define MAX_RADIUS 200
73
74 // Limits of block size in percent.
75 #define MIN_BLOCK 1
76 #define MAX_BLOCK 100
77
78 #define MIN_LAYER 0
79 #define MAX_LAYER 255
80
81 #define MIN_BLEND 1
82 #define MAX_BLEND 100
83
84 #define NO_ALGORITHM 0
85 #define ALGORITHM_SIFT  1
86 #define ALGORITHM_SURF  2
87 #define ALGORITHM_ORB   3
88 #define ALGORITHM_AKAZE 4
89 #define ALGORITHM_BRISK 5
90
91 class FindObjConfig
92 {
93 public:
94         FindObjConfig();
95
96         int equivalent(FindObjConfig &that);
97         void copy_from(FindObjConfig &that);
98         void interpolate(FindObjConfig &prev, FindObjConfig &next,
99                 int64_t prev_frame, int64_t next_frame, int64_t current_frame);
100         void boundaries();
101
102         int algorithm, use_flann;
103         float object_x, object_y, object_w, object_h;
104         float scene_x, scene_y,   scene_w, scene_h;
105
106         int draw_keypoints;
107         int draw_border;
108         int replace_object;
109         int draw_object_border;
110
111         int object_layer;
112         int replace_layer;
113         int scene_layer;
114         int blend;
115 };
116
117 class FindObjMain : public PluginVClient
118 {
119 public:
120         FindObjMain(PluginServer *server);
121         ~FindObjMain();
122
123         int process_buffer(VFrame **frame, int64_t start_position, double frame_rate);
124 #ifdef _SIFT
125         void set_sift();
126 #endif
127 #ifdef _SURF
128         void set_surf();
129 #endif
130 #ifdef _ORB
131         void set_orb();
132 #endif
133 #ifdef _AKAZE
134         void set_akaze();
135 #endif
136 #ifdef _BRISK
137         void set_brisk();
138 #endif
139         void process_match();
140
141         void draw_vectors(VFrame *frame);
142         int is_multichannel();
143         int is_realtime();
144         void save_data(KeyFrame *keyframe);
145         void read_data(KeyFrame *keyframe);
146         void update_gui();
147
148         PLUGIN_CLASS_MEMBERS2(FindObjConfig)
149
150         AffineEngine *affine;
151         OverlayFrame *overlayer;
152         VFrame *object, *scene, *replace;
153
154         static void draw_line(VFrame *vframe, int x1, int y1, int x2, int y2);
155         static void draw_rect(VFrame *vframe, int x1, int y1, int x2, int y2);
156         static void draw_circle(VFrame *vframe, int x, int y, int r);
157
158         int object_x, object_y, object_w, object_h;
159         int scene_x, scene_y, scene_w, scene_h;
160
161         int w, h;
162         int object_layer;
163         int scene_layer;
164         int replace_layer;
165
166 // Latest coordinates of object in scene
167         int border_x1, border_y1;
168         int border_x2, border_y2;
169         int border_x3, border_y3;
170         int border_x4, border_y4;
171 // Coordinates of object in scene with blending
172         float obj_x1, obj_y1;
173         float obj_x2, obj_y2;
174         float obj_x3, obj_y3;
175         float obj_x4, obj_y4;
176         int init_border;
177
178 //opencv
179         typedef vector<DMatch> DMatchV;
180         typedef vector<DMatchV> DMatches;
181         typedef vector<KeyPoint> KeyPointV;
182         typedef vector<Point2f> ptV;
183
184         BC_CModel cvmodel;
185         Mat object_mat, scene_mat;
186         Mat obj_descrs;  KeyPointV obj_keypts;
187         Mat scn_descrs;  KeyPointV scn_keypts;
188         DMatches pairs;
189
190         static void to_mat(Mat &mat, int mcols, int mrows,
191                 VFrame *inp, int ix,int iy, BC_CModel mcolor_model);
192         void detect(Mat &mat, KeyPointV &keypts, Mat &descrs);
193         void match();
194         void filter_matches(ptV &p1, ptV &p2, double ratio=0.75);
195
196         Ptr<Feature2D> detector;
197         Ptr<DescriptorMatcher> matcher;
198         Ptr<DescriptorMatcher> flann_kdtree_matcher();
199         Ptr<DescriptorMatcher> flann_lshidx_matcher();
200         Ptr<DescriptorMatcher> bf_matcher_norm_l2();
201         Ptr<DescriptorMatcher> bf_matcher_norm_hamming();
202 };
203
204 #endif