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
40 #include "filexml.inc"
41 #include "keyframe.inc"
42 #include "findobjectwindow.inc"
43 #include "overlayframe.inc"
44 #include "pluginvclient.h"
47 #include "opencv2/core/core_c.h"
48 #include "opencv2/objdetect/objdetect.hpp"
49 #include "opencv2/core/mat.hpp"
50 #include "opencv2/imgproc/types_c.h"
51 #include "opencv2/imgproc/imgproc.hpp"
52 #include "opencv2/legacy/blobtrack.hpp"
55 class FindObjectWindow;
62 // Limits of global range in percent
64 #define MAX_RADIUS 200
66 // Limits of block size in percent.
76 // Sizes must be quantized a certain amount for OpenCV
79 // Storage for results
80 #define FINDOBJECT_FILE "/tmp/findobject"
82 #define MIN_CAMSHIFT 0
83 #define MAX_CAMSHIFT 256
86 #define NO_ALGORITHM 0
88 #define ALGORITHM_SURF 1
90 #define ALGORITHM_CAMSHIFT 2
91 #define ALGORITHM_BLOB 3
93 class FindObjectConfig
98 int equivalent(FindObjectConfig &that);
99 void copy_from(FindObjectConfig &that);
100 void interpolate(FindObjectConfig &prev,
101 FindObjectConfig &next,
104 int64_t current_frame);
109 // Block size as percent of image size
110 // Object must be a rectangle for the algorithm to work,
111 // so no oblique edges unless we also do an affine transform.
112 float global_block_w;
113 float global_block_h;
114 // Block position in percentage 0 - 100
119 // Draw border over object in scene layer
121 // Draw transparency over object in object layer
123 // Draw border over object
124 int draw_object_border;
126 // Which layer is the object 0 or 1
128 // Which layer replaces the object
130 // Which layer is the object searched for in
134 // Camshift parameters
135 int vmin, vmax, smin;
136 // Amount to blend new object position in
143 class FindObjectMain : public PluginVClient
146 FindObjectMain(PluginServer *server);
149 int process_buffer(VFrame **frame,
150 int64_t start_position,
152 void draw_vectors(VFrame *frame);
153 int is_multichannel();
155 void save_data(KeyFrame *keyframe);
156 void read_data(KeyFrame *keyframe);
158 // Calculate frame to copy from and frame to move
159 void calculate_pointers(VFrame **frame, VFrame **src, VFrame **dst);
160 void allocate_temp(int w, int h, int color_model);
162 PLUGIN_CLASS_MEMBERS2(FindObjectConfig)
165 AffineEngine *affine;
166 // Temporary for affine overlay
168 OverlayFrame *overlayer;
170 static void draw_pixel(VFrame *frame, int x, int y);
171 static void draw_line(VFrame *frame, int x1, int y1, int x2, int y2);
172 static void draw_rect(VFrame *frame, int x1, int y1, int x2, int y2);
174 void grey_crop(unsigned char *dst,
186 void process_camshift();
191 // clamped coordinates
211 // Latest coordinates of object in scene
220 // Coordinates of object in scene with blending
221 float border_x1_accum;
222 float border_y1_accum;
223 float border_x2_accum;
224 float border_y2_accum;
225 float border_x3_accum;
226 float border_y3_accum;
227 float border_x4_accum;
228 float border_y4_accum;
232 IplImage *object_image;
233 IplImage *scene_image;
236 // Comparison with current object_image
237 unsigned char *prev_object;
243 CvSeq *object_keypoints;
244 CvSeq *object_descriptors;
245 CvSeq *scene_keypoints;
246 CvSeq *scene_descriptors;
247 CvMemStorage *storage;
256 int blob_initialized;
257 CvBlobTrackerAutoParam1 blob_param;
258 CvBlobTrackerAuto* blob_pTracker;