~charon-developers/+junk/gerald-edevis

« back to all changes in this revision

Viewing changes to LinearMotionCompensation/LinearMotionCompensation.h

  • Committer: Gerald Mwangi
  • Date: 2013-06-20 08:32:46 UTC
  • Revision ID: gerald.mwangi@gmx.de-20130620083246-5rj592zfiu0ohovc
Initialized edevis branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  Copyright (C) 2013 Gerald Mwangi
 
2
 
 
3
        This file is part of Charon.
 
4
 
 
5
        Charon is free software: you can redistribute it and/or modify
 
6
        it under the terms of the GNU Lesser General Public License as published by
 
7
        the Free Software Foundation, either version 3 of the License, or
 
8
        (at your option) any later version.
 
9
 
 
10
        Charon is distributed in the hope that it will be useful,
 
11
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
        GNU Lesser General Public License for more details.
 
14
 
 
15
        You should have received a copy of the GNU Lesser General Public License
 
16
        along with Charon.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
/** \file LinearMotionCompensation.h
 
19
 *  Declaration of the parameter class LinearMotionCompensation.
 
20
 *  \author <a href="mailto:gerald.mwangi@gmx.de">
 
21
 *      Gerald Mwangi</a>
 
22
 *  \date 19.06.2013
 
23
 */
 
24
 
 
25
#ifndef _LINEARMOTIONCOMPENSATION_H_
 
26
#define _LINEARMOTIONCOMPENSATION_H_
 
27
 
 
28
#ifdef _MSC_VER
 
29
#ifdef linearmotioncompensation_EXPORTS
 
30
/// Visual C++ specific code
 
31
#define linearmotioncompensation_DECLDIR __declspec(dllexport)
 
32
#else
 
33
#define linearmotioncompensation_DECLDIR __declspec(dllimport)
 
34
#endif /*Export or import*/
 
35
#else
 
36
/// Not needed without MSVC
 
37
#define linearmotioncompensation_DECLDIR
 
38
#endif
 
39
 
 
40
#include <charon-core/ParameteredObject.h>
 
41
#include <charon-utils/Roi.hxx>
 
42
#include <vigra/multi_array.hxx>
 
43
#include <opencv2/opencv.hpp>
 
44
using namespace std;
 
45
/// Compensates linear motion in an image sequence
 
46
/** Compensates linear motion in an image sequence, using the sift detector in
 
47
 *  the opencv library. The motion is assumed to be constrained to the image
 
48
 *  plane (x,y coordinates), thus no  motion in z direction.
 
49
 */
 
50
template <typename T>
 
51
class linearmotioncompensation_DECLDIR LinearMotionCompensation :
 
52
                public TemplatedParameteredObject<T> {
 
53
public:
 
54
        /// default constructor
 
55
        /// \param name          Instance name
 
56
        LinearMotionCompensation(const std::string& name = "");
 
57
 
 
58
        /// sequence with linear motion
 
59
        InputSlot< vigra::MultiArray<5,T> > image_sequence;
 
60
        /// roi to estimate the linear motion
 
61
        InputSlot< Roi<T>* > roi;
 
62
 
 
63
        /// motion compensated sequence
 
64
        OutputSlot< vigra::MultiArray<5,T> > compensated_sequence;
 
65
        /// image sequence with found features
 
66
        OutputSlot< vigra::MultiArray<5,T> > feature_sequence;
 
67
 
 
68
        /// allowed deviation from linear motion model
 
69
        Parameter< double > motion_tolerance;
 
70
        /// Fraction of the number features with motion tolerance below
 
71
        /// motion_tolerance parameter and total number of found features. Values
 
72
        /// ~1 mean nearly all features are required to have a linear motion,
 
73
        /// values ~0 mean no features must have a linear motion.
 
74
        Parameter< double > good_feature_fraction;
 
75
 
 
76
 
 
77
protected:
 
78
        /// Update object.
 
79
        virtual void execute();
 
80
    void getCvMatFrame(cv::Mat& out,int frame, bool create);
 
81
    cv::Mat warpImage(cv::Mat src,cv::Mat dst, cv::Mat &dst_imkpts);
 
82
    void determinParameters(vector< cv::Point2f > best_src,vector< cv::Point2f > best_dst,float& cos_theta,cv::Point2f& trans);
 
83
    float errorFunction(float cos_theta,cv::Point2f trans,cv::Point2f src,cv::Point2f dst);
 
84
    void findAffineTrans(vector< cv::DMatch >  matches,vector<cv::KeyPoint> srckpts,vector<cv::KeyPoint> dstkpts,float tolerance,float inlier_frac,int max_iter,cv::Mat& affTrans);
 
85
    void copyFrameToOut(cv::Mat& in, cv::Mat &inkpts, int frame);
 
86
};
 
87
 
 
88
#endif // _LINEARMOTIONCOMPENSATION_H_