updated internationalization po files
[goodguy/history.git] / cinelerra-5.0 / plugins / findobject / findobject.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 FINDOBJECT_H
30 #define FINDOBJECT_H
31
32 #include <math.h>
33 #include <stdint.h>
34 #include <string.h>
35
36 #include "affine.inc"
37 #include "bchash.inc"
38 #include "filexml.inc"
39 #include "keyframe.inc"
40 #include "findobjectwindow.inc"
41 #include "overlayframe.inc"
42 #include "pluginvclient.h"
43 #include "vframe.inc"
44
45 #include "opencv2/core/core_c.h"
46 #include "opencv2/objdetect/objdetect.hpp"
47 #include "opencv2/core/mat.hpp"
48 #include "opencv2/imgproc/types_c.h"
49 #include "opencv2/imgproc/imgproc.hpp"
50 #include "opencv2/legacy/blobtrack.hpp"
51
52 class FindObjectMain;
53 class FindObjectWindow;
54
55 using namespace cv;
56
57
58
59
60 // Limits of global range in percent
61 #define MIN_RADIUS 1
62 #define MAX_RADIUS 200
63
64 // Limits of block size in percent.
65 #define MIN_BLOCK 1
66 #define MAX_BLOCK 100
67
68 #define MIN_LAYER 0
69 #define MAX_LAYER 255
70
71 #define MIN_BLEND 1
72 #define MAX_BLEND 100
73
74 // Sizes must be quantized a certain amount for OpenCV
75 #define QUANTIZE 8
76
77 // Storage for results
78 #define FINDOBJECT_FILE "/tmp/findobject"
79
80 #define MIN_CAMSHIFT 0
81 #define MAX_CAMSHIFT 256
82
83
84 #define NO_ALGORITHM 0
85 #define ALGORITHM_SURF 1
86 #define ALGORITHM_CAMSHIFT 2
87 #define ALGORITHM_BLOB 3
88
89 class FindObjectConfig
90 {
91 public:
92         FindObjectConfig();
93
94         int equivalent(FindObjectConfig &that);
95         void copy_from(FindObjectConfig &that);
96         void interpolate(FindObjectConfig &prev, 
97                 FindObjectConfig &next, 
98                 int64_t prev_frame, 
99                 int64_t next_frame, 
100                 int64_t current_frame);
101         void boundaries();
102
103         int global_range_w;
104         int global_range_h;
105 // Block size as percent of image size
106 // Object must be a rectangle for the algorithm to work,
107 // so no oblique edges unless we also do an affine transform.
108         float global_block_w;
109         float global_block_h;
110 // Block position in percentage 0 - 100
111         float block_x;
112         float block_y;
113 // Draw key points
114         int draw_keypoints;
115 // Draw border over object in scene layer
116         int draw_border;
117 // Draw transparency over object in object layer
118         int replace_object;
119 // Draw border over object
120         int draw_object_border;
121
122 // Which layer is the object 0 or 1
123         int object_layer;
124 // Which layer replaces the object
125         int replace_layer;
126 // Which layer is the object searched for in
127         int scene_layer;
128
129         int algorithm;
130 // Camshift parameters
131         int vmin, vmax, smin;
132 // Amount to blend new object position in
133         int blend;
134 };
135
136
137
138
139 class FindObjectMain : public PluginVClient
140 {
141 public:
142         FindObjectMain(PluginServer *server);
143         ~FindObjectMain();
144
145         int process_buffer(VFrame **frame,
146                 int64_t start_position,
147                 double frame_rate);
148         void draw_vectors(VFrame *frame);
149         int is_multichannel();
150         int is_realtime();
151         void save_data(KeyFrame *keyframe);
152         void read_data(KeyFrame *keyframe);
153         void update_gui();
154 // Calculate frame to copy from and frame to move
155         void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
156         void allocate_temp(int w, int h, int color_model);
157
158         PLUGIN_CLASS_MEMBERS2(FindObjectConfig)
159
160
161         AffineEngine *affine;
162 // Temporary for affine overlay
163         VFrame *temp;
164         OverlayFrame *overlayer;
165
166         static void draw_pixel(VFrame *frame, int x, int y);
167         static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
168         static void draw_rect(VFrame *frame, int x1, int y1, int x2, int y2);
169
170         void grey_crop(unsigned char *dst, 
171                 VFrame *src, 
172                 int x1, 
173                 int y1,
174                 int x2,
175                 int y2,
176                 int dst_w,
177                 int dst_h);
178
179
180
181         void process_surf();
182         void process_camshift();
183         void process_blob();
184
185
186
187 // clamped coordinates
188         int object_w;
189         int object_h;
190         int object_x1;
191         int object_y1;
192         int object_x2;
193         int object_y2;
194         int scene_w;
195         int scene_h;
196         int scene_x1;
197         int scene_y1;
198         int scene_x2;
199         int scene_y2;
200 // input frame size
201         int w, h;
202 // clamped layers
203         int object_layer;
204         int scene_layer;
205         int replace_layer;
206
207 // Latest coordinates of object in scene
208         int border_x1;
209         int border_y1;
210         int border_x2;
211         int border_y2;
212         int border_x3;
213         int border_y3;
214         int border_x4;
215         int border_y4;
216 // Coordinates of object in scene with blending
217         float border_x1_accum;
218         float border_y1_accum;
219         float border_x2_accum;
220         float border_y2_accum;
221         float border_x3_accum;
222         float border_y3_accum;
223         float border_x4_accum;
224         float border_y4_accum;
225         int init_border;
226
227
228         IplImage *object_image;
229         IplImage *scene_image;
230
231
232 // Comparison with current object_image
233         unsigned char *prev_object;
234 // Quantized sizes
235         int object_image_w;
236         int object_image_h;
237         int scene_image_w;
238         int scene_image_h;
239         CvSeq *object_keypoints;
240         CvSeq *object_descriptors;
241         CvSeq *scene_keypoints;
242         CvSeq *scene_descriptors;
243         CvMemStorage *storage;
244
245 // camshift
246 // object histogram
247         Mat hist;
248         Rect trackWindow;
249
250
251 // Blob
252         int blob_initialized;
253         CvBlobTrackerAutoParam1 blob_param;
254         CvBlobTrackerAuto* blob_pTracker;
255         
256         
257 };
258
259
260
261
262
263
264
265
266
267
268 #endif
269
270
271
272
273
274