1
/* Copyright (C) 2013 Gerald Mwangi
3
This file is part of Charon.
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.
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.
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/>.
18
/** \file LinearMotionCompensation.h
19
* Declaration of the parameter class LinearMotionCompensation.
20
* \author <a href="mailto:gerald.mwangi@gmx.de">
25
#ifndef _LINEARMOTIONCOMPENSATION_H_
26
#define _LINEARMOTIONCOMPENSATION_H_
29
#ifdef linearmotioncompensation_EXPORTS
30
/// Visual C++ specific code
31
#define linearmotioncompensation_DECLDIR __declspec(dllexport)
33
#define linearmotioncompensation_DECLDIR __declspec(dllimport)
34
#endif /*Export or import*/
36
/// Not needed without MSVC
37
#define linearmotioncompensation_DECLDIR
40
#include <charon-core/ParameteredObject.h>
41
#include <charon-utils/Roi.hxx>
42
#include <vigra/multi_array.hxx>
43
#include <opencv2/opencv.hpp>
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.
51
class linearmotioncompensation_DECLDIR LinearMotionCompensation :
52
public TemplatedParameteredObject<T> {
54
/// default constructor
55
/// \param name Instance name
56
LinearMotionCompensation(const std::string& name = "");
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;
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;
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;
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);
88
#endif // _LINEARMOTIONCOMPENSATION_H_