00001 // ---------------------------------------------------------------------------- 00002 // 00003 // $Id$ 00004 // 00005 // Copyright 2008, 2009, 2010, 2011, 2012 Antonio Franchi and Paolo Stegagno 00006 // 00007 // This file is part of MIP. 00008 // 00009 // MIP is free software: you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 3 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // MIP is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it 00023 // 00024 // ---------------------------------------------------------------------------- 00025 00026 #ifndef BASIC_OPTICAL_FLOW_H 00027 #define BASIC_OPTICAL_FLOW_H 00028 00029 #include <SpacesArma.h> 00030 #include <opencv2/opencv.hpp> 00031 #include <opencv2/highgui/highgui.hpp> 00032 00033 namespace MipAlgorithms{ 00037 00041 00043 /* @{ */ 00044 00045 class basicOpticalFlowPar { 00046 public: 00047 bool visualize; 00048 bool dense; 00049 Decimal pyrScale; // used to set pyramid scaling factor (default = 0.5) 00050 Decimal pyrLevels; // used to set pyramid levels (default = 3) 00051 Decimal polySigma; // Standard deviation to smooth derivatives (linked to polyN, default = 1.1) 00052 int iterations; // number of iterations (default = 5) 00053 int polyN; // Size of the pixel neighborhood (typical 5 or 7, default = 5) 00054 int winSize; // Size of search window 00055 int maxCorners; 00056 Decimal qualityLevel; 00057 Decimal minDistance; 00058 00060 basicOpticalFlowPar(); 00061 }; 00062 00066 class basicOpticalFlow { 00067 private: 00068 basicOpticalFlowPar* _par; 00069 cv::Mat prevImage, grayim, cflow, currFlow; 00070 00071 std::vector<cv::Point2f> prevFeatures; 00072 std::vector<cv::Point2f> currFeatures; 00073 std::vector<uchar> status; 00074 std::vector<float> errors; 00075 int featuresNumber; 00076 00077 void drawOptFlowMap(const cv::Mat& flow, cv::Mat& cflowmap, int step, double, const cv::Scalar& color); 00078 00079 public: 00081 basicOpticalFlow(cv::Mat & initImage); 00082 ~basicOpticalFlow(); 00083 00085 void visualizeOutput(); 00086 00089 void getFlow(cv::Mat & newImage, cv::Mat & flow); 00090 }; 00091 00092 /* @} */ 00093 };// end namespace MipAlgorithms 00094 00095 00096 #endif /* __LUCAKANADE_H */