00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef VOBJ_TRACKER
00021 #define VOBJ_TRACKER
00022
00023 #include <memory>
00024 #include <set>
00025
00026 #include "kpttracker.h"
00027 #include "visual_database.h"
00028
00032
00033 class vobj_instance
00034 {
00035 public:
00036 visual_object *object;
00037 int support;
00038
00039
00040 float transform[3][3];
00041 CvMat get_transform() { CvMat m; cvInitMatHeader(&m, 3, 3, CV_32FC1, transform); return m; }
00042 };
00043 typedef std::vector<vobj_instance> vobj_instance_vector;
00044
00045 class vobj_keypoint : public pyr_keypoint
00046 {
00047 public:
00048 visual_object *vobj;
00049 db_keypoint *obj_kpt;
00050
00051 vobj_keypoint() : vobj(0), obj_kpt(0) {}
00052
00053 vobj_keypoint *prev_match_vobj() { return static_cast<vobj_keypoint *>(matches.prev); }
00054 vobj_keypoint *next_match_vobj() { return static_cast<vobj_keypoint *>(matches.next); }
00055
00056 virtual void dispose() { vobj=0; pyr_keypoint::dispose(); }
00057
00058 struct vobj_keypoint_factory_t : pyr_keypoint_factory_t {
00059 virtual tkeypoint *create() { return new vobj_keypoint(); }
00060 };
00061 };
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 class vobj_frame : public pyr_frame
00076 {
00077 public:
00078 vobj_instance_vector visible_objects;
00079
00080 vobj_frame(PyrImage *p, int bits=4) : pyr_frame(p, bits) {}
00081
00082 vobj_instance *find_instance(visual_object *obj);
00083 vobj_keypoint *find_closest_match(float u, float v, float radius);
00084
00085 struct vobj_frame_factory_t : pyr_frame_factory_t {
00086 virtual pyr_frame *create(PyrImage *p, int bits=4) { return new vobj_frame(p,bits); }
00087 };
00088 };
00089
00090 class vobj_tracker : public kpt_tracker
00091 {
00092 public:
00093
00094 visual_database *vdb;
00095 std::auto_ptr<incremental_query> query;
00096
00097 float score_threshold;
00098 int max_results;
00099
00101 int homography_corresp_threshold;
00102
00104 int fmat_corresp_threshold;
00105
00106 vobj_tracker(int width, int height, int levels, int max_motion, visual_database *vdb=0, bool glContext=false,
00107 pyr_keypoint::pyr_keypoint_factory_t *kf=0,
00108 vobj_frame::vobj_frame_factory_t *ff=0,
00109 pyr_track::pyr_track_factory_t *tf=0);
00110
00111
00112 virtual pyr_frame *process_frame(IplImage *im);
00113 virtual pyr_frame *process_frame_pipeline(IplImage *im);
00114 int track_objects(vobj_frame *frame, vobj_frame *last_frame);
00115
00116 void remove_visible_objects_from_db(vobj_frame *frame);
00117 void incremental_learning(vobj_frame *frame, int track_length, float radius, int max_pts);
00118
00119 bool use_incremental_learning;
00120 protected:
00121
00122 void find_candidates(vobj_frame *frame, std::set<visual_object *> &candidates, vobj_frame *last_frame);
00123 bool verify(vobj_frame *frame, visual_object *obj, vobj_instance *instance);
00124 };
00125
00127 #endif