4 * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
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.
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.
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
24 // This is mainly a test for object tracking
38 #include "filexml.inc"
39 #include "keyframe.inc"
40 #include "findobjectwindow.inc"
41 #include "overlayframe.inc"
42 #include "pluginvclient.h"
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"
53 class FindObjectWindow;
60 // Limits of global range in percent
62 #define MAX_RADIUS 200
64 // Limits of block size in percent.
74 // Sizes must be quantized a certain amount for OpenCV
77 // Storage for results
78 #define FINDOBJECT_FILE "/tmp/findobject"
80 #define MIN_CAMSHIFT 0
81 #define MAX_CAMSHIFT 256
84 #define NO_ALGORITHM 0
85 #define ALGORITHM_SURF 1
86 #define ALGORITHM_CAMSHIFT 2
87 #define ALGORITHM_BLOB 3
89 class FindObjectConfig
94 int equivalent(FindObjectConfig &that);
95 void copy_from(FindObjectConfig &that);
96 void interpolate(FindObjectConfig &prev,
97 FindObjectConfig &next,
100 int64_t current_frame);
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
115 // Draw border over object in scene layer
117 // Draw transparency over object in object layer
119 // Draw border over object
120 int draw_object_border;
122 // Which layer is the object 0 or 1
124 // Which layer replaces the object
126 // Which layer is the object searched for in
130 // Camshift parameters
131 int vmin, vmax, smin;
132 // Amount to blend new object position in
139 class FindObjectMain : public PluginVClient
142 FindObjectMain(PluginServer *server);
145 int process_buffer(VFrame **frame,
146 int64_t start_position,
148 void draw_vectors(VFrame *frame);
149 int is_multichannel();
151 void save_data(KeyFrame *keyframe);
152 void read_data(KeyFrame *keyframe);
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);
158 PLUGIN_CLASS_MEMBERS2(FindObjectConfig)
161 AffineEngine *affine;
162 // Temporary for affine overlay
164 OverlayFrame *overlayer;
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);
170 void grey_crop(unsigned char *dst,
182 void process_camshift();
187 // clamped coordinates
207 // Latest coordinates of object in scene
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;
228 IplImage *object_image;
229 IplImage *scene_image;
232 // Comparison with current object_image
233 unsigned char *prev_object;
239 CvSeq *object_keypoints;
240 CvSeq *object_descriptors;
241 CvSeq *scene_keypoints;
242 CvSeq *scene_descriptors;
243 CvMemStorage *storage;
252 int blob_initialized;
253 CvBlobTrackerAutoParam1 blob_param;
254 CvBlobTrackerAuto* blob_pTracker;