├── .gitignore ├── ErrorAnalyser ├── .gitignore └── ErrorAnalyser │ ├── ErrorAnalyser.vcxproj.filters │ └── main.cpp ├── LICENSE.txt ├── README.md ├── SDK_LITIV ├── .gitignore ├── SDK_LITIV.sdf ├── lib │ ├── slAlgorithms22.dll │ ├── slAlgorithms22.exp │ ├── slAlgorithms22.lib │ ├── slAlgorithms22.pdb │ ├── slAlgorithms22d.dll │ ├── slAlgorithms22d.exp │ ├── slAlgorithms22d.ilk │ ├── slAlgorithms22d.lib │ ├── slAlgorithms22d.pdb │ ├── slBgSub22.dll │ ├── slBgSub22.exp │ ├── slBgSub22.lib │ ├── slBgSub22.pdb │ ├── slBgSub22d.dll │ ├── slBgSub22d.exp │ ├── slBgSub22d.ilk │ ├── slBgSub22d.lib │ ├── slBgSub22d.pdb │ ├── slCam22.exp │ ├── slCam22.lib │ ├── slCam22d.dll │ ├── slCam22d.exp │ ├── slCam22d.ilk │ ├── slCam22d.lib │ ├── slCam22d.pdb │ ├── slCore22.dll │ ├── slCore22.exp │ ├── slCore22.lib │ ├── slCore22.pdb │ ├── slCore22d.dll │ ├── slCore22d.exp │ ├── slCore22d.ilk │ ├── slCore22d.lib │ ├── slCore22d.pdb │ ├── slIO22.dll │ ├── slIO22.exp │ ├── slIO22.lib │ ├── slIO22.pdb │ ├── slIO22d.dll │ ├── slIO22d.exp │ ├── slIO22d.ilk │ ├── slIO22d.lib │ └── slIO22d.pdb ├── slAlgorithms │ ├── include │ │ ├── slAlgorithms.h │ │ ├── slBlobAnalyzer.h │ │ ├── slContourEngine.h │ │ ├── slDescriptor.h │ │ ├── slKeyPoint.h │ │ ├── slSpherGaussMixMat.h │ │ └── slSphericalGaussian.h │ ├── slAlgorithms.vcxproj.filters │ └── src │ │ ├── slAlgorithms.cpp │ │ ├── slBlobAnalyzer.cpp │ │ ├── slContourEngine.cpp │ │ ├── slDescriptor.cpp │ │ ├── slKeyPoint.cpp │ │ ├── slSpherGaussMixMat.cpp │ │ └── slSphericalGaussian.cpp ├── slBgSub │ ├── include │ │ ├── slBgSub.h │ │ ├── slEpsilon3ch.h │ │ ├── slGaussMixture.h │ │ ├── slMedian.h │ │ ├── slMinMax.h │ │ ├── slNonFgKeepFg.h │ │ ├── slNonFgMergeFg.h │ │ ├── slOpenCv.h │ │ ├── slRectGaussMixture.h │ │ ├── slRectMedian.h │ │ ├── slRectSimple.h │ │ ├── slSimpleGauss.h │ │ ├── slTempAvg.h │ │ ├── slTestComparaison.h │ │ └── slTexture.h │ ├── slBgSub.vcxproj.filters │ └── src │ │ ├── slBgSub.cpp │ │ ├── slEpsilon3ch.cpp │ │ ├── slGaussMixture.cpp │ │ ├── slMedian.cpp │ │ ├── slNonFgKeepFg.cpp │ │ ├── slNonFgMergeFg.cpp │ │ ├── slOpenCv.cpp │ │ ├── slRectGaussMixture.cpp │ │ ├── slRectMedian.cpp │ │ ├── slRectSimple.cpp │ │ ├── slSimpleGauss.cpp │ │ ├── slTempAvg.cpp │ │ ├── slTestComparaison.cpp │ │ └── slTexture.cpp ├── slCam │ ├── ReadMe.txt │ ├── include │ │ ├── slCamIn.h │ │ ├── slCameraSynchro.h │ │ ├── slFlirCam.h │ │ ├── slIpelaCam.h │ │ └── slUnibrainCam.h │ ├── res │ │ └── slCam.rc2 │ ├── resource.h │ ├── slCam.cpp │ ├── slCam.def │ ├── slCam.h │ ├── slCam.rc │ ├── slCam.vcxproj.filters │ ├── slCamd.def │ ├── src │ │ ├── slCamIn.cpp │ │ ├── slCameraSynchro.cpp │ │ ├── slFlirCam.cpp │ │ ├── slIpelaCam.cpp │ │ └── slUnibrainCam.cpp │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h ├── slCore │ ├── include │ │ ├── slArgHandler.h │ │ ├── slClock.h │ │ ├── slContours.h │ │ ├── slCore.h │ │ ├── slException.h │ │ ├── slHistogram3ch.h │ │ ├── slMedianContainer.h │ │ ├── slParamGenerator.h │ │ ├── slQuantParams.h │ │ ├── slRectPixels.h │ │ └── slWindow.h │ ├── slCore.vcxproj.filters │ └── src │ │ ├── slArgHandler.cpp │ │ ├── slClock.cpp │ │ ├── slContours.cpp │ │ ├── slCore.cpp │ │ ├── slException.cpp │ │ ├── slHistogram3ch.cpp │ │ ├── slParamGenerator.cpp │ │ ├── slQuantParams.cpp │ │ ├── slRectPixels.cpp │ │ └── slWindow.cpp └── slIO │ ├── include │ ├── slIO.h │ ├── slImageIn.h │ ├── slImageOut.h │ ├── slIn.h │ ├── slOut.h │ ├── slVideoIn.h │ └── slVideoOut.h │ ├── slIO.vcxproj.filters │ ├── slIO_Parameters.txt │ └── src │ ├── slIO.cpp │ ├── slImageIn.cpp │ ├── slImageOut.cpp │ ├── slIn.cpp │ ├── slOut.cpp │ ├── slVideoIn.cpp │ └── slVideoOut.cpp ├── blobAnalyzer ├── .gitignore └── main.cpp └── pointsMatcher ├── .gitignore ├── KeyPt.cpp ├── KeyPt.h ├── Outils.cpp ├── Outils.h ├── main.cpp └── pointsMatcher.sdf /.gitignore: -------------------------------------------------------------------------------- 1 | 3rdparty 2 | Debug 3 | Release 4 | *.sln 5 | *.suo 6 | *.doc 7 | *.vcxproj 8 | *.user 9 | FD 10 | Results 11 | ManualRegDisp -------------------------------------------------------------------------------- /ErrorAnalyser/.gitignore: -------------------------------------------------------------------------------- 1 | 3rdparty 2 | Debug 3 | Release 4 | *.sln 5 | *.suo 6 | *.doc 7 | *.vcxproj 8 | *.user 9 | *.txt -------------------------------------------------------------------------------- /ErrorAnalyser/ErrorAnalyser/ErrorAnalyser.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Fichiers sources 20 | 21 | 22 | -------------------------------------------------------------------------------- /ErrorAnalyser/ErrorAnalyser/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | vector &split(const string &s, char delim, vector &elems) { 9 | stringstream ss(s); 10 | string item; 11 | while(getline(ss, item, delim)) { 12 | elems.push_back(item); 13 | } 14 | return elems; 15 | } 16 | 17 | vector split(const string &s, char delim) { 18 | vector elems; 19 | return split(s, delim, elems); 20 | } 21 | 22 | void main() 23 | { 24 | double erreur; 25 | unsigned int nbFrame; 26 | string line; 27 | string input = ""; 28 | 29 | while (true) 30 | { 31 | erreur = 0; 32 | nbFrame = 0; 33 | 34 | cout << "Nom du fichier : "; 35 | cin >> input; 36 | 37 | if (input == "exit") 38 | break; 39 | 40 | vector output; 41 | 42 | ifstream myfile (input); 43 | 44 | if (myfile.is_open()) 45 | { 46 | while ( myfile.good() ) 47 | { 48 | getline(myfile, line); 49 | 50 | if (line != "") 51 | { 52 | output = split(line, ' '); 53 | 54 | erreur += ::atof(output[4].c_str()); 55 | ++nbFrame; 56 | } 57 | } 58 | myfile.close(); 59 | 60 | cout << "Erreur totale pour " << nbFrame << " frames = " << erreur << endl; 61 | cout << "Erreur totale moyenne = " << erreur/nbFrame << endl << endl; 62 | } 63 | else 64 | { 65 | cout << "Unable to open file" << endl << endl; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This directory contains the source code for the Automatic Image Registration Method ( Paper titled 'Automatic Image Registration in Infrared-Visible Videos using Polygon Vertices'). 2 | 3 | It uses Background Substraction, Discrete Curve Evolution and Polygon Vertices Matching for image registration from visible and infrared modalities. 4 | For details please refer the paper. 5 | 6 | The paper is available on https://arxiv.org/pdf/1403.4232.pdf 7 | 8 | The algorithm has dependency of SDK_LITIV and OpenCV 2.4.3. 9 | The libs of SDK_LITIV are contained in the lib folder under SDK_LITIV folder. 10 | 11 | Usage: Run the main.cpp in pointsMatcher directory. For changing the temporal buffer size change the NB_FRAME_MEMORY macro 12 | 13 | ----------- 14 | Copyright (c) Tanushri Chakravorty (tanushri.chakravorty@polymtl.ca). All rights reserved. 15 | 16 | See LICENSE.txt for more details. 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SDK_LITIV/.gitignore: -------------------------------------------------------------------------------- 1 | 3rdparty 2 | Debug 3 | Release 4 | *.sln 5 | *.suo 6 | *.doc 7 | *.vcxproj 8 | *.user 9 | mediaFiles 10 | developpement 11 | ipch -------------------------------------------------------------------------------- /SDK_LITIV/SDK_LITIV.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/SDK_LITIV.sdf -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22.pdb -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22d.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22d.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22d.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22d.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22d.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22d.ilk -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22d.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slAlgorithms22d.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slAlgorithms22d.pdb -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22.pdb -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22d.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22d.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22d.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22d.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22d.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22d.ilk -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22d.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slBgSub22d.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slBgSub22d.pdb -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCam22.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCam22.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCam22.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCam22.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCam22d.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCam22d.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCam22d.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCam22d.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCam22d.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCam22d.ilk -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCam22d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCam22d.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCam22d.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCam22d.pdb -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22.pdb -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22d.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22d.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22d.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22d.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22d.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22d.ilk -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22d.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slCore22d.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slCore22d.pdb -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22.pdb -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22d.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22d.dll -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22d.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22d.exp -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22d.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22d.ilk -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22d.lib -------------------------------------------------------------------------------- /SDK_LITIV/lib/slIO22d.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/lib/slIO22d.pdb -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/include/slAlgorithms.h: -------------------------------------------------------------------------------- 1 | /*! \file slAlgorithms.h 2 | * \brief This file contains DLL stuff for slAlgorithms 3 | * 4 | * \author Pier-Luc St-Onge 5 | * \date November 2011 6 | */ 7 | 8 | #ifndef SLALGORITHMS_H 9 | #define SLALGORITHMS_H 10 | 11 | 12 | #ifndef SLALGORITHMS_DLL_EXPORT 13 | #ifdef WIN32 14 | #define SLALGORITHMS_DLL_EXPORT __declspec(dllexport) 15 | #else 16 | #define SLALGORITHMS_DLL_EXPORT 17 | #endif 18 | #endif 19 | 20 | 21 | #endif // SLALGORITHMS_H 22 | 23 | 24 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/include/slContourEngine.h: -------------------------------------------------------------------------------- 1 | /*! \file slContourEngine.h 2 | * \brief This file contains class slContourEngine. 3 | * 4 | * \author Pier-Luc St-Onge 5 | * \date November 2011 6 | */ 7 | 8 | #ifndef SLCONTOURENGINE_H 9 | #define SLCONTOURENGINE_H 10 | 11 | 12 | #include "slAlgorithms.h" 13 | 14 | #include 15 | #include 16 | 17 | 18 | //! This class adds additionnal functionalities to slContours 19 | /*! 20 | * This class can find contours on a binary image (slImage1ch), but 21 | * according to its configuration, it can also preprocess the input 22 | * image before finding the contours. 23 | * For example, setClosure() can enable a closure on the image 24 | * before slContours::findAll() is called. 25 | * 26 | * \see slContours, slBlobAnalyzer 27 | * \author Pier-Luc St-Onge 28 | * \date July 2011 29 | */ 30 | class SLALGORITHMS_DLL_EXPORT slContourEngine 31 | { 32 | public: 33 | slContourEngine(); //!< Constructor 34 | virtual ~slContourEngine(); 35 | 36 | static void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap); //!< To get the possible parameters 37 | 38 | // Set Functions 39 | 40 | void setParameters(const slAH::slParameters& parameters); //!< To set the parameters 41 | 42 | void setClosure(bool enabled, int w = 3, int h = 3); //!< To enable the closure filter and set the kernel size 43 | 44 | void showParameters() const; //!< To show the parameters for the closure 45 | 46 | // Compute functions 47 | 48 | void findContours(slImage1ch &bForeground); //!< Does a closure on bForeground if needed, then calls slContours::findAll() 49 | 50 | static slContour approximate(const slContour &contour, double distance); //!< Contour approximation, distance is the maximum error of approximation 51 | 52 | // Get Functions 53 | 54 | const slContours& getContours() const { return contours_; } //!< Returns found contours 55 | 56 | private: 57 | bool doClosure_; 58 | cv::Mat kernel_; 59 | 60 | slContours contours_; 61 | 62 | }; 63 | 64 | 65 | #endif // SLCONTOURENGINE_H 66 | 67 | 68 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/include/slDescriptor.h: -------------------------------------------------------------------------------- 1 | /*! \file slDescriptor.h 2 | * \brief This file contains classes slDescriptor, 3 | * slDceK and slSkelRelDist 4 | * 5 | * \author Pier-Luc St-Onge 6 | * \date July 2011 7 | */ 8 | 9 | #ifndef SLDESCRIPTOR_H 10 | #define SLDESCRIPTOR_H 11 | 12 | 13 | #include "slAlgorithms.h" 14 | 15 | #include 16 | #include 17 | 18 | 19 | #define DESC_K "K" //!< Descriptor name for DCE method 20 | #define DESC_RELDIST "RelDist" //!< Descriptor name for skeleton method 21 | 22 | 23 | //! This is the base class for all key points' descriptor 24 | /*! 25 | * This class is abstract. 26 | * 27 | * The different descriptor names are defined in slKeyPoint.h. 28 | * 29 | * \see slDceK, slSkelRelDist, slKeyPoint, slBlobAnalyzer 30 | * \author Pier-Luc St-Onge 31 | * \date July 2011 32 | */ 33 | class SLALGORITHMS_DLL_EXPORT slDescriptor 34 | { 35 | public: 36 | slDescriptor(); //!< Constructor 37 | virtual ~slDescriptor(); 38 | 39 | virtual slDescriptor* clone() const = 0; //!< To get a clone of the descriptor 40 | virtual std::string getName() const = 0; //!< To get the name of the descriptor 41 | 42 | }; 43 | 44 | 45 | //! This class represents the K value in DCE method. 46 | /*! 47 | * In the DCE method, the only descriptor for a key point is the k value. 48 | * 49 | * This class also implements some algorithms to compute the k value. 50 | * 51 | * \see slDce, slDescriptor, slKeyPoint, slKeyPoint.h 52 | * \author Pier-Luc St-Onge 53 | * \date July 2011 54 | */ 55 | class SLALGORITHMS_DLL_EXPORT slDceK: public slDescriptor 56 | { 57 | public: 58 | slDceK(float k = 0); //!< Constructor 59 | 60 | virtual slDceK* clone() const; //!< Generates a clone (calls copy constructor) 61 | virtual std::string getName() const; //!< Returns DESC_K (see slKeyPoint.h) 62 | 63 | // Score function 64 | float scoreK(const slDceK &k2) const; //!< Comparison function between two k values (negative normalized difference). 65 | 66 | static float compute(const cv::Point &p0, const cv::Point &p1, const cv::Point &p2); //!< Computes k value, integer components 67 | static float compute(const cv::Point2f &p0, const cv::Point2f &p1, const cv::Point2f &p2); //!< Computes k value, float components 68 | 69 | public: 70 | float k_; //!< The k value, read and write public access 71 | 72 | }; 73 | 74 | 75 | //! This class represents the relative distance value for the skeleton method 76 | /*! 77 | * In the skeleton method, the descriptor for a key point is the normalized 78 | * distance between the point inside a blob and the closest point on the 79 | * contour of that blob. 80 | * In other words, the distance transform applied to a given blob is normalized 81 | * to values limited from 0.0 to 1.0. 82 | * So, the relative distance of a key point is only the value of the 83 | * normalized distance transform for that key point which is inside the blob. 84 | * 85 | * This descriptor of a key point on the skeleton should be resistant 86 | * to scaling and rotation of the blob. 87 | * 88 | * \see slSkel, slDescriptor, slKeyPoint, slKeyPoint.h 89 | * \author Pier-Luc St-Onge 90 | * \date July 2011 91 | */ 92 | class SLALGORITHMS_DLL_EXPORT slSkelRelDist: public slDescriptor 93 | { 94 | public: 95 | slSkelRelDist(float relDist = 0); //!< Constructor 96 | 97 | virtual slSkelRelDist* clone() const; //!< Generates a clone (calls copy constructor) 98 | virtual std::string getName() const; //!< Returns DESC_RELDIST (see slKeyPoint.h) 99 | 100 | // Score function 101 | float scoreRelDist(const slSkelRelDist &rd2) const; //!< Comparison function between two relative distances (negative absolute difference). 102 | 103 | public: 104 | float relDist_; //!< The relative distance, read and write public access 105 | 106 | }; 107 | 108 | 109 | #endif // SLDESCRIPTOR_H 110 | 111 | 112 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/include/slKeyPoint.h: -------------------------------------------------------------------------------- 1 | /*! \file slKeyPoint.h 2 | * \brief This file contains class slKeyPoint 3 | * and some defines 4 | * 5 | * \author Pier-Luc St-Onge 6 | * \date July 2011 7 | */ 8 | 9 | #ifndef SLKEYPOINT_H 10 | #define SLKEYPOINT_H 11 | 12 | 13 | #include "slDescriptor.h" 14 | 15 | #include 16 | #include 17 | 18 | 19 | typedef std::vector CvPt2fVector_t; //!< Vector of points, float components 20 | typedef std::vector CvPtVector_t; //!< Vector of points, integer components 21 | 22 | 23 | //! This class is the key point 24 | /*! 25 | * A key point has a position (float components only), 26 | * neighbor key points and one or many descriptors. 27 | * 28 | * \see slBlobAnalyzer, slDescriptor, slKeyPoint.h 29 | * \author Pier-Luc St-Onge 30 | * \date July 2011 31 | */ 32 | class SLALGORITHMS_DLL_EXPORT slKeyPoint 33 | { 34 | public: 35 | slKeyPoint(); //!< Default constructor 36 | slKeyPoint(const slKeyPoint &kPt); //!< Copy constructor (calls operator=) 37 | 38 | ~slKeyPoint(); 39 | 40 | const slKeyPoint& operator=(const slKeyPoint &kPt); //!< Copies attributes, clones descriptors 41 | 42 | void moveTo(const cv::Point2f &position); //!< Sets the position of the key point 43 | const cv::Point2f& position() const; //!< Returns the position of the key point 44 | 45 | void insert(const cv::Point &neighbor); //!< Saves a neighbor point, integer components 46 | void insert(const cv::Point2f &neighbor); //!< Saves a neighbor point, float components 47 | 48 | CvPt2fVector_t::const_iterator beginNeighbors() const; //!< First neighbor 49 | CvPt2fVector_t::const_iterator endNeighbors() const; //!< After last neighbor 50 | 51 | const slDescriptor* find(const std::string &name) const; //!< Returns requested descriptor or NULL 52 | void insert(slDescriptor *desc); //!< Saves a descriptor 53 | void remove(const std::string &name); //!< Removes a descriptor 54 | 55 | // Score functions 56 | float scoreEuclidean(const slKeyPoint &kPt2, float diagLength, 57 | int offsetX = 0, int offsetY = 0) const; //!< Comparison function, distance between two key points 58 | float scoreOrientation(const slKeyPoint &kPt2) const; //!< Comparison function, orientation of neighbors of two key points 59 | float scoreNbNeighbors(const slKeyPoint &kPt2) const; //!< Comparison function, number of neighbors of two key points 60 | 61 | private: 62 | void clearDescriptors(); 63 | 64 | private: 65 | cv::Point2f position_; 66 | CvPt2fVector_t neighbors_; 67 | 68 | std::map descriptors_; 69 | 70 | }; 71 | 72 | 73 | //! This is a functor to compare two points of type Point2f 74 | /*! 75 | * Useful for sorting points. 76 | * 77 | * \see slBlobAnalyzer for an example of use, slKeyPoint 78 | * \author Pier-Luc St-Onge 79 | * \date July 2011 80 | */ 81 | struct SLALGORITHMS_DLL_EXPORT CvPoint2fLessThan 82 | { 83 | /*! The comparison operator 84 | * Compares two points. 85 | */ 86 | bool operator()(const cv::Point2f &p1, const cv::Point2f &p2) const 87 | { 88 | if (p1.y < p2.y) return true; 89 | if (p1.y > p2.y) return false; 90 | return (p1.x < p2.x); 91 | } 92 | }; 93 | 94 | 95 | typedef std::map slKeyPoints; //!< Key points container 96 | 97 | 98 | #endif // SLKEYPOINT_H 99 | 100 | 101 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/include/slSpherGaussMixMat.h: -------------------------------------------------------------------------------- 1 | /*! \file slSpherGaussMixMat.h 2 | * \brief This file contains the class slSpherGaussMixMat 3 | * 4 | * \author Pier-Luc St-Onge 5 | * \date February 2012 6 | */ 7 | 8 | // Adaptive background mixture models for real-time tracking 9 | // Chris Stauffer, W.E.L Grimson 10 | // http://www.ai.mit.edu/projects/vsam/Publications/stauffer_cvpr98_track.pdf 11 | 12 | #ifndef SLSPHERGAUSSMIXMAT_H 13 | #define SLSPHERGAUSSMIXMAT_H 14 | 15 | 16 | #include "slSphericalGaussian.h" 17 | 18 | #include 19 | 20 | 21 | //! This class is a vector of vectors of K slSphericalGaussian instances 22 | /*! 23 | * This class and its private sub-classes implement the Gaussian Mixture Model 24 | * algorithm. 25 | * It is a vector of Gaussian mixtures, which are simply a vector of up to K 26 | * sorted instances of slSphericalGaussian. 27 | * While it is implemented as a vector, one could still resize it to the total 28 | * number of pixels in an image. 29 | * 30 | * The Gaussian Mixture parameters are set once, and they are used for all 31 | * mixtures. There are five of these and five corresponding "set" methods. 32 | * 33 | * All new Gaussian distributions are initiated with a default variance. 34 | * The current class does not know anything about the domain of computed 35 | * values, so the "default variance" is 1 by default, and it should be set to 36 | * a proper value since it has some impact on the behavior of the mixture. 37 | * 38 | * \see slSphericalGaussian, slGaussMixture, slRectGaussMixture 39 | * \author Pier-Luc St-Onge 40 | * \date February 2012 41 | */ 42 | class SLALGORITHMS_DLL_EXPORT slSpherGaussMixMat 43 | { 44 | public: 45 | slSpherGaussMixMat(); 46 | 47 | static void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap); //!< To get the parameters' syntax 48 | 49 | // Set functions 50 | 51 | void setK(size_t K); //!< K distributions (default = 3) 52 | void setDefVariance(float defVar); //!< Default variance for new distributions (default = 1.0) 53 | void setDistWidth(float nbStdDev); //!< Distribution width (# std dev.) (default = 2.5) 54 | void setAlpha(float alpha); //!< Learning rate (default = 0.05) 55 | void setT(float T); //!< T threshold : Sum(w_i, 0..B-1) > T, (default = 0.5) 56 | 57 | void setParameters(const slAH::slParameters& parameters); //!< Complete configuration 58 | void showParameters() const; //!< Show parameters' value 59 | 60 | // Compute functions 61 | 62 | void reset(size_t nbMixtures); //!< Global reset on the matrix 63 | bool update(size_t index, const cv::Vec3f &X_t); //!< Returns true if X_t matches a gaussian, then updates the mixture 64 | 65 | // Get functions 66 | 67 | size_t getMixtureSize(size_t index) const; //!< Returns number of activated gaussians 68 | float getWeight(size_t index, size_t k = 0) const; //!< Returns the distribution's weight 69 | const cv::Vec3f& getMean(size_t index, size_t k = 0) const; //!< Returns the mean of a distribution 70 | float getVariance(size_t index, size_t k = 0) const; //!< Returns the variance of a distribution 71 | 72 | private: 73 | class slSpherGaussMix 74 | { 75 | public: 76 | slSpherGaussMix(); 77 | 78 | void reset(size_t K); //!< Creates K slSphericalGaussian, none is activated 79 | 80 | bool update(const cv::Vec3f &X_t, float variance, 81 | float distW, float alpha, float T); //!< Returns true if X_t matches a gaussian, updates the gaussian mixture 82 | 83 | size_t getSize() const; //!< Returns number of activated slSphericalGaussian 84 | float getWeight(size_t k) const; //!< Returns the distribution's weight 85 | const slSphericalGaussian& operator[](size_t k) const; 86 | 87 | private: 88 | struct slWeightedSpherGauss 89 | { 90 | bool operator<(const slWeightedSpherGauss& wsg) const; 91 | 92 | float weight; 93 | slSphericalGaussian *gaussian; 94 | }; 95 | 96 | private: 97 | std::vector sphericalGaussians_; 98 | std::vector gaussMixture_; 99 | 100 | size_t K_; 101 | size_t B_; 102 | }; 103 | 104 | private: 105 | size_t K_; 106 | 107 | float defaultVariance_; 108 | float distWidth_; 109 | float alpha_; 110 | float T_; 111 | 112 | std::vector gaussMixtures_; 113 | 114 | }; 115 | 116 | 117 | #endif // SLSPHERGAUSSMIXMAT_H 118 | 119 | 120 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/include/slSphericalGaussian.h: -------------------------------------------------------------------------------- 1 | /*! \file slSphericalGaussian.h 2 | * \brief This file contains the class slSphericalGaussian 3 | * 4 | * \author Pier-Luc St-Onge 5 | * \date February 2012 6 | */ 7 | 8 | // Adaptive background mixture models for real-time tracking 9 | // Chris Stauffer, W.E.L Grimson 10 | // http://www.ai.mit.edu/projects/vsam/Publications/stauffer_cvpr98_track.pdf 11 | 12 | #ifndef SLSPHERICALGAUSSIAN_H 13 | #define SLSPHERICALGAUSSIAN_H 14 | 15 | 16 | #include "slAlgorithms.h" 17 | 18 | #include 19 | 20 | 21 | //! This class is a spherical Gaussian model 22 | /*! 23 | * There is only one common variance for a 3-channels model. 24 | * The three channels are independent. 25 | * 26 | * \see slSpherGaussMixMat 27 | * \author Pier-Luc St-Onge 28 | * \date February 2012 29 | */ 30 | class SLALGORITHMS_DLL_EXPORT slSphericalGaussian 31 | { 32 | public: 33 | slSphericalGaussian(const cv::Vec3f &mean = cv::Vec3f(0, 0, 0), float variance = 1); //!< Constructor 34 | 35 | void setMean(const cv::Vec3f &mean); //!< Force new mean value vector 36 | const cv::Vec3f& getMean() const; //!< Returns the current mean value vector 37 | 38 | void setVariance(float variance); //!< Force new variance 39 | float getVariance() const; //!< Returns the current variance 40 | 41 | float prob(const cv::Vec3f &X_t) const; //!< Probability of X_t in the distribution 42 | 43 | void insertInlier(const cv::Vec3f &X_t, float alpha = 0.0625f); //!< Update the distribution with X_t and learning rate alpha 44 | bool testInlier(const cv::Vec3f &X_t, float nbStdDev = 3.0f) const; //!< Test if X_t is in the sphere of radius nbStdDev*sqrt(variance) 45 | 46 | private: 47 | // Mean value for all components 48 | cv::Vec3f mean_; 49 | 50 | // Shared variance (spherical distribution) 51 | float variance_; 52 | 53 | }; 54 | 55 | 56 | 57 | #endif // SLSPHERICALGAUSSIAN_H 58 | 59 | 60 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/slAlgorithms.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Fichiers d%27en-tête 20 | 21 | 22 | Fichiers d%27en-tête 23 | 24 | 25 | Fichiers d%27en-tête 26 | 27 | 28 | Fichiers d%27en-tête 29 | 30 | 31 | Fichiers d%27en-tête 32 | 33 | 34 | Fichiers d%27en-tête 35 | 36 | 37 | Fichiers d%27en-tête 38 | 39 | 40 | 41 | 42 | Fichiers sources 43 | 44 | 45 | Fichiers sources 46 | 47 | 48 | Fichiers sources 49 | 50 | 51 | Fichiers sources 52 | 53 | 54 | Fichiers sources 55 | 56 | 57 | Fichiers sources 58 | 59 | 60 | Fichiers sources 61 | 62 | 63 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/src/slAlgorithms.cpp: -------------------------------------------------------------------------------- 1 | #include "slAlgorithms.h" 2 | 3 | 4 | #ifdef WIN32 5 | #include 6 | 7 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved) 8 | { 9 | return TRUE; 10 | } 11 | #endif // WIN32 12 | 13 | 14 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/src/slBlobAnalyzer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slAlgorithms/src/slBlobAnalyzer.cpp -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/src/slContourEngine.cpp: -------------------------------------------------------------------------------- 1 | #include "slContourEngine.h" 2 | #include "slKeyPoint.h" 3 | 4 | #include 5 | #include 6 | 7 | 8 | using namespace cv; 9 | using namespace std; 10 | using namespace slAH; 11 | 12 | 13 | #define ARG_CLOSURE "-c" 14 | 15 | 16 | slContourEngine::slContourEngine() 17 | :doClosure_(false) 18 | { 19 | } 20 | 21 | 22 | slContourEngine::~slContourEngine() 23 | { 24 | kernel_.release(); 25 | contours_.clear(); 26 | } 27 | 28 | 29 | void slContourEngine::fillParamSpecs(slAH::slParamSpecMap& paramSpecMap) 30 | { 31 | paramSpecMap << (slParamSpec(ARG_CLOSURE, "Do closure with kernel size w*k") 32 | << slSyntax("w", "3") << slSyntax("h", "3")); 33 | } 34 | 35 | 36 | void slContourEngine::setParameters(const slAH::slParameters& parameters) 37 | { 38 | // Closure 39 | if (parameters.isParsed(ARG_CLOSURE)) { 40 | setClosure(true, 41 | atoi(parameters.getValue(ARG_CLOSURE, 0).c_str()), 42 | atoi(parameters.getValue(ARG_CLOSURE, 1).c_str())); 43 | } 44 | else { 45 | setClosure(false); 46 | } 47 | } 48 | 49 | 50 | void slContourEngine::setClosure(bool enabled, int w, int h) 51 | { 52 | kernel_.release(); 53 | 54 | if (doClosure_ = enabled) { 55 | kernel_ = getStructuringElement(MORPH_ELLIPSE, Size(w, h)); 56 | } 57 | } 58 | 59 | 60 | void slContourEngine::showParameters() const 61 | { 62 | cout << "--- slContour ---" << endl; 63 | 64 | cout << "Closure : "; 65 | if (doClosure_) { 66 | cout << "Yes, " << kernel_.size().width << "x" << kernel_.size().height << endl; 67 | } 68 | else { 69 | cout << "No" << endl; 70 | } 71 | 72 | cout << endl; 73 | } 74 | 75 | 76 | void slContourEngine::findContours(slImage1ch &bForeground) 77 | { 78 | if (doClosure_) { 79 | morphologyEx(bForeground, bForeground, MORPH_CLOSE, kernel_); 80 | } 81 | 82 | // Find all contours 83 | contours_.findAll(bForeground); 84 | } 85 | 86 | 87 | slContour slContourEngine::approximate(const slContour &contour, double distance) 88 | { 89 | slContour approx; 90 | 91 | if (!contour.empty()) { 92 | CvPt2fVector_t approx2f; 93 | 94 | // Approximate contour 95 | approxPolyDP(contour, approx2f, distance, true); 96 | 97 | // Conversion Point2f->Point 98 | for (CvPt2fVector_t::const_iterator it = approx2f.begin(); it != approx2f.end(); it++) { 99 | approx.push_back(*it); 100 | } 101 | } 102 | 103 | return approx; 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/src/slDescriptor.cpp: -------------------------------------------------------------------------------- 1 | #include "slDescriptor.h" 2 | 3 | 4 | using namespace std; 5 | 6 | 7 | /////////////////////////////////////////////////////////////////////////////// 8 | // slDescriptor 9 | /////////////////////////////////////////////////////////////////////////////// 10 | 11 | 12 | slDescriptor::slDescriptor() 13 | { 14 | } 15 | 16 | 17 | slDescriptor::~slDescriptor() 18 | { 19 | } 20 | 21 | 22 | /////////////////////////////////////////////////////////////////////////////// 23 | // slDceK 24 | /////////////////////////////////////////////////////////////////////////////// 25 | 26 | 27 | slDceK::slDceK(float k): slDescriptor(), k_(k) 28 | { 29 | } 30 | 31 | 32 | slDceK* slDceK::clone() const 33 | { 34 | return new slDceK(*this); 35 | } 36 | 37 | 38 | string slDceK::getName() const 39 | { 40 | return DESC_K; 41 | } 42 | 43 | 44 | float slDceK::scoreK(const slDceK &k2) const 45 | { 46 | float length = sqrt(k_ * k_ + k2.k_ * k2.k_); 47 | 48 | return (-fabs(k_ - k2.k_) / (length > 0 ? length : 1)); 49 | } 50 | 51 | 52 | float slDceK::compute(const cv::Point &p0, const cv::Point &p1, const cv::Point &p2) 53 | { 54 | CvPoint vect1 = cvPoint(p1.x - p0.x, p1.y - p0.y); 55 | CvPoint vect2 = cvPoint(p2.x - p1.x, p2.y - p1.y); 56 | float long1 = sqrt((float)vect1.x * vect1.x + vect1.y * vect1.y); 57 | float long2 = sqrt((float)vect2.x * vect2.x + vect2.y * vect2.y); 58 | float beta = acos(((float)vect1.x * vect2.x + vect1.y * vect2.y) / (long1 * long2)); 59 | 60 | return (beta * long1 * long2 / (long1 + long2)); 61 | } 62 | 63 | 64 | float slDceK::compute(const cv::Point2f &p0, const cv::Point2f &p1, const cv::Point2f &p2) 65 | { 66 | CvPoint2D32f vect1 = cvPoint2D32f(p1.x - p0.x, p1.y - p0.y); 67 | CvPoint2D32f vect2 = cvPoint2D32f(p2.x - p1.x, p2.y - p1.y); 68 | float long1 = sqrt(vect1.x * vect1.x + vect1.y * vect1.y); 69 | float long2 = sqrt(vect2.x * vect2.x + vect2.y * vect2.y); 70 | float beta = acos((vect1.x * vect2.x + vect1.y * vect2.y) / (long1 * long2)); 71 | 72 | return (beta * long1 * long2 / (long1 + long2)); 73 | } 74 | 75 | 76 | /////////////////////////////////////////////////////////////////////////////// 77 | // slSkelRelDist 78 | /////////////////////////////////////////////////////////////////////////////// 79 | 80 | 81 | slSkelRelDist::slSkelRelDist(float relDist): slDescriptor(), relDist_(relDist) 82 | { 83 | } 84 | 85 | 86 | slSkelRelDist* slSkelRelDist::clone() const 87 | { 88 | return new slSkelRelDist(*this); 89 | } 90 | 91 | 92 | string slSkelRelDist::getName() const 93 | { 94 | return DESC_RELDIST; 95 | } 96 | 97 | 98 | float slSkelRelDist::scoreRelDist(const slSkelRelDist &rd2) const 99 | { 100 | return -fabs(relDist_ - rd2.relDist_); 101 | } 102 | 103 | 104 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/src/slKeyPoint.cpp: -------------------------------------------------------------------------------- 1 | #include "slKeyPoint.h" 2 | 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | 8 | /////////////////////////////////////////////////////////////////////////////// 9 | // slKeyPoint 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | 13 | slKeyPoint::slKeyPoint() 14 | { 15 | } 16 | 17 | 18 | slKeyPoint::slKeyPoint(const slKeyPoint &kPt) 19 | { 20 | *this = kPt; 21 | } 22 | 23 | 24 | slKeyPoint::~slKeyPoint() 25 | { 26 | clearDescriptors(); 27 | } 28 | 29 | 30 | void slKeyPoint::clearDescriptors() 31 | { 32 | for (map::iterator it = descriptors_.begin(); 33 | it != descriptors_.end(); it++) 34 | { 35 | delete it->second; 36 | } 37 | 38 | descriptors_.clear(); 39 | } 40 | 41 | 42 | const slKeyPoint& slKeyPoint::operator=(const slKeyPoint &kPt) 43 | { 44 | if (&kPt != this) { 45 | position_ = kPt.position_; 46 | neighbors_ = kPt.neighbors_; 47 | clearDescriptors(); 48 | 49 | for (map::const_iterator it = kPt.descriptors_.begin(); 50 | it != kPt.descriptors_.end(); it++) 51 | { 52 | descriptors_[it->first] = it->second->clone(); 53 | } 54 | } 55 | 56 | return *this; 57 | } 58 | 59 | 60 | void slKeyPoint::moveTo(const cv::Point2f &position) 61 | { 62 | position_ = position; 63 | } 64 | 65 | 66 | const cv::Point2f& slKeyPoint::position() const 67 | { 68 | return position_; 69 | } 70 | 71 | 72 | void slKeyPoint::insert(const cv::Point &neighbor) 73 | { 74 | insert(Point2f(neighbor)); 75 | } 76 | 77 | 78 | void slKeyPoint::insert(const cv::Point2f &neighbor) 79 | { 80 | neighbors_.push_back(neighbor); 81 | } 82 | 83 | 84 | CvPt2fVector_t::const_iterator slKeyPoint::beginNeighbors() const 85 | { 86 | return neighbors_.begin(); 87 | } 88 | 89 | 90 | CvPt2fVector_t::const_iterator slKeyPoint::endNeighbors() const 91 | { 92 | return neighbors_.end(); 93 | } 94 | 95 | 96 | const slDescriptor* slKeyPoint::find(const std::string &name) const 97 | { 98 | map::const_iterator it = descriptors_.find(name); 99 | 100 | return (it != descriptors_.end() ? it->second : NULL); 101 | } 102 | 103 | 104 | void slKeyPoint::insert(slDescriptor *desc) 105 | { 106 | string name(desc->getName()); 107 | 108 | remove(name); 109 | descriptors_[name] = desc; 110 | } 111 | 112 | 113 | void slKeyPoint::remove(const std::string &name) 114 | { 115 | map::iterator it = descriptors_.find(name); 116 | 117 | if (it != descriptors_.end()) { 118 | delete it->second; 119 | descriptors_.erase(it); 120 | } 121 | } 122 | 123 | 124 | float slKeyPoint::scoreEuclidean(const slKeyPoint &kPt2, float diagLength, int offsetX, int offsetY) const 125 | { 126 | float diffx = position_.x + offsetX - kPt2.position_.x; 127 | float diffy = position_.y + offsetY - kPt2.position_.y; 128 | 129 | return (1 / (1 + exp(-3 + 6 * sqrt(diffx * diffx + diffy * diffy) / diagLength))); 130 | } 131 | 132 | 133 | float slKeyPoint::scoreOrientation(const slKeyPoint &kPt2) const 134 | { 135 | const slKeyPoint &kPt1 = *this; 136 | const CvPoint2D32f pt1 = kPt1.position_; 137 | const CvPoint2D32f pt2 = kPt2.position_; 138 | const unsigned int nb1 = kPt1.neighbors_.size(); 139 | const unsigned int nb2 = kPt2.neighbors_.size(); 140 | float *cosTheta = new float[nb1 * nb2]; 141 | 142 | // Compute all possible cos(Theta) 143 | for (unsigned int ind1 = 0; ind1 < nb1; ind1++) { 144 | CvPoint2D32f ne1 = kPt1.neighbors_[ind1]; 145 | 146 | for (unsigned int ind2 = 0; ind2 < nb2; ind2++) { 147 | CvPoint2D32f ne2 = kPt2.neighbors_[ind2]; 148 | 149 | float ax = ne1.x - pt1.x; 150 | float ay = ne1.y - pt1.y; 151 | float bx = ne2.x - pt2.x; 152 | float by = ne2.y - pt2.y; 153 | 154 | cosTheta[ind1 * nb2 + ind2] = (ax * bx + ay * by) / 155 | sqrt((ax * ax + ay * ay) * (bx * bx + by * by)); 156 | } 157 | } 158 | 159 | float sumCosTheta = 0.0f; 160 | 161 | // For each neighbor of point 1 162 | for (unsigned int ind1 = 0; ind1 < nb1; ind1++) { 163 | float *row = &cosTheta[ind1 * nb2]; 164 | int ind2Max = 0; 165 | 166 | // Find the neighbor of point 2 that gives a similar orientation 167 | for (unsigned int ind2 = 1; ind2 < nb2; ind2++) { 168 | if (row[ind2] > row[ind2Max]) ind2Max = ind2; 169 | } 170 | 171 | // Find the neighbor of point 1 that gives a similar orientation 172 | float *col = &cosTheta[ind2Max]; 173 | int ind1Max = 0; 174 | 175 | for (unsigned int ind1_ = 1; ind1_ < nb1; ind1_++) { 176 | if (col[ind1_ * nb2] > col[ind1Max * nb2]) ind1Max = ind1_; 177 | } 178 | 179 | // Update the sum of cos(theta) if points 1 and 2 are mutually choosing each other 180 | if (ind1Max == ind1) sumCosTheta += row[ind2Max]; 181 | } 182 | 183 | delete[] cosTheta; 184 | 185 | return (sumCosTheta / max(nb1, nb2)); 186 | } 187 | 188 | 189 | float slKeyPoint::scoreNbNeighbors(const slKeyPoint &kPt2) const 190 | { 191 | unsigned int nb1 = ( neighbors_.size() > 1) ? 3 : 1; 192 | unsigned int nb2 = (kPt2.neighbors_.size() > 1) ? 3 : 1; 193 | 194 | return ((nb1 == nb2) ? 2.0f : 0.0f); 195 | } 196 | 197 | 198 | -------------------------------------------------------------------------------- /SDK_LITIV/slAlgorithms/src/slSphericalGaussian.cpp: -------------------------------------------------------------------------------- 1 | // Adaptive background mixture models for real-time tracking 2 | // Chris Stauffer, W.E.L Grimson 3 | // http://www.ai.mit.edu/projects/vsam/Publications/stauffer_cvpr98_track.pdf 4 | 5 | #include "slSphericalGaussian.h" 6 | 7 | #define _USE_MATH_DEFINES 8 | #include 9 | 10 | 11 | using namespace cv; 12 | 13 | 14 | slSphericalGaussian::slSphericalGaussian(const cv::Vec3f &mean, float variance) 15 | { 16 | setMean(mean); 17 | setVariance(variance); 18 | } 19 | 20 | 21 | void slSphericalGaussian::setMean(const cv::Vec3f &mean) 22 | { 23 | mean_ = mean; 24 | } 25 | 26 | 27 | const cv::Vec3f& slSphericalGaussian::getMean() const 28 | { 29 | return mean_; 30 | } 31 | 32 | 33 | void slSphericalGaussian::setVariance(float variance) 34 | { 35 | variance_ = variance; 36 | } 37 | 38 | 39 | float slSphericalGaussian::getVariance() const 40 | { 41 | return variance_; 42 | } 43 | 44 | 45 | float slSphericalGaussian::prob(const cv::Vec3f &X_t) const 46 | { 47 | // (X_t - Mu_t) 48 | Vec3f xt_mu = X_t - mean_; 49 | 50 | // -1/2 * (X_t - Mu_t)' * Covar^-1 * (X_t - Mu_t) 51 | // where Covar^-1 = (variance * I(3))^-1 = I(3) / variance 52 | // -1/2 * (X_t - Mu_t)'(X_t - Mu_t) / variance 53 | double exponent = -0.5 * (xt_mu.t() * xt_mu).val[0] / variance_; 54 | 55 | // (2*Pi)^(3/2) * |Covar|^1/2 56 | // where |Covar| = variance * variance * variance = variance ^ 3 57 | // (2*Pi)^(3/2) * (variance^3)^1/2 = (2*Pi*variance)^(3/2) 58 | double den = pow(2 * M_PI * variance_, 1.5); 59 | 60 | return (float)(exp(exponent) / den); 61 | } 62 | 63 | 64 | void slSphericalGaussian::insertInlier(const cv::Vec3f &X_t, float alpha) 65 | { 66 | // X_t - Mu_{t-1} 67 | Vec3f xt_mu = X_t - mean_; 68 | 69 | // rho = alpha * prob(X_t) / prob(Mu_{t-1}) 70 | // rho = alpha * e^(-1/2 * (X_t - Mu_{t-1})' * Covar^-1 * (X_t - Mu_{t-1})) 71 | // where Covar^-1 = (variance * I(3))^-1 = I(3) / variance 72 | // rho = alpha * e^(-1/2 * (X_t - Mu_{t-1})'(X_t - Mu_{t-1}) / variance) 73 | float rho = alpha * (float)exp(-0.5 * (xt_mu.t() * xt_mu).val[0] / variance_); 74 | 75 | // Update Mu_t 76 | // Mu_t = (1 - rho) * Mu_{t-1} + rho * X_t 77 | // mean_ = (1.0f - rho) * mean_ + rho * X_t 78 | // mean_ = mean_ - rho * mean_ + rho * X_t 79 | mean_ += rho * (X_t - mean_); 80 | 81 | // X_t - Mu_t 82 | xt_mu = X_t - mean_; 83 | 84 | // Update variance 85 | // variance_t = (1 - rho) * variance_t-1 + rho * (X_t - Mu_t)'(X_t - Mu_t) 86 | // variance_ = (1.0f - rho) * variance_ + rho * (xt_mu.t() * xt_mu).val[0]; 87 | // variance_ = variance_ - rho * variance_ + rho * (xt_mu.t() * xt_mu).val[0]; 88 | variance_ += rho * ((xt_mu.t() * xt_mu).val[0] - variance_); 89 | } 90 | 91 | 92 | bool slSphericalGaussian::testInlier(const cv::Vec3f &X_t, float nbStdDev) const 93 | { 94 | // X_t - Mu_t 95 | Vec3f xt_mu = X_t - mean_; 96 | 97 | // ||X_t - Mu_t|| < nbStdDev * StdDev 98 | // (X_t - Mu_t)'(X_t - Mu_t) < nbStdDev^2 * variance 99 | return ((xt_mu.t() * xt_mu).val[0]) < (nbStdDev * nbStdDev * variance_); 100 | } 101 | 102 | 103 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slEpsilon3ch.h: -------------------------------------------------------------------------------- 1 | #ifndef _SLEPSILON3CH_H_ 2 | #define _SLEPSILON3CH_H_ 3 | 4 | 5 | #include "slQuantParams.h" 6 | 7 | 8 | //Treshold structure 9 | class SLCORE_DLL_EXPORT slEpsilon3ch 10 | { 11 | public: 12 | slEpsilon3ch(slPixel1ch eps0 = 0, slPixel1ch eps1 = 0, slPixel1ch eps2 = 0); 13 | 14 | void setEpsilon(slPixel1ch eps0, slPixel1ch eps1, slPixel1ch eps2); 15 | 16 | bool pixIsBackground(const slPixel3ch &newPix, const slPixel3ch &bgPix, 17 | typeColorSys csys = SL_BGR, bool considerLightChanges = true) const; 18 | 19 | SLCORE_DLL_EXPORT friend std::ostream& operator<<(std::ostream &ostr, const slEpsilon3ch &eps); 20 | 21 | private: 22 | slPixel1ch eps0_; 23 | slPixel1ch eps1_; 24 | slPixel1ch eps2_; 25 | 26 | }; 27 | 28 | 29 | #endif // _SLEPSILON3CH_H_ 30 | 31 | 32 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slGaussMixture.h: -------------------------------------------------------------------------------- 1 | /*! \file slGaussMixture.h 2 | * \brief Contains the class slGaussMixture, which is the Gaussian Mixture 3 | * background subtraction class 4 | * 5 | * This file contains the definition of the class slGaussMixture and 6 | * its corresponding factory. 7 | * 8 | * \author Pier-Luc St-Onge 9 | * \date June 2010 10 | */ 11 | 12 | #ifndef _SLGAUSSMIXTURE_H_ 13 | #define _SLGAUSSMIXTURE_H_ 14 | 15 | 16 | #include "slBgSub.h" 17 | #include "slSpherGaussMixMat.h" 18 | 19 | 20 | //! This is the class for Gaussian Mixture background subtraction 21 | /*! 22 | * The current class does background subtraction by comparing each pixel of a 23 | * new image to its corresponding multiple Gaussian distributions of the 24 | * background. 25 | * In fact, for each pixel, there are many Gaussian distributions to describe 26 | * different colors that could be part of the background. For example: waves. 27 | * 28 | * In this algorithm, all pixels are saved in one of the multiple Gaussian 29 | * distributions, but background pixels are the ones that belong to the most 30 | * popular distributions (highest weights). 31 | * 32 | * \section constructor Constructor and Factory 33 | * It is possible to create an instance directly: 34 | * \code 35 | * slGaussMixture gaussMixture; 36 | * // Configuration... 37 | * slSpherGaussMixMat &sgmm = gaussMixture.getGaussMixtures(); 38 | * \endcode 39 | * 40 | * With slBgSubFactory, it is also possible to create an instance of slGaussMixture: 41 | * \code 42 | * slBgSub *bgSub = slBgSubFactory::createInstance("gaussMixture"); 43 | * // Delete bgSub 44 | * \endcode 45 | * 46 | * \see slBgSub, slSpherGaussMixMat, slTempAvg, slSimpleGauss 47 | * \author Pier-Luc St-Onge 48 | * \date June 2010 49 | */ 50 | class SLBGSUB_DLL_EXPORT slGaussMixture: public slBgSub 51 | { 52 | public: 53 | slGaussMixture(); //!< Constructor 54 | virtual ~slGaussMixture(); //!< Destructor 55 | 56 | static void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap); 57 | 58 | // Get function(s) 59 | 60 | //! Returns the slSpherGaussMixMat instance 61 | inline slSpherGaussMixMat& getGaussMixtures() { return gaussMixtures_; } 62 | 63 | protected: 64 | // Set specific parameters 65 | virtual void setSubParameters(const slAH::slParameters& parameters); 66 | 67 | // Shows (with cout) you function's parameters' getValue 68 | virtual void showSubParameters() const; 69 | 70 | // For things to do before computing the first current frame 71 | virtual void init(); 72 | 73 | // The function that actually computes the current frame 74 | virtual void doSubtraction(slImage1ch &bForeground); 75 | 76 | // To set a specific background pixel 77 | virtual void setBgPixel(const slPixel3ch *cur_row, 78 | slPixel3ch *bg_row, slPixel1ch *b_fg_row, int w, int i, int j); 79 | 80 | // For things to do before computing the current image 81 | virtual void prepareNextSubtraction(); 82 | 83 | // Update any other windows 84 | virtual void updateSubWindows(); 85 | 86 | private: 87 | // A Gaussian mixture for all pixels 88 | slSpherGaussMixMat gaussMixtures_; 89 | 90 | }; 91 | 92 | 93 | class SLBGSUB_DLL_EXPORT slGaussMixtureFactory: public slBgSubFactory 94 | { 95 | public: 96 | virtual ~slGaussMixtureFactory(); 97 | 98 | protected: 99 | // To specify your functions's parameters 100 | virtual void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap) const; 101 | 102 | // The factory (a static instance) will create an instance of your BgSubtractor 103 | virtual slGaussMixture* createInstance() const; 104 | 105 | private: 106 | // The factory's constructor 107 | slGaussMixtureFactory(); 108 | 109 | private: 110 | static slGaussMixtureFactory factory_; 111 | 112 | }; 113 | 114 | 115 | #endif // _SLGAUSSMIXTURE_H_ 116 | 117 | 118 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slMedian.h: -------------------------------------------------------------------------------- 1 | #ifndef _SLMEDIAN_H_ 2 | #define _SLMEDIAN_H_ 3 | 4 | 5 | #include "slBgSub.h" 6 | #include "slEpsilon3ch.h" 7 | #include "slMedianContainer.h" 8 | 9 | 10 | class slMedian: public slBgSub 11 | { 12 | public: 13 | virtual ~slMedian(); 14 | 15 | protected: 16 | virtual void showSpecificParameters() const; 17 | virtual void fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const; 18 | 19 | virtual slBgSub* createSpecificInstance(const slParameters& parameters) const; 20 | 21 | virtual int specificInit(); 22 | virtual void computeFrame(); 23 | virtual void setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 24 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j); 25 | virtual int specificLoadNextFrame(); 26 | 27 | private: 28 | slMedian(const string &name); 29 | slMedian(const slParameters& parameters); 30 | 31 | private: 32 | 33 | class slMedianPixel3ch 34 | { 35 | public: 36 | void resize(int size) 37 | { 38 | mB.resize(size); 39 | mG.resize(size); 40 | mR.resize(size); 41 | } 42 | 43 | const slMedianPixel3ch& operator+=(const slPixel3ch &pixel) 44 | { 45 | mB += pixel.b(); 46 | mG += pixel.g(); 47 | mR += pixel.r(); 48 | 49 | return *this; 50 | } 51 | 52 | slPixel3ch getMeanPixel() const 53 | { 54 | return slPixel3ch( (BGRComp)mB.getMedian(), 55 | (BGRComp)mG.getMedian(), 56 | (BGRComp)mR.getMedian()); 57 | } 58 | 59 | private: 60 | typedef slMedianContainer slMedianPix; 61 | 62 | private: 63 | slMedianPix mB; 64 | slMedianPix mG; 65 | slMedianPix mR; 66 | }; 67 | 68 | private: 69 | // Parameters 70 | int mMValue; 71 | slEpsilon3ch mEpsilon; 72 | 73 | // Medians 74 | vector mMedians; 75 | 76 | private: 77 | static slMedian Creator_; 78 | 79 | }; 80 | 81 | 82 | #endif // _SLMEDIAN_H_ 83 | 84 | 85 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slMinMax.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slBgSub/include/slMinMax.h -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slNonFgKeepFg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * file slNonFgKeepFg.h 3 | * 4 | * author Michael Sills Lavoie 5 | * 6 | * date 24.05.2007 7 | */ 8 | 9 | #ifndef _SLNONFGKEEPFG_H_ 10 | #define _SLNONFGKEEPFG_H_ 11 | 12 | 13 | #include "slBgSub.h" 14 | #include "slEpsilon3ch.h" 15 | 16 | 17 | class slNonFgKeepFg: public slBgSub 18 | { 19 | public: 20 | virtual ~slNonFgKeepFg(); 21 | 22 | protected: 23 | virtual void showSpecificParameters() const; 24 | virtual void fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const; 25 | 26 | virtual slBgSub* createSpecificInstance(const slParameters& parameters) const; 27 | 28 | virtual int specificInit(); 29 | virtual void computeFrame(); 30 | virtual void setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 31 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j); 32 | virtual int specificLoadNextFrame(); 33 | 34 | private: 35 | slNonFgKeepFg(const std::string &name = ""); 36 | slNonFgKeepFg(const slParameters& parameters); 37 | 38 | private: 39 | slEpsilon3ch mEpsilon; 40 | static slNonFgKeepFg Creator_; 41 | 42 | }; 43 | 44 | 45 | #endif // _SLNONFGKEEPFG_H_ 46 | 47 | 48 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slNonFgMergeFg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * file slNonFgMergeFg.h 3 | * 4 | * author Michael Sills Lavoie 5 | * 6 | * date 24.05.2007 7 | */ 8 | 9 | #ifndef _SLNONFGMERGEFG_H_ 10 | #define _SLNONFGMERGEFG_H_ 11 | 12 | 13 | #include "slBgSub.h" 14 | #include "slEpsilon3ch.h" 15 | 16 | 17 | class slNonFgMergeFg: public slBgSub 18 | { 19 | public: 20 | virtual ~slNonFgMergeFg(); 21 | 22 | protected: 23 | virtual void showSpecificParameters() const; 24 | virtual void fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const; 25 | 26 | virtual slBgSub* createSpecificInstance(const slParameters& parameters) const; 27 | 28 | virtual int specificInit(); 29 | virtual void computeFrame(); 30 | virtual void setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 31 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j); 32 | virtual int specificLoadNextFrame(); 33 | 34 | private: 35 | slNonFgMergeFg(const std::string &name = ""); 36 | slNonFgMergeFg(const slParameters& parameters); 37 | 38 | private: 39 | unsigned long int mNbPixel; 40 | unsigned long int mNbPixelCount; 41 | 42 | slEpsilon3ch mEpsilon; 43 | static slNonFgMergeFg Creator_; 44 | 45 | }; 46 | 47 | 48 | #endif // _SLNONFGMERGEFG_H_ 49 | 50 | 51 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slOpenCv.h: -------------------------------------------------------------------------------- 1 | #ifndef _SLOPENCV_H_ 2 | #define _SLOPENCV_H_ 3 | 4 | 5 | #include "slBgSub.h" 6 | 7 | 8 | struct CvBGStatModel; 9 | 10 | 11 | class slOpenCv: public slBgSub 12 | { 13 | public: 14 | virtual ~slOpenCv(); 15 | 16 | protected: 17 | virtual void showSpecificParameters() const; 18 | virtual void fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const; 19 | 20 | virtual slBgSub* createSpecificInstance(const slParameters& parameters) const; 21 | 22 | virtual int specificInit(); 23 | virtual void computeFrame(); 24 | virtual void setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 25 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j); 26 | virtual int specificLoadNextFrame(); 27 | 28 | private: 29 | slOpenCv(const std::string &name = ""); 30 | slOpenCv(const slParameters& parameters); 31 | 32 | private: 33 | CvBGStatModel *mStatModel; 34 | 35 | private: 36 | static slOpenCv Creator_; 37 | 38 | }; 39 | 40 | 41 | #endif // _SLOPENCV_H_ 42 | 43 | 44 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slRectGaussMixture.h: -------------------------------------------------------------------------------- 1 | /*! \file slRectGaussMixture.h 2 | * \brief Remake of rafik background subtractor with a mix of the 3 | * GaussianMixture bgs 4 | * 5 | * \author Michael Sills Lavoie, (GaussMixture) Pier-Luc St-Onge 6 | * \date 30.05.2007 - February 2012 7 | */ 8 | 9 | #ifndef _SLRECTGAUSSMIXTURE_H_ 10 | #define _SLRECTGAUSSMIXTURE_H_ 11 | 12 | 13 | #include "slRectSimple.h" 14 | #include "slSpherGaussMixMat.h" 15 | 16 | 17 | //! slRectGaussMixture based on rafik bg subtractor and slGaussMixture 18 | /*! 19 | * Foreground pixels detected by the slRectSimple algorithm are filtered 20 | * a second time by a gaussian mixture algorithm. 21 | * This hybrid algorithm uses similar parameters as the ones in 22 | * slRectSimple and slGaussMixture on the command line. 23 | * 24 | * \section constructor Constructor and Factory 25 | * It is possible to create an instance directly: 26 | * \code 27 | * slRectGaussMixture rectGaussMixture; 28 | * // Configuration... 29 | * slSpherGaussMixMat &sgmm = rectGaussMixture.getGaussMixtures(); 30 | * \endcode 31 | * 32 | * With slBgSubFactory, it is also possible to create an instance of slRectGaussMixture: 33 | * \code 34 | * slBgSub *bgSub = slBgSubFactory::createInstance("rectGaussMixture"); 35 | * // Delete bgSub 36 | * \endcode 37 | * 38 | * \see slBgSub, slRectSimple, slSpherGaussMixMat, slRectPixels, slHistogram3ch 39 | * \author Michael Sills Lavoie, (GaussMixture) Pier-Luc St-Onge 40 | * \date 30.05.2007 - February 2012 41 | */ 42 | class SLBGSUB_DLL_EXPORT slRectGaussMixture: public slRectSimple 43 | { 44 | public: 45 | slRectGaussMixture(); //!< Constructor 46 | virtual ~slRectGaussMixture(); //!< Destructor 47 | 48 | static void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap); 49 | 50 | // Get function(s) 51 | 52 | //! Returns the slSpherGaussMixMat instance 53 | inline slSpherGaussMixMat& getGaussMixtures() { return gaussMixtures_; } 54 | 55 | protected: 56 | // Set specific parameters 57 | virtual void setSubParameters(const slAH::slParameters& parameters); 58 | 59 | // Shows (with cout) you function's parameters' getValue 60 | virtual void showSubParameters() const; 61 | 62 | // For things to do before computing the first current frame 63 | virtual void init(); 64 | 65 | // The function that actually computes the current frame 66 | virtual void doSubtraction(slImage1ch &bForeground); 67 | 68 | // To set a specific background pixel 69 | virtual void setBgPixel(const slPixel3ch *cur_row, 70 | slPixel3ch *bg_row, slPixel1ch *b_fg_row, int w, int i, int j); 71 | 72 | // For things to do before computing the current image 73 | virtual void prepareNextSubtraction(); 74 | 75 | // Update any other windows 76 | virtual void updateSubWindows(); 77 | 78 | private: 79 | // A Gaussian mixture for all pixels 80 | slSpherGaussMixMat gaussMixtures_; 81 | 82 | }; 83 | 84 | 85 | class SLBGSUB_DLL_EXPORT slRectGaussMixtureFactory: public slBgSubFactory 86 | { 87 | public: 88 | virtual ~slRectGaussMixtureFactory(); 89 | 90 | protected: 91 | // To specify your functions's parameters 92 | virtual void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap) const; 93 | 94 | // The factory (a static instance) will create an instance of your BgSubtractor 95 | virtual slRectGaussMixture* createInstance() const; 96 | 97 | private: 98 | // The factory's constructor 99 | slRectGaussMixtureFactory(); 100 | 101 | private: 102 | static slRectGaussMixtureFactory factory_; 103 | 104 | }; 105 | 106 | 107 | #endif // _SLRECTGAUSSMIXTURE_H_ 108 | 109 | 110 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slRectMedian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @file slRectMedian.h 3 | * Remake of rafik background subtractor updated with 4 | * the median bgs 5 | * 6 | * @author Michael Sills Lavoie 7 | * @author (Median) ??? 8 | * 9 | * @date 30.05.2007 10 | */ 11 | 12 | #ifndef _SLRECTMEDIAN_H_ 13 | #define _SLRECTMEDIAN_H_ 14 | 15 | #include "slRectPixels.h" 16 | #include "slArgHandler.h" 17 | #include "slHistogram3ch.h" 18 | #include "slPixel3ch.h" 19 | #include "slBgSub.h" 20 | #include "slMedianContainer.h" 21 | #include 22 | 23 | 24 | using namespace std; 25 | 26 | /* 27 | * slRectSimple based on rafik bg subtractor. 28 | * @author Michael Sills Lavoie 29 | */ 30 | class slRectMedian: public slBgSub 31 | { 32 | public: 33 | virtual ~slRectMedian(); 34 | 35 | protected: 36 | virtual void showSpecificParameters() const; 37 | virtual void fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const; 38 | 39 | virtual slBgSub* createSpecificInstance(const slParameters& parameters) const; 40 | 41 | virtual int specificInit(); 42 | virtual void computeFrame(); 43 | virtual void setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 44 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j); 45 | virtual int specificLoadNextFrame(); 46 | 47 | private: 48 | slRectMedian(const string &name); 49 | slRectMedian(const slParameters& parameters); 50 | 51 | private: 52 | 53 | /* 54 | * This class contain the midian pixel. 55 | * @author ??? 56 | */ 57 | class slMedianPixel3ch 58 | { 59 | public: 60 | void resize(int size) 61 | { 62 | mB.resize(size); 63 | mG.resize(size); 64 | mR.resize(size); 65 | } 66 | 67 | const slMedianPixel3ch& operator+=(const slPixel3ch &pixel) 68 | { 69 | mB += pixel.b(); 70 | mG += pixel.g(); 71 | mR += pixel.r(); 72 | 73 | return *this; 74 | } 75 | 76 | slPixel3ch getMeanPixel() const 77 | { 78 | return slPixel3ch( (BGRComp)mB.getMedian(), 79 | (BGRComp)mG.getMedian(), 80 | (BGRComp)mR.getMedian()); 81 | } 82 | 83 | private: 84 | typedef slMedianContainer slMedianPix; 85 | 86 | private: 87 | slMedianPix mB; 88 | slMedianPix mG; 89 | slMedianPix mR; 90 | }; 91 | 92 | private: 93 | /** 94 | * Container for the statistic of each level 95 | */ 96 | vector statistic_; 97 | 98 | /** 99 | * Container of the level of slRectPixels for the current frame 100 | * Each level contain all the slRectPixels of this level 101 | */ 102 | vector> level_; 103 | 104 | /** 105 | * Th for the upper level slRectPixels when we compare their histograms 106 | */ 107 | float th_; 108 | /** 109 | * The value that we add to the th_ for each lower level 110 | */ 111 | float deltath_; 112 | /** 113 | * Minimal number of slRectPixels that are at the upper level 114 | */ 115 | int minRect_; 116 | /** 117 | * Bool to know the color space 118 | */ 119 | bool isHSV_; 120 | 121 | /** 122 | * Bool to if we use the MDPA distance for the histograms 123 | */ 124 | bool MPDA_; 125 | 126 | void createLevel (vector> &level); 127 | 128 | int mMValue; 129 | 130 | /** 131 | * Treshold for the texture to know if a rectangle is textured or not 132 | */ 133 | float Tth_; 134 | 135 | /** 136 | * The value that we add to the Tth_ for each lower level 137 | */ 138 | float Tdeltath_; 139 | 140 | /** 141 | * Bool to know if we use texture 142 | */ 143 | bool useTexture_; 144 | 145 | // Medians 146 | vector mMedians; 147 | 148 | private: 149 | static slRectMedian Creator_; 150 | 151 | }; 152 | 153 | 154 | #endif // _SLRECTMEDIAN_H_ 155 | 156 | 157 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slRectSimple.h: -------------------------------------------------------------------------------- 1 | /*! \file slRectSimple.h 2 | * \brief Remake of rafik background subtractor 3 | * 4 | * \author Michael Sills Lavoie, Pier-Luc St-Onge 5 | * \date 24.05.2007 - February 2012 6 | */ 7 | 8 | #ifndef _SLRECTSIMPLE_H_ 9 | #define _SLRECTSIMPLE_H_ 10 | 11 | 12 | #include "slArgHandler.h" 13 | #include "slBgSub.h" 14 | #include "slRectPixels.h" 15 | 16 | 17 | //! slRectSimple based on rafik bg subtractor. 18 | /*! 19 | * \section constructor Constructor and Factory 20 | * It is possible to create an instance directly: 21 | * \code 22 | * slRectSimple rectSimple; 23 | * // Configuration... 24 | * \endcode 25 | * 26 | * With slBgSubFactory, it is also possible to create an instance of slRectSimple: 27 | * \code 28 | * slBgSub *bgSub = slBgSubFactory::createInstance("rect"); 29 | * // Delete bgSub 30 | * \endcode 31 | * 32 | * \see slBgSub, slRectGaussMixture, slRectPixels, slHistogram3ch 33 | * \author Michael Sills Lavoie, Pier-Luc St-Onge 34 | * \date 24.05.2007 - February 2012 35 | */ 36 | class SLBGSUB_DLL_EXPORT slRectSimple: public slBgSub 37 | { 38 | public: 39 | slRectSimple(); //!< Constructor 40 | virtual ~slRectSimple(); //!< Destructor 41 | 42 | static void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap); 43 | 44 | // Set function(s) 45 | 46 | void setBaseEps(float th); //!< Base epsilon for comparison (histogram) 47 | void setDeltaEps(float deltath); //!< Delta to increase base epsilon (histogram) when going to lower level 48 | 49 | void setMinRect(int minRect); //!< Minimal number of slRectPixels in the upper level 50 | 51 | void setTextureBaseEps(float Tth); //!< Base epsilon for comparison (rectangle texture) 52 | void setTextureDeltaEps(float Tdeltath); //!< Delta to increase base epsilon (rectangle texture) when going to lower level 53 | 54 | void setTexture(bool useTexture); //!< Use the texture method 55 | void setDistanceMethod(bool mpda); //!< Use the MDPA distance for the histograms 56 | 57 | void setColorSystem(typeColorSys colorSystem); //!< SL_BGR or SL_HSV 58 | void setQuantification(bool enabled, const slQuant3ch& quant = slQuant3ch()); //!< Image quantification 59 | 60 | protected: 61 | // Set specific parameters 62 | virtual void setSubParameters(const slAH::slParameters& parameters); 63 | 64 | // Shows (with cout) you function's parameters' getValue 65 | virtual void showSubParameters() const; 66 | 67 | // For things to do before computing the first current frame 68 | virtual void init(); 69 | 70 | // The function that actually computes the current frame 71 | virtual void doSubtraction(slImage1ch &bForeground); 72 | 73 | // To set a specific background pixel 74 | virtual void setBgPixel(const slPixel3ch *cur_row, 75 | slPixel3ch *bg_row, slPixel1ch *b_fg_row, int w, int i, int j); 76 | 77 | // For things to do before computing the current image 78 | virtual void prepareNextSubtraction(); 79 | 80 | // Update any other windows 81 | virtual void updateSubWindows(); 82 | 83 | protected: 84 | /** 85 | * Container for the statistic of each level 86 | */ 87 | std::vector statistic_; 88 | 89 | /** 90 | * Container of the level of slRectPixels for the current frame 91 | * Each level contain all the slRectPixels of this level 92 | */ 93 | std::vector > level_; 94 | 95 | /** 96 | * Th for the upper level slRectPixels when we compare their histograms 97 | */ 98 | float th_; 99 | /** 100 | * The value that we add to the th_ for each lower level 101 | */ 102 | float deltath_; 103 | /** 104 | * Minimal number of slRectPixels that are at the upper level 105 | */ 106 | int minRect_; 107 | 108 | /** 109 | * Bool to if we use the MDPA distance for the histograms 110 | */ 111 | bool MPDA_; 112 | 113 | /** 114 | * Bool to know if we use texture 115 | */ 116 | bool useTexture_; 117 | 118 | /** 119 | * Treshold for the texture to know if a rectangle is textured or not 120 | */ 121 | float Tth_; 122 | 123 | /** 124 | * The value that we add to the Tth_ for each lower level 125 | */ 126 | float Tdeltath_; 127 | 128 | void createLevel (std::vector > &level); 129 | }; 130 | 131 | 132 | class SLBGSUB_DLL_EXPORT slRectSimpleFactory: public slBgSubFactory 133 | { 134 | public: 135 | virtual ~slRectSimpleFactory(); 136 | 137 | protected: 138 | // To specify your functions's parameters 139 | virtual void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap) const; 140 | 141 | // The factory (a static instance) will create an instance of your BgSubtractor 142 | virtual slRectSimple* createInstance() const; 143 | 144 | private: 145 | // The factory's constructor 146 | slRectSimpleFactory(); 147 | 148 | private: 149 | static slRectSimpleFactory factory_; 150 | 151 | }; 152 | 153 | 154 | #endif // _SLRECTSIMPLE_H_ 155 | 156 | 157 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slTempAvg.h: -------------------------------------------------------------------------------- 1 | /*! \file slTempAvg.h 2 | * \brief Contains the class slTempAvg, which is the Temporal Averaging 3 | * background subtraction class 4 | * 5 | * This file contains the definition of the class slTempAvg and 6 | * its corresponding factory. 7 | * 8 | * \author Pier-Luc St-Onge 9 | * \date June 2010 10 | */ 11 | 12 | #ifndef _SLTEMPAVG_H_ 13 | #define _SLTEMPAVG_H_ 14 | 15 | 16 | #include "slBgSub.h" 17 | #include "slEpsilon3ch.h" 18 | 19 | 20 | //! This is the class for Temporal Averaging background subtraction 21 | /*! 22 | * The current class does background subtraction by comparing each pixel of a 23 | * new image to its corresponding pixel in the static background image. 24 | * This last image is made of the mean of all corresponding background pixels 25 | * in computed images. 26 | * 27 | * \section constructor Constructor and Factory 28 | * It is possible to create an instance directly: 29 | * \code 30 | * slTempAvg tempAvg; 31 | * // Configuration... 32 | * \endcode 33 | * 34 | * With slBgSubFactory, it is also possible to create an instance of slTempAvg: 35 | * \code 36 | * slBgSub *bgSub = slBgSubFactory::createInstance("tempAVG"); 37 | * // Delete bgSub 38 | * \endcode 39 | * 40 | * \see slBgSub, slSimpleGauss, slGaussMixture 41 | * \author Pier-Luc St-Onge 42 | * \date June 2010 43 | */ 44 | class SLBGSUB_DLL_EXPORT slTempAvg: public slBgSub 45 | { 46 | public: 47 | slTempAvg(); 48 | virtual ~slTempAvg(); 49 | 50 | static void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap); 51 | 52 | // Set function(s) 53 | 54 | void setEpsilon(int eps); //!< Epsilon or error tolerance (default = 15) 55 | 56 | protected: 57 | // Set specific parameters 58 | virtual void setSubParameters(const slAH::slParameters& parameters); 59 | 60 | // Shows (with cout) you function's parameters' getValue 61 | virtual void showSubParameters() const; 62 | 63 | // For things to do before computing the first current frame 64 | virtual void init(); 65 | 66 | // The function that actually computes the current frame 67 | virtual void doSubtraction(slImage1ch &bForeground); 68 | 69 | // To set a specific background pixel 70 | virtual void setBgPixel(const slPixel3ch *cur_row, 71 | slPixel3ch *bg_row, slPixel1ch *b_fg_row, int w, int i, int j); 72 | 73 | // For things to do before computing the current image 74 | virtual void prepareNextSubtraction(); 75 | 76 | // Update any other windows 77 | virtual void updateSubWindows(); 78 | 79 | private: 80 | class MeanPixel3ch 81 | { 82 | public: 83 | MeanPixel3ch(); 84 | 85 | const MeanPixel3ch& operator+=(const slPixel3ch &pixel); 86 | 87 | slPixel3ch getMeanPixel() const; 88 | 89 | private: 90 | int sumB_; 91 | int sumG_; 92 | int sumR_; 93 | 94 | int nbPix_; 95 | }; 96 | 97 | private: 98 | slEpsilon3ch epsilon_; 99 | 100 | MeanPixel3ch* meanPix_; 101 | 102 | }; 103 | 104 | 105 | class SLBGSUB_DLL_EXPORT slTempAvgFactory: public slBgSubFactory 106 | { 107 | public: 108 | virtual ~slTempAvgFactory(); 109 | 110 | protected: 111 | // To specify your functions's parameters 112 | virtual void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap) const; 113 | 114 | // The factory (a static instance) will create an instance of your BgSubtractor 115 | virtual slTempAvg* createInstance() const; 116 | 117 | private: 118 | // The factory's constructor 119 | slTempAvgFactory(); 120 | 121 | private: 122 | static slTempAvgFactory factory_; 123 | 124 | }; 125 | 126 | 127 | #endif // _SLTEMPAVG_H_ 128 | 129 | 130 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slTestComparaison.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slBgSub/include/slTestComparaison.h -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/include/slTexture.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | File: slSimpleGauss.h 3 | Description: This is the Gaussian Mixture algorithm class. 4 | Created: November 2006 (Pier-Luc St-Onge, Atousa Torabi, Parisa Darvish Zadeh Varcheie) 5 | Some comments (Pier-Luc St-Onge, Atousa Torabi, Parisa Darvish Zadeh Varcheie) 6 | ******************************************************************************/ 7 | 8 | #ifndef _SLTEXTURE_H_ 9 | #define _SLTEXTURE_H_ 10 | 11 | 12 | #include "slBgSub.h" 13 | #include "slEpsilon3ch.h" 14 | 15 | 16 | class slTexture: public slBgSub 17 | { 18 | public: 19 | virtual ~slTexture(); 20 | 21 | protected: 22 | virtual void showSpecificParameters() const; 23 | virtual void fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const; 24 | 25 | virtual slBgSub* createSpecificInstance(const slParameters& parameters) const; 26 | 27 | virtual int specificInit(); 28 | virtual void computeFrame(); 29 | virtual void setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 30 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j); 31 | virtual int specificLoadNextFrame(); 32 | 33 | private: 34 | slTexture(const std::string &name = ""); 35 | slTexture(const slParameters& parameters); 36 | 37 | private: 38 | //This class contains histogram of pixeles and updaintg their informtion 39 | class slHistogram 40 | { 41 | public: 42 | slHistogram(): mW(0) 43 | { 44 | mBins.resize(1 << mP); 45 | 46 | for (int ind = 0; ind < (1 << mP); ind++) { 47 | mBins[ind] = 0; 48 | } 49 | } 50 | //Fill histogram bins 51 | const slHistogram& operator=(const slHistogram& histogram) 52 | { 53 | if (&histogram != this) { 54 | mW = histogram.mW; 55 | 56 | for (int ind = 0; ind < (1 << mP); ind++) { 57 | mBins[ind] = histogram.mBins[ind]; 58 | } 59 | } 60 | 61 | return *this; 62 | } 63 | //Update histogram 64 | const slHistogram& operator+=(const slHistogram& histogram) 65 | { 66 | for (int ind = 0; ind < (1 << mP); ind++) { 67 | mBins[ind] = (short)(mAb * histogram.mBins[ind] + (1 - mAb) * mBins[ind]); 68 | } 69 | 70 | return *this; 71 | } 72 | 73 | inline void addLBP(const unsigned char lbp) { mBins[lbp]++; } 74 | 75 | //Update weights 76 | inline void addW(const double Mk) { mW = mAw * Mk + (1 - mAw) * mW; } 77 | 78 | inline bool operator<(const slHistogram& histogram) { return mW > histogram.mW; } 79 | 80 | double intersection(const slHistogram& histogram); 81 | 82 | void setW(const double W) { mW = W; } 83 | inline double getW() const { return mW; } 84 | 85 | public: 86 | static void setP(int P) 87 | { 88 | mP = P; 89 | 90 | if (mP < 3 || 8 < mP) { 91 | throw "Neighborhood too small or too large."; 92 | } 93 | } 94 | 95 | static int getP() { return mP; } 96 | 97 | static void setAb(double Ab) { mAb = Ab; } 98 | static double getAb() { return mAb; } 99 | 100 | static void setAw(double Aw) { mAw = Aw; } 101 | static double getAw() { return mAw; } 102 | 103 | private: 104 | double mW; 105 | std::vector mBins; 106 | 107 | static int mP; 108 | static double mAb; 109 | static double mAw; 110 | 111 | }; 112 | 113 | private: 114 | class slTextureComp 115 | { 116 | public: 117 | slTextureComp() 118 | { 119 | mHistograms.resize(mK); 120 | mB = mK; 121 | } 122 | 123 | void setInitHistogram(const slHistogram &histogram) 124 | { 125 | mHistograms[0] = histogram; 126 | mHistograms[0].setW(1); 127 | 128 | for (int ind = 1; ind < mK; ind++) 129 | { 130 | mHistograms[ind].setW(0); 131 | } 132 | 133 | mB = 1; 134 | } 135 | 136 | bool isPixBackground(const slHistogram &histogram); 137 | 138 | public: 139 | static void setK(int K) { mK = K; } 140 | static int getK() { return mK; } 141 | 142 | static void setTp(double Tp) { mTp = Tp; } 143 | static double getTp() { return mTp; } 144 | 145 | static void setTb(double Tb) { mTb = Tb; } 146 | static double getTb() { return mTb; } 147 | 148 | private: 149 | std::vector mHistograms; 150 | int mB; 151 | 152 | static int mK; 153 | static double mTp; 154 | static double mTb; 155 | }; 156 | 157 | private: 158 | void computeTheHistograms(const slImage &image); 159 | 160 | private: 161 | int mA; 162 | double mR; 163 | double mRr; 164 | 165 | double* offsets[2]; 166 | 167 | // For all pixels, keep K histograms of LBPs 168 | slTextureComp* mTexturePix; 169 | 170 | // For all pixels of the current frame, keep an histogram of LPBs 171 | slHistogram* mCurrentHist; 172 | 173 | private: 174 | static slTexture Creator_; 175 | 176 | }; 177 | 178 | 179 | 180 | 181 | #endif // _SLTEXTURE_H_ 182 | 183 | 184 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/slBgSub.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/src/slEpsilon3ch.cpp: -------------------------------------------------------------------------------- 1 | #include "slEpsilon3ch.h" 2 | 3 | 4 | using namespace std; 5 | 6 | 7 | slEpsilon3ch::slEpsilon3ch(slPixel1ch eps0, slPixel1ch eps1, slPixel1ch eps2) 8 | { 9 | setEpsilon(eps0, eps1, eps2); 10 | } 11 | 12 | 13 | void slEpsilon3ch::setEpsilon(slPixel1ch eps0, slPixel1ch eps1, slPixel1ch eps2) 14 | { 15 | eps0_ = eps0; 16 | eps1_ = eps1; 17 | eps2_ = eps2; 18 | } 19 | 20 | 21 | bool slEpsilon3ch::pixIsBackground(const slPixel3ch &newPix, const slPixel3ch &bgPix, 22 | typeColorSys csys, bool considerLightChanges) const 23 | { 24 | bool disableVtest = (csys == SL_HSV && considerLightChanges == false); 25 | 26 | return ( abs(newPix.val[0] - bgPix.val[0]) <= eps0_ && 27 | abs(newPix.val[1] - bgPix.val[1]) <= eps1_ && 28 | ( abs(newPix.val[2] - bgPix.val[2]) <= eps2_ || disableVtest ) 29 | ); 30 | } 31 | 32 | 33 | ostream& operator<<(ostream &ostr, const slEpsilon3ch &eps) 34 | { 35 | ostr << (int)eps.eps0_ << " " << (int)eps.eps1_ << " " << (int)eps.eps2_; 36 | 37 | return ostr; 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/src/slGaussMixture.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | File: slGaussMixture.cpp 3 | Description: This is the implementation of the 4 | Gaussian Mixture algorithm. 5 | Created: October 2006 (Pier-Luc St-Onge) 6 | Modified: November 2006: 7 | Some comments (Pier-Luc St-Onge) 8 | ******************************************************************************/ 9 | 10 | #include "slGaussMixture.h" 11 | 12 | #include 13 | 14 | 15 | using namespace cv; 16 | using namespace slAH; 17 | 18 | 19 | slGaussMixture::slGaussMixture() 20 | : slBgSub() 21 | { 22 | } 23 | 24 | 25 | slGaussMixture::~slGaussMixture() 26 | { 27 | } 28 | 29 | 30 | void slGaussMixture::fillParamSpecs(slAH::slParamSpecMap& paramSpecMap) 31 | { 32 | slSpherGaussMixMat::fillParamSpecs(paramSpecMap); 33 | } 34 | 35 | 36 | void slGaussMixture::setSubParameters(const slAH::slParameters& parameters) 37 | { 38 | // Make sure the HSV color space is not used 39 | if (parameters.isParsed(ARG_COLOR_S) && 40 | strcmp(parameters.getValue(ARG_COLOR_S).c_str(), BGR_NAME) != 0) 41 | { 42 | throw slException("Gaussian mixture only works in the rgb color space."); 43 | } 44 | 45 | // All gaussian mixture parameters 46 | gaussMixtures_.setParameters(parameters); 47 | } 48 | 49 | 50 | void slGaussMixture::showSubParameters() const 51 | { 52 | gaussMixtures_.showParameters(); 53 | } 54 | 55 | 56 | void slGaussMixture::init() 57 | { 58 | if (colorSystem_ == SL_HSV) { 59 | throw slException("Gaussian mixture only works in the rgb color space."); 60 | } 61 | 62 | const int w = imageSize_.width; 63 | const int h = imageSize_.height; 64 | 65 | // Create a new gaussMixtures_ vector 66 | gaussMixtures_.reset(w * h); 67 | 68 | // For each row 69 | #pragma omp parallel for 70 | for (int i = 0; i < h; i++) { 71 | const int wi = w * i; 72 | const slPixel3ch* bg_row = background_[i]; 73 | 74 | // For each column 75 | for (int j = 0; j < w; j++) { 76 | // Initialize the gaussian mixture 77 | gaussMixtures_.update(wi + j, bg_row[j]); 78 | } 79 | } 80 | } 81 | 82 | 83 | void slGaussMixture::doSubtraction(slImage1ch &bForeground) 84 | { 85 | const int w = imageSize_.width; 86 | const int h = imageSize_.height; 87 | 88 | // Empty foreground images 89 | bForeground = PIXEL_1CH_BLACK; 90 | 91 | // For each row 92 | #pragma omp parallel for 93 | for (int i = 0; i < h; i++) { 94 | const int wi = w * i; 95 | const slPixel3ch* cur_row = current_[i]; 96 | 97 | slPixel3ch* bg_row = background_[i]; 98 | slPixel1ch* b_fg_row = bForeground[i]; 99 | 100 | // For each column 101 | for (int j = 0; j < w; j++) { 102 | // Evaluate if the quantified pixel is in the background 103 | bool isBackground = gaussMixtures_.update(wi + j, cur_row[j]); 104 | 105 | // Update the background pixel 106 | bg_row[j] = gaussMixtures_.getMean(wi + j); 107 | 108 | // Foreground pixel 109 | if (!isBackground) { 110 | // Update binary foreground - foreground pixel 111 | b_fg_row[j] = PIXEL_1CH_WHITE; 112 | } 113 | } 114 | } 115 | } 116 | 117 | 118 | void slGaussMixture::setBgPixel(const slPixel3ch *cur_row, 119 | slPixel3ch *bg_row, slPixel1ch *b_fg_row, int w, int i, int j) 120 | { 121 | // Update binary foreground - non foreground pixel 122 | b_fg_row[j] = PIXEL_1CH_BLACK; 123 | } 124 | 125 | 126 | void slGaussMixture::prepareNextSubtraction() 127 | { 128 | // Nothing to do here 129 | } 130 | 131 | 132 | void slGaussMixture::updateSubWindows() 133 | { 134 | } 135 | 136 | 137 | /////////////////////////////////////////////////////////////////////////////// 138 | // slGaussMixtureFactory 139 | /////////////////////////////////////////////////////////////////////////////// 140 | 141 | 142 | slGaussMixtureFactory slGaussMixtureFactory::factory_; 143 | 144 | 145 | slGaussMixtureFactory::slGaussMixtureFactory() 146 | : slBgSubFactory("gaussMixture") 147 | { 148 | } 149 | 150 | 151 | slGaussMixtureFactory::~slGaussMixtureFactory() 152 | { 153 | } 154 | 155 | 156 | void slGaussMixtureFactory::fillParamSpecs(slParamSpecMap& paramSpecMap) const 157 | { 158 | slGaussMixture::fillParamSpecs(paramSpecMap); 159 | } 160 | 161 | 162 | slGaussMixture* slGaussMixtureFactory::createInstance() const 163 | { 164 | return new slGaussMixture(); 165 | } 166 | 167 | 168 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/src/slMedian.cpp: -------------------------------------------------------------------------------- 1 | #include "slMedian.h" 2 | 3 | #include 4 | 5 | 6 | #define ARG_M_VALUE "-m" 7 | #define ARG_EPSILON "-e" 8 | 9 | 10 | slMedian slMedian::Creator_ = slMedian("median"); 11 | 12 | 13 | slMedian::slMedian(const string &name): 14 | slBgSub(name), mMedians(NULL) 15 | { 16 | } 17 | 18 | 19 | slMedian::slMedian(const slParameters& parameters): 20 | slBgSub(parameters), mMedians(NULL) 21 | { 22 | // M Value 23 | mMValue = atoi(parameters.getValue(ARG_M_VALUE).c_str()); 24 | 25 | int eps = atoi(parameters.getValue(ARG_EPSILON).c_str()); 26 | 27 | // Epsilon 28 | if (colorSystem_ == BGR) 29 | mEpsilon.setBGREpsilon(eps, eps, eps); 30 | else 31 | mEpsilon.setHSVEpsilon(eps * MAX_H / MAX_V, eps, eps); 32 | } 33 | 34 | 35 | slMedian::~slMedian() 36 | { 37 | } 38 | 39 | 40 | void slMedian::showSpecificParameters() const 41 | { 42 | cout << "M_Value : " << mMValue << endl; 43 | cout << "Epsilon : " << mEpsilon << endl; 44 | 45 | cout << endl; 46 | } 47 | 48 | 49 | void slMedian::fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const 50 | { 51 | paramSpecMap << (slParamSpec(ARG_M_VALUE, "M value") << slSyntax("1..256", "20")); 52 | paramSpecMap << (slParamSpec(ARG_EPSILON, "Epsilon") << slSyntax("0..255", "15")); 53 | } 54 | 55 | 56 | slBgSub* slMedian::createSpecificInstance(const slParameters& parameters) const 57 | { 58 | return new slMedian(parameters); 59 | } 60 | 61 | 62 | int slMedian::specificInit() 63 | { 64 | mMedians.resize(Size_.width * Size_.height); 65 | 66 | // Resize all slMedianPixel3ch objects to mMValue elements 67 | for (int i = 0; i < Size_.height; i++) 68 | { 69 | for (int j = 0; j < Size_.width; j++) 70 | { 71 | mMedians[Size_.width * i + j].resize(mMValue); 72 | } 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | 79 | void slMedian::computeFrame() 80 | { 81 | const int w = Size_.width; 82 | const int h = Size_.height; 83 | 84 | slPixel3ch* bg_data = imageList_[ARG_BG]->getPixel3chData(); 85 | slPixel3ch* fg_data = imageList_[ARG_FG]->getPixel3chData(); 86 | 87 | slPixel3ch* q_bg_data = imageList_[ARG_QBG]->getPixel3chData(); 88 | slPixel1ch* b_fg_data = imageList_[ARG_BFG]->getPixel1chData(); 89 | 90 | slPixel3ch* cur_data = imageList_[ARG_C_FR]->getPixel3chData(); 91 | slPixel3ch* q_cur_data = imageList_[ARG_QC_FR]->getPixel3chData(); 92 | 93 | #pragma omp parallel for 94 | for (int i = 0; i < h; i++) 95 | { 96 | for (int j = 0; j < w; j++) 97 | { 98 | // Background pixel 99 | if (indFrame_ < mMValue || mEpsilon.pixIsBackground( 100 | q_cur_data[w*i+j], q_bg_data[w*i+j], colorSystem_, doConsiderLightChanges_)) 101 | { 102 | // Update background pixel 103 | bg_data[w*i+j] = (mMedians[w*i+j] += cur_data[w*i+j]).getMeanPixel(); 104 | 105 | // Update foreground pixel value 106 | fg_data[w*i+j] = (colorSystem_ == BGR ? BGR_WHITE : HSV_WHITE); 107 | 108 | // Update binary foreground - non foreground pixel 109 | b_fg_data[w*i+j] = PIXEL_1CH_BLACK; 110 | } 111 | // Foreground pixel 112 | else 113 | { 114 | // Update foreground pixel value 115 | fg_data[w*i+j] = cur_data[w*i+j]; 116 | 117 | // Update binary foreground - foreground pixel 118 | b_fg_data[w*i+j] = PIXEL_1CH_WHITE; 119 | } 120 | } 121 | } 122 | } 123 | 124 | 125 | void slMedian::setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 126 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j) 127 | { 128 | // Update background pixel 129 | bg_data[w*i+j] = (mMedians[w*i+j] += fg_data[w*i+j]).getMeanPixel(); 130 | 131 | // Update foreground pixel value 132 | fg_data[w*i+j] = (colorSystem_ == BGR ? BGR_WHITE : HSV_WHITE); 133 | 134 | // Update binary foreground - non foreground pixel 135 | b_fg_data[w*i+j] = PIXEL_1CH_BLACK; 136 | } 137 | 138 | 139 | int slMedian::specificLoadNextFrame() 140 | { 141 | return 0; 142 | } 143 | 144 | 145 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/src/slNonFgKeepFg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @file slNonFgKeepFg.h 3 | * 4 | * @author Michael Sills Lavoie 5 | * 6 | * @date 24.05.2007 7 | */ 8 | 9 | #include "slNonFgKeepFg.h" 10 | 11 | #include 12 | #include 13 | 14 | 15 | using namespace std; 16 | 17 | 18 | #define ARG_EPSILON "-e" 19 | 20 | slNonFgKeepFg slNonFgKeepFg::Creator_ = slNonFgKeepFg("nfgKeep"); 21 | 22 | 23 | slNonFgKeepFg::slNonFgKeepFg(const std::string &name): 24 | slBgSub(name) 25 | { 26 | } 27 | 28 | 29 | slNonFgKeepFg::slNonFgKeepFg(const slParameters& parameters): 30 | slBgSub(parameters) 31 | { 32 | int eps = atoi(parameters.getValue(ARG_EPSILON).c_str()); 33 | 34 | // Epsilon 35 | if (colorSystem_ == BGR) 36 | mEpsilon.setBGREpsilon(eps, eps, eps); 37 | else 38 | mEpsilon.setHSVEpsilon(eps * MAX_H / MAX_V, eps, eps); 39 | } 40 | 41 | 42 | slNonFgKeepFg::~slNonFgKeepFg() 43 | { 44 | } 45 | 46 | 47 | void slNonFgKeepFg::showSpecificParameters() const 48 | { 49 | cout << "Epsilon : " << mEpsilon << endl; 50 | 51 | cout << endl; 52 | } 53 | 54 | 55 | void slNonFgKeepFg::fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const 56 | { 57 | paramSpecMap << (slParamSpec(ARG_EPSILON, "Epsilon") << slSyntax("0..255", "15")); 58 | } 59 | 60 | 61 | slBgSub* slNonFgKeepFg::createSpecificInstance(const slParameters& parameters) const 62 | { 63 | return new slNonFgKeepFg(parameters); 64 | } 65 | 66 | 67 | int slNonFgKeepFg::specificInit() 68 | { 69 | return 0; 70 | } 71 | 72 | 73 | void slNonFgKeepFg::computeFrame() 74 | { 75 | const int w = Size_.width; 76 | const int h = Size_.height; 77 | 78 | slPixel3ch* bg_data = imageList_[ARG_BG]->getPixel3chData(); 79 | slPixel3ch* fg_data = imageList_[ARG_FG]->getPixel3chData(); 80 | 81 | slPixel3ch* q_bg_data = imageList_[ARG_QBG]->getPixel3chData(); 82 | slPixel1ch* b_fg_data = imageList_[ARG_BFG]->getPixel1chData(); 83 | 84 | slPixel3ch* cur_data = imageList_[ARG_C_FR]->getPixel3chData(); 85 | slPixel3ch* q_cur_data = imageList_[ARG_QC_FR]->getPixel3chData(); 86 | 87 | #pragma omp parallel for 88 | for (int i = 0; i < h; i++) 89 | { 90 | for (int j = 0; j < w; j++) 91 | { 92 | // Background pixel 93 | if (mEpsilon.pixIsBackground(q_cur_data[w*i+j], q_bg_data[w*i+j], 94 | colorSystem_, doConsiderLightChanges_)) 95 | { 96 | // Update background pixel 97 | bg_data[w*i+j] = cur_data[w*i+j]; 98 | 99 | // Update foreground pixel value 100 | fg_data[w*i+j] = (colorSystem_ == BGR ? BGR_WHITE : HSV_WHITE); 101 | 102 | // Update binary foreground - non foreground pixel 103 | b_fg_data[w*i+j] = PIXEL_1CH_BLACK; 104 | } 105 | // Foreground pixel 106 | else 107 | { 108 | // Update foreground pixel value 109 | fg_data[w*i+j] = cur_data[w*i+j]; 110 | 111 | // Update binary foreground - foreground pixel 112 | b_fg_data[w*i+j] = PIXEL_1CH_WHITE; 113 | } 114 | } 115 | } 116 | } 117 | 118 | 119 | void slNonFgKeepFg::setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 120 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j) 121 | { 122 | // Update background pixel 123 | bg_data[w*i+j] = fg_data[w*i+j]; 124 | 125 | // Update foreground pixel value 126 | fg_data[w*i+j] = (colorSystem_ == BGR ? BGR_WHITE : HSV_WHITE); 127 | 128 | // Update binary foreground - non foreground pixel 129 | b_fg_data[w*i+j] = PIXEL_1CH_BLACK; 130 | } 131 | 132 | 133 | int slNonFgKeepFg::specificLoadNextFrame() 134 | { 135 | return 0; 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/src/slOpenCv.cpp: -------------------------------------------------------------------------------- 1 | #include "slOpenCv.h" 2 | 3 | #pragma warning(disable : 4996) 4 | #include 5 | #pragma warning(default : 4996) 6 | #include 7 | 8 | 9 | using namespace std; 10 | 11 | 12 | slOpenCv slOpenCv::Creator_ = slOpenCv("opencv"); 13 | 14 | 15 | slOpenCv::slOpenCv(const std::string &name): 16 | slBgSub(name), mStatModel(NULL) 17 | { 18 | } 19 | 20 | 21 | slOpenCv::slOpenCv(const slParameters& parameters): 22 | slBgSub(parameters), mStatModel(NULL) 23 | { 24 | } 25 | 26 | 27 | slOpenCv::~slOpenCv() 28 | { 29 | if (mStatModel != NULL) cvReleaseBGStatModel(&mStatModel); 30 | } 31 | 32 | 33 | void slOpenCv::showSpecificParameters() const 34 | { 35 | cout << endl; 36 | } 37 | 38 | 39 | void slOpenCv::fillSpecificParameterSpecs(slParamSpecMap& paramSpecMap) const 40 | { 41 | } 42 | 43 | 44 | slBgSub* slOpenCv::createSpecificInstance(const slParameters& parameters) const 45 | { 46 | return new slOpenCv(parameters); 47 | } 48 | 49 | 50 | int slOpenCv::specificInit() 51 | { 52 | mStatModel = cvCreateFGDStatModel(imageList_[ARG_BG]->getIplImage()); 53 | 54 | return 0; 55 | } 56 | 57 | 58 | void slOpenCv::computeFrame() 59 | { 60 | cvUpdateBGStatModel(imageList_[ARG_QC_FR]->getIplImage(), mStatModel); 61 | 62 | cvCopy(mStatModel->background, imageList_[ARG_BG]->getIplImage()); 63 | cvCopy(mStatModel->foreground, imageList_[ARG_BFG]->getIplImage()); 64 | 65 | CvScalar couleur = (colorSystem_ == BGR ? CV_RGB(BGR_WHITE.r(), BGR_WHITE.g(), BGR_WHITE.b()) : 66 | CV_RGB(HSV_WHITE.h(), HSV_WHITE.s(), HSV_WHITE.v())); 67 | 68 | cvSet(imageList_[ARG_FG]->getIplImage(), couleur); 69 | cvCopy(imageList_[ARG_C_FR]->getIplImage(), imageList_[ARG_FG]->getIplImage(), mStatModel->foreground); 70 | } 71 | 72 | 73 | void slOpenCv::setBgPixel(slPixel3ch *bg_data, slPixel3ch *fg_data, 74 | slPixel1ch *b_fg_data, const int& w, const int& i, const int& j) 75 | { 76 | // Update foreground pixel value 77 | fg_data[w*i+j] = (colorSystem_ == BGR ? BGR_WHITE : HSV_WHITE); 78 | 79 | // Update binary foreground - non foreground pixel 80 | b_fg_data[w*i+j] = PIXEL_1CH_BLACK; 81 | } 82 | 83 | 84 | int slOpenCv::specificLoadNextFrame() 85 | { 86 | return 0; 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/src/slTempAvg.cpp: -------------------------------------------------------------------------------- 1 | #include "slTempAvg.h" 2 | 3 | #include 4 | #include 5 | 6 | 7 | using namespace std; 8 | using namespace slAH; 9 | 10 | 11 | #define ARG_EPSILON "-e" 12 | 13 | 14 | slTempAvg::slTempAvg() 15 | : slBgSub(), meanPix_(NULL) 16 | { 17 | setEpsilon(15); 18 | } 19 | 20 | 21 | slTempAvg::~slTempAvg() 22 | { 23 | if (meanPix_ != NULL) { 24 | delete [] meanPix_; 25 | } 26 | } 27 | 28 | 29 | void slTempAvg::fillParamSpecs(slParamSpecMap& paramSpecMap) 30 | { 31 | paramSpecMap << (slParamSpec(ARG_EPSILON, "Epsilon") << slSyntax("0..255", "15")); 32 | } 33 | 34 | 35 | void slTempAvg::setEpsilon(int eps) 36 | { 37 | // Epsilon 38 | if (colorSystem_ == SL_BGR) { 39 | epsilon_.setEpsilon(eps, eps, eps); 40 | } 41 | else { 42 | epsilon_.setEpsilon(eps * Q_H_LIMIT / Q_CHAN_LIMIT, eps, eps); 43 | } 44 | } 45 | 46 | 47 | void slTempAvg::setSubParameters(const slParameters& parameters) 48 | { 49 | setEpsilon(atoi(parameters.getValue(ARG_EPSILON).c_str())); 50 | } 51 | 52 | 53 | void slTempAvg::showSubParameters() const 54 | { 55 | cout << "--- slTempAvg ---" << endl; 56 | cout << "Epsilon : " << epsilon_ << endl; 57 | } 58 | 59 | 60 | void slTempAvg::init() 61 | { 62 | if (meanPix_ != NULL) { 63 | delete [] meanPix_; 64 | } 65 | 66 | meanPix_ = new MeanPixel3ch[imageSize_.width * imageSize_.height](); 67 | } 68 | 69 | 70 | void slTempAvg::doSubtraction(slImage1ch &bForeground) 71 | { 72 | const int w = imageSize_.width; 73 | const int h = imageSize_.height; 74 | 75 | // Empty foreground images 76 | bForeground = PIXEL_1CH_BLACK; 77 | 78 | #pragma omp parallel for 79 | for (int i = 0; i < h; i++) { 80 | const slPixel3ch* cur_row = current_[i]; 81 | const slPixel3ch* q_cur_row = qCurrent_[i]; 82 | 83 | slPixel3ch* bg_row = background_[i]; 84 | const slPixel3ch* q_bg_row = qBackground_[i]; 85 | 86 | slPixel1ch* b_fg_row = bForeground[i]; 87 | MeanPixel3ch* mean_row = &meanPix_[w * i]; 88 | 89 | for (int j = 0; j < w; j++) { 90 | // Background pixel 91 | if (epsilon_.pixIsBackground(q_cur_row[j], q_bg_row[j], colorSystem_, doConsiderLightChanges_)) { 92 | // Update background pixel 93 | bg_row[j] = (mean_row[j] += cur_row[j]).getMeanPixel(); 94 | } 95 | // Foreground pixel 96 | else { 97 | // Update binary foreground - foreground pixel 98 | b_fg_row[j] = PIXEL_1CH_WHITE; 99 | } 100 | } 101 | } 102 | } 103 | 104 | 105 | void slTempAvg::setBgPixel(const slPixel3ch *cur_row, 106 | slPixel3ch *bg_row, slPixel1ch *b_fg_row, int w, int i, int j) 107 | { 108 | // Update background pixel 109 | bg_row[j] = (meanPix_[w*i+j] += cur_row[j]).getMeanPixel(); 110 | 111 | // Update binary foreground - non foreground pixel 112 | b_fg_row[j] = PIXEL_1CH_BLACK; 113 | } 114 | 115 | 116 | void slTempAvg::prepareNextSubtraction() 117 | { 118 | } 119 | 120 | 121 | void slTempAvg::updateSubWindows() 122 | { 123 | } 124 | 125 | 126 | /////////////////////////////////////////////////////////////////////////////// 127 | // slTempAvg::MeanPixel3ch 128 | /////////////////////////////////////////////////////////////////////////////// 129 | 130 | 131 | slTempAvg::MeanPixel3ch::MeanPixel3ch() 132 | : sumB_(0), sumG_(0), sumR_(0), nbPix_(0) 133 | { 134 | } 135 | 136 | 137 | const slTempAvg::MeanPixel3ch& slTempAvg::MeanPixel3ch::operator+=(const slPixel3ch &pixel) 138 | { 139 | sumB_ += pixel.val[0]; 140 | sumG_ += pixel.val[1]; 141 | sumR_ += pixel.val[2]; 142 | 143 | nbPix_++; 144 | 145 | return *this; 146 | } 147 | 148 | 149 | slPixel3ch slTempAvg::MeanPixel3ch::getMeanPixel() const 150 | { 151 | if (nbPix_ > 0) 152 | return slPixel3ch( (sumB_ / nbPix_), 153 | (sumG_ / nbPix_), 154 | (sumR_ / nbPix_)); 155 | else 156 | return slPixel3ch(); 157 | } 158 | 159 | 160 | /////////////////////////////////////////////////////////////////////////////// 161 | // slTempAvgFactory 162 | /////////////////////////////////////////////////////////////////////////////// 163 | 164 | 165 | slTempAvgFactory slTempAvgFactory::factory_; 166 | 167 | 168 | slTempAvgFactory::slTempAvgFactory() 169 | : slBgSubFactory("tempAVG") 170 | { 171 | } 172 | 173 | 174 | slTempAvgFactory::~slTempAvgFactory() 175 | { 176 | } 177 | 178 | 179 | void slTempAvgFactory::fillParamSpecs(slParamSpecMap& paramSpecMap) const 180 | { 181 | slTempAvg::fillParamSpecs(paramSpecMap); 182 | } 183 | 184 | 185 | slTempAvg* slTempAvgFactory::createInstance() const 186 | { 187 | return new slTempAvg(); 188 | } 189 | 190 | 191 | -------------------------------------------------------------------------------- /SDK_LITIV/slBgSub/src/slTestComparaison.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * file slTestComparaison.cpp 3 | * PURPOSE: Comparer des images segmenter a la main avec celles faite par un soustracteur. 4 | * 5 | * author Michael Sills Lavoie, Pier-Luc St-Onge 6 | * 7 | * date 20.06.2007 - February 2012 8 | */ 9 | 10 | #include "slTestComparaison.h" 11 | 12 | 13 | using namespace cv; 14 | using namespace std; 15 | using namespace slAH; 16 | 17 | 18 | /* 19 | * Destructeur de la classe. 20 | * Cette methode finalise l analyse du fichier_ en entran le total des informations traite 21 | * et en fermant le fichier_. 22 | */ 23 | slTestComparaison::~slTestComparaison() 24 | { 25 | close(); 26 | } 27 | 28 | 29 | /* 30 | * Initialisation de l objet avant le debut du traitement. 31 | * On creer ici le fichier_ texte qui sera utiliser pour le traitement en faisant bien sur 32 | * qu il n existe pas deja. Si c est le cas le nom utiliser sera [nom du video][(version)][.txt] 33 | */ 34 | void slTestComparaison::open(const std::string &filename, const slAH::slParameters& parameters) 35 | { 36 | // Set default output filename prefix 37 | filenamePrefix_ = filename.substr(0, filename.size() - 4); 38 | 39 | //Test to see if the file already exist (if it exist we change the name of the file 40 | bool openCorrectly = false; 41 | int nbOfFile = 0; 42 | string resultsFilename = filenamePrefix_; 43 | 44 | do { 45 | ifstream exist; 46 | exist.open((resultsFilename + ".txt").c_str(), ios::in); 47 | 48 | if (!exist.fail()) { 49 | exist.close(); 50 | 51 | char temp[10]; 52 | _itoa_s(++nbOfFile, temp, 10, 10); 53 | resultsFilename = filenamePrefix_ + "(" + string(temp) + ")"; 54 | } 55 | else { 56 | exist.clear(); 57 | openCorrectly = true; 58 | } 59 | } while(!openCorrectly); 60 | 61 | // Open file and write header 62 | results_.open((resultsFilename + ".txt").c_str(), ios::out); 63 | results_ << "TEST DE QUALITE DE LA SOUSTRACTION D'ARRIERE-PLAN"<< endl << endl; 64 | results_ << "Parametres utilises avec leurs valeurs respectives: " << endl << endl; 65 | parameters.printParameters(results_); 66 | results_ << endl << endl; 67 | 68 | // Reset all statistics 69 | truePositives_ = 0; 70 | trueNegatives_ = 0; 71 | falsePositives_ = 0; 72 | falseNegatives_ = 0; 73 | } 74 | 75 | 76 | /* 77 | * Methode executer apres le traitement de chaque frame. 78 | * Cette methode cherche dans le dossier ou se trouve le video pour voir si il 79 | * y a une image traite a la main, si oui elle execute la comparaison, si non, 80 | * elle ne fait rien. (voir la declaration de la classe pour plus de detail. 81 | */ 82 | void slTestComparaison::compare(int index, const slImage1ch &binaryFG, const slImage1ch &groundTruth) 83 | { 84 | if (!results_.is_open()) return; 85 | if (groundTruth.empty()) return; 86 | 87 | const Size imSize = binaryFG.size(); 88 | 89 | unsigned int truePos = 0; 90 | unsigned int trueNeg = 0; 91 | unsigned int falsePos = 0; 92 | unsigned int falseNeg = 0; 93 | 94 | for (int i = 0; i < imSize.height; i++) { 95 | for (int j = 0; j < imSize.width; j++) { 96 | if (groundTruth[i][j] < 128) { 97 | if (binaryFG[i][j] < 128) { 98 | trueNeg++; 99 | } 100 | else { // binaryFG[i][j] >= 128 101 | falsePos++; 102 | } 103 | } 104 | else { // groundTruth[i][j] >= 128 105 | if (binaryFG[i][j] < 128) { 106 | falseNeg++; 107 | } 108 | else { // binaryFG[i][j] >= 128 109 | truePos++; 110 | } 111 | } 112 | } 113 | } 114 | 115 | unsigned int nbCorrect = truePos + trueNeg; 116 | unsigned int nbTotal = truePos + trueNeg + falsePos + falseNeg; 117 | 118 | results_ << "Frame : " << index << endl; 119 | results_ << "\tTrue positives : " << truePos << endl; 120 | results_ << "\tTrue negatives : " << trueNeg << endl; 121 | results_ << "\tCorrectly identified pixels : " << nbCorrect << endl; 122 | results_ << "\tPercentage of correctly identified pixels : " 123 | << (100.0 * nbCorrect / nbTotal) << "%" << endl; 124 | results_ << "\tFalse positives : " << falsePos << endl; 125 | results_ << "\tFalse negatives : " << falseNeg << endl; 126 | results_ << "\tPercentage of incorrectly identifid pixels : " 127 | << (100.0 * (falsePos + falseNeg) / nbTotal) << "%" << endl << endl; 128 | 129 | truePositives_ += truePos; 130 | trueNegatives_ += trueNeg; 131 | falsePositives_ += falsePos; 132 | falseNegatives_ += falseNeg; 133 | } 134 | 135 | 136 | void slTestComparaison::close() 137 | { 138 | if (results_.is_open()) { 139 | unsigned long long int nbCorrect = truePositives_ + trueNegatives_; 140 | unsigned long long int nbTotal = 141 | truePositives_ + trueNegatives_ + falsePositives_ + falseNegatives_; 142 | 143 | results_ << "Total : " << endl; 144 | results_ << "\tTrue positives : " << truePositives_ << endl; 145 | results_ << "\tTrue negatives : " << trueNegatives_ << endl; 146 | results_ << "\tCorrectly identified pixels : " << nbCorrect << endl; 147 | results_ << "\tPercentage of correctly identified pixels : " 148 | << (100.0 * nbCorrect / nbTotal) << "%" << endl; 149 | results_ << "\tFalse positives : " << falsePositives_ << endl; 150 | results_ << "\tFalse negatives : " << falseNegatives_ << endl; 151 | results_ << "\tPercentage of incorrectly identifid pixels : " 152 | << (100.0 * (falsePositives_ + falseNegatives_) / nbTotal) << "%" << endl << endl; 153 | 154 | results_.close(); 155 | } 156 | } 157 | 158 | 159 | std::string slTestComparaison::getFilenamePrefix() const 160 | { 161 | return filenamePrefix_; 162 | } 163 | 164 | 165 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | MICROSOFT FOUNDATION CLASS LIBRARY : slCam Project Overview 3 | ======================================================================== 4 | 5 | 6 | AppWizard has created this slCam DLL for you. This DLL not only 7 | demonstrates the basics of using the Microsoft Foundation classes but 8 | is also a starting point for writing your DLL. 9 | 10 | This file contains a summary of what you will find in each of the files that 11 | make up your slCam DLL. 12 | 13 | slCam.vcproj 14 | This is the main project file for VC++ projects generated using an Application Wizard. 15 | It contains information about the version of Visual C++ that generated the file, and 16 | information about the platforms, configurations, and project features selected with the 17 | Application Wizard. 18 | 19 | slCam.h 20 | This is the main header file for the DLL. It declares the 21 | CslCamApp class. 22 | 23 | slCam.cpp 24 | This is the main DLL source file. It contains the class CslCamApp. 25 | 26 | slCam.rc 27 | This is a listing of all of the Microsoft Windows resources that the 28 | program uses. It includes the icons, bitmaps, and cursors that are stored 29 | in the RES subdirectory. This file can be directly edited in Microsoft 30 | Visual C++. 31 | 32 | res\slCam.rc2 33 | This file contains resources that are not edited by Microsoft 34 | Visual C++. You should place all resources not editable by 35 | the resource editor in this file. 36 | 37 | slCam.def 38 | This file contains information about the DLL that must be 39 | provided to run with Microsoft Windows. It defines parameters 40 | such as the name and description of the DLL. It also exports 41 | functions from the DLL. 42 | 43 | ///////////////////////////////////////////////////////////////////////////// 44 | Other standard files: 45 | 46 | StdAfx.h, StdAfx.cpp 47 | These files are used to build a precompiled header (PCH) file 48 | named slCam.pch and a precompiled types file named StdAfx.obj. 49 | 50 | Resource.h 51 | This is the standard header file, which defines new resource IDs. 52 | Microsoft Visual C++ reads and updates this file. 53 | 54 | ///////////////////////////////////////////////////////////////////////////// 55 | Other notes: 56 | 57 | AppWizard uses "TODO:" to indicate parts of the source code you 58 | should add to or customize. 59 | 60 | ///////////////////////////////////////////////////////////////////////////// 61 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/include/slCameraSynchro.h: -------------------------------------------------------------------------------- 1 | /*! \file slCameraSynchro.h 2 | * \brief This file contains classes slCameraSynchro, 3 | * slSynchroSem and slSynchroSemPtr 4 | * 5 | * \author Pier-Luc St-Onge 6 | * \date October 2011 7 | */ 8 | 9 | #ifndef SLCAMERASYNCHRO_H 10 | #define SLCAMERASYNCHRO_H 11 | 12 | 13 | #ifndef SLSYNCHRO_DLL_EXPORT 14 | #ifdef WIN32 15 | #define SLSYNCHRO_DLL_EXPORT __declspec(dllexport) 16 | #else 17 | #define SLSYNCHRO_DLL_EXPORT 18 | #endif 19 | #endif 20 | 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | //! This is a dual-semaphore (go, wait) for camera synchronisation 28 | /*! 29 | * While capturing with threads, the main loop must be able to unlock 30 | * all capturing threads and, then, wait for all threads to complete 31 | * their capture of one image. 32 | * One instance of slSynchroSem is already a member of the slCamIn class. 33 | * 34 | * Here is how it works: 35 | * - slCameraSynchro::goAndWait() fixes a common base time for all slSynchroSem objects. 36 | * - This base time is the parameter of go(), which will update the internal base time 37 | * of the current slSynchroSem instance. The semaphore "go" is then unlocked. 38 | * - The function waitForGo() waits for the "go" semaphore. 39 | * Finally, waitForGo() will loop as long as the current time is less than 40 | * the sum of the base time and the private delay. 41 | * 42 | * The private delay is almost always updated by using function reset(), which 43 | * also resets both internal semaphores. 44 | * 45 | * \see slCamIn, slCameraSynchro, slSynchroSemPtr 46 | * \author Pier-Luc St-Onge 47 | * \date October 2011 48 | */ 49 | class SLSYNCHRO_DLL_EXPORT slSynchroSem 50 | { 51 | public: 52 | slSynchroSem(clock_t delay = 0); //!< Constructor which initiates both semaphores 53 | ~slSynchroSem(); 54 | 55 | void reset(clock_t delay); //!< Closes both semaphores, and recreate them both 56 | 57 | void go(clock_t baseTime = 0); //!< Unlocks "go" semaphore 58 | void done(); //!< Unlocks "done" semaphore 59 | 60 | void waitForGo(); //!< Waits for "go" semaphore and applies the delay (loop for a few milliseconds) 61 | void waitForDone(); //!< Waits for "done" semaphore 62 | 63 | bool loop() const; //!< Returns true if not stopping 64 | void stopLoop(); //!< Modifies "stop" boolean and unlocks "go" semaphore 65 | 66 | bool operator<(const slSynchroSem &ss) const; //!< Less-than operator for sorting purposes 67 | 68 | protected: 69 | slSynchroSem operator=(const slSynchroSem &ss); 70 | 71 | private: 72 | void init(clock_t delay); 73 | void clear(); 74 | 75 | private: 76 | int id_; // Make sure each instance is not equal (< or >) to another instance 77 | 78 | clock_t baseTime_; // Common basetime for each synchronized capture 79 | clock_t delay_; // Private delay 80 | 81 | HANDLE go_; // "go" semaphore 82 | HANDLE done_; // "done" semaphore 83 | 84 | bool stop_; // True if must stop loop 85 | 86 | static int count_; // Count for a unique id 87 | }; 88 | 89 | 90 | //! This is an automatic pointer for slSynchroSem instances 91 | /*! 92 | * It implements the arrow operator. 93 | * It also implements the less-than operator, since slSynchroSemPtr objects 94 | * are sorted in a slCameraSynchro set. 95 | * 96 | * \see slSynchroSem, slCameraSynchro, slCamIn 97 | * \author Pier-Luc St-Onge 98 | * \date October 2011 99 | */ 100 | class SLSYNCHRO_DLL_EXPORT slSynchroSemPtr 101 | { 102 | public: 103 | slSynchroSemPtr(slSynchroSem *ref = NULL); 104 | 105 | slSynchroSem* operator->() const; //!< Arrow operator, like a regular pointer 106 | 107 | bool operator<(const slSynchroSemPtr &ssptr) const; //!< For sorting purposes 108 | 109 | private: 110 | slSynchroSem *ref_; 111 | 112 | }; 113 | 114 | 115 | //! This is a set of dual-semaphores for camera synchronisation 116 | /*! 117 | * class slCameraSynchro: public std::set {...}; 118 | * 119 | * The current class only stores slSynchroSemPtr objects, which are 120 | * automatic pointers to slSynchroSem instances: 121 | * \code 122 | * slCameraSynchro synchro; 123 | * 124 | * synchro.insert(cam1->synchro()); 125 | * synchro.insert(cam2->synchro()); 126 | * \endcode 127 | * 128 | * The real instances of slSynchroSem are owned by the slCamIn objects. 129 | * So, each camera is controlled by its own dual-semaphore. 130 | * Furthermore, each camera could be started with an individual delay. 131 | * 132 | * The role of slCameraSynchro is to unlock all threads, and 133 | * wait for all captures to be done: 134 | * \code 135 | * while (capture) { 136 | * // This will trigger both captures at the same time according to the individual delay 137 | * // This function returns when both captures are done 138 | * synchro.goAndWait(); 139 | * } 140 | * \endcode 141 | * 142 | * \see slCamIn for an example, slSynchroSemPtr, slSynchroSem 143 | * \author Pier-Luc St-Onge 144 | * \date October 2011 145 | */ 146 | class SLSYNCHRO_DLL_EXPORT slCameraSynchro: public std::set 147 | { 148 | public: 149 | void goAndWait(); //!< Releases all "go" semaphores and waits for all "wait" semaphores 150 | 151 | }; 152 | 153 | 154 | #endif // SLCAMERASYNCHRO_H 155 | 156 | 157 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/include/slFlirCam.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slCam/include/slFlirCam.h -------------------------------------------------------------------------------- /SDK_LITIV/slCam/include/slUnibrainCam.h: -------------------------------------------------------------------------------- 1 | /*! \file slUnibrainCam.h 2 | * \brief This file contains the class slUnibrainCam. 3 | * 4 | * \author Pier-Luc St-Onge 5 | * \date May 2011 6 | */ 7 | 8 | #ifndef SLUNIBRAINCAM_H 9 | #define SLUNIBRAINCAM_H 10 | 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #if defined(MIN) || defined(MAX) 18 | #undef MIN 19 | #undef MAX 20 | #endif 21 | 22 | #include "slCamIn.h" 23 | 24 | 25 | //! This class uses Unibrain's SDK for the use of Sony IIDC cameras 26 | /*! 27 | * This class is compatible with 1 channel and 3 channels images. 28 | * In case of 1 channel format from camera, slUnibrainCam will ask 29 | * if user wants a conversion with a Bayer filter. 30 | * Then, the output will be 3 channels images. 31 | * 32 | * The open() function usually takes an empty string. A non empty string 33 | * could possibly contain the GUID code, but it is not yet supported. 34 | * With the empty guid string, a window could appear to let the user choose 35 | * the camera he wants to use. If only one Unibrain compatible camera is 36 | * connected to the computer, no window is shown, and this camera is chosen by default. 37 | * 38 | * \see slCamIn 39 | * \author Pier-Luc St-Onge 40 | * \date May 2011 41 | */ 42 | class SLCAMIN_DLL_EXPORT slUnibrainCam: public slCamIn 43 | { 44 | public: 45 | slUnibrainCam(); //!< Constructor 46 | virtual ~slUnibrainCam(); 47 | 48 | slUnibrainCam& open(const std::string &guid = ""); //!< Empty guid lets you choose a camera from a GUI. 49 | void close(); //!< Close camera connexion 50 | 51 | std::string description2() const; //!< Other specifications 52 | bool inColors() const; //!< Useful to know if the output format is 1 or 3 channels 53 | 54 | bool hasParameters() const; //!< Returns true: GUI available 55 | bool hasDynamicParameters() const; //!< Returns true: GUI available at capture time 56 | void showParameters(); //!< Show parameters editor 57 | void hideParameters(); //!< Hide parameters editor 58 | 59 | void read(slMat &image); //!< Capture an image from camera and copy header to image 60 | 61 | protected: 62 | void startAfter(); 63 | void stopBefore(); 64 | 65 | private: 66 | void iidcInit(); 67 | void iidcUninit(); 68 | 69 | void obtainSpecifications(); 70 | bool isStarted() const; 71 | 72 | static FIREi_CAMERA_GUID invalidGUID(); 73 | 74 | static long long compare(const FIREi_CAMERA_GUID &guid1, const FIREi_CAMERA_GUID &guid2); 75 | 76 | static std::string guidToHex(const FIREi_CAMERA_GUID &guid); 77 | static long long guidToLL(const FIREi_CAMERA_GUID &guid); 78 | static FIREi_CAMERA_GUID llToGUID(const long long llid); 79 | 80 | static std::string getString(FIREi_CAMERA_HANDLE camHandle, FIREi_OID oidCode); 81 | static void throwLastError(const std::string &prefix, FIREi_STATUS status); 82 | 83 | private: 84 | static unsigned long nbUnibrainObj_; 85 | static std::set usedGUID_; 86 | 87 | FIREi_CAMERA_GUID guid_; 88 | FIREi_CAMERA_HANDLE handle_; 89 | FIREi_CAMERA_STARTUP_INFO startupInfo_; 90 | UBUI_SETTINGS_HANDLE settings_; 91 | FIREi_ISOCH_ENGINE_HANDLE engine_; 92 | 93 | bool mono_; 94 | bool doBayer_; 95 | 96 | }; 97 | 98 | 99 | class SLCAMIN_DLL_EXPORT slUnibrainCamFactory: public slCamInFactory 100 | { 101 | public: 102 | virtual ~slUnibrainCamFactory(); 103 | 104 | protected: 105 | // To specify your functions's parameters 106 | void fillParamSpecs(slAH::slParamSpecMap& paramSpecMap) const; 107 | 108 | // The factory (a static instance) will create an instance of your slCamIn 109 | slUnibrainCam* createInstance() const; 110 | 111 | private: 112 | // The factory's constructor 113 | slUnibrainCamFactory(); 114 | 115 | private: 116 | static slUnibrainCamFactory factory_; 117 | 118 | }; 119 | 120 | 121 | #endif // SLUNIBRAINCAM_H 122 | 123 | 124 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/res/slCam.rc2: -------------------------------------------------------------------------------- 1 | // 2 | // slCam.RC2 - resources Microsoft Visual C++ does not edit directly 3 | // 4 | 5 | #ifdef APSTUDIO_INVOKED 6 | #error this file is not editable by Microsoft Visual C++ 7 | #endif //APSTUDIO_INVOKED 8 | 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Add manually edited resources here... 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by slCam.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | 11 | #define _APS_NEXT_RESOURCE_VALUE 2000 12 | #define _APS_NEXT_CONTROL_VALUE 2000 13 | #define _APS_NEXT_SYMED_VALUE 2000 14 | #define _APS_NEXT_COMMAND_VALUE 32771 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/slCam.cpp: -------------------------------------------------------------------------------- 1 | // slCam.cpp : Defines the initialization routines for the DLL. 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "slCam.h" 6 | 7 | #ifdef _DEBUG 8 | #define new DEBUG_NEW 9 | #endif 10 | 11 | // 12 | //TODO: If this DLL is dynamically linked against the MFC DLLs, 13 | // any functions exported from this DLL which call into 14 | // MFC must have the AFX_MANAGE_STATE macro added at the 15 | // very beginning of the function. 16 | // 17 | // For example: 18 | // 19 | // extern "C" BOOL PASCAL EXPORT ExportedFunction() 20 | // { 21 | // AFX_MANAGE_STATE(AfxGetStaticModuleState()); 22 | // // normal function body here 23 | // } 24 | // 25 | // It is very important that this macro appear in each 26 | // function, prior to any calls into MFC. This means that 27 | // it must appear as the first statement within the 28 | // function, even before any object variable declarations 29 | // as their constructors may generate calls into the MFC 30 | // DLL. 31 | // 32 | // Please see MFC Technical Notes 33 and 58 for additional 33 | // details. 34 | // 35 | 36 | // CslCamApp 37 | 38 | BEGIN_MESSAGE_MAP(CslCamApp, CWinApp) 39 | END_MESSAGE_MAP() 40 | 41 | 42 | // CslCamApp construction 43 | 44 | CslCamApp::CslCamApp() 45 | { 46 | // TODO: add construction code here, 47 | // Place all significant initialization in InitInstance 48 | } 49 | 50 | 51 | // The one and only CslCamApp object 52 | 53 | CslCamApp theApp; 54 | 55 | 56 | // CslCamApp initialization 57 | 58 | BOOL CslCamApp::InitInstance() 59 | { 60 | CWinApp::InitInstance(); 61 | 62 | return TRUE; 63 | } 64 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/slCam.def: -------------------------------------------------------------------------------- 1 | ; slCam.def : Declares the module parameters for the DLL. 2 | 3 | LIBRARY "slCam22" 4 | 5 | EXPORTS 6 | ; Explicit exports can go here 7 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/slCam.h: -------------------------------------------------------------------------------- 1 | // slCam.h : main header file for the slCam DLL 2 | // 3 | 4 | #pragma once 5 | 6 | #ifndef __AFXWIN_H__ 7 | #error "include 'stdafx.h' before including this file for PCH" 8 | #endif 9 | 10 | #include "resource.h" // main symbols 11 | 12 | 13 | // CslCamApp 14 | // See slCam.cpp for the implementation of this class 15 | // 16 | 17 | class CslCamApp : public CWinApp 18 | { 19 | public: 20 | CslCamApp(); 21 | 22 | // Overrides 23 | public: 24 | virtual BOOL InitInstance(); 25 | 26 | DECLARE_MESSAGE_MAP() 27 | }; 28 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/slCam.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #ifndef APSTUDIO_INVOKED 11 | #include "targetver.h" 12 | #endif 13 | #include "afxres.h" 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | #undef APSTUDIO_READONLY_SYMBOLS 17 | 18 | #ifdef APSTUDIO_INVOKED 19 | ///////////////////////////////////////////////////////////////////////////// 20 | // 21 | // TEXTINCLUDE 22 | // 23 | 24 | 1 TEXTINCLUDE 25 | BEGIN 26 | "resource.h\0" 27 | END 28 | 29 | 2 TEXTINCLUDE 30 | BEGIN 31 | "#ifndef APSTUDIO_INVOKED\r\n" 32 | "#include ""targetver.h""\r\n" 33 | "#endif\r\n" 34 | "#include ""afxres.h""\r\n" 35 | "\0" 36 | END 37 | 38 | 3 TEXTINCLUDE 39 | BEGIN 40 | "#define _AFX_NO_SPLITTER_RESOURCES\r\n" 41 | "#define _AFX_NO_OLE_RESOURCES\r\n" 42 | "#define _AFX_NO_TRACKER_RESOURCES\r\n" 43 | "#define _AFX_NO_PROPERTY_RESOURCES\r\n" 44 | "\r\n" 45 | "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" 46 | "LANGUAGE 9, 1\r\n" 47 | "#pragma code_page(1252)\r\n" 48 | "#include ""res\\slCam.rc2"" // non-Microsoft Visual C++ edited resources\r\n" 49 | #ifndef _AFXDLL 50 | "#include ""afxres.rc"" // Standard components\r\n" 51 | #endif 52 | "#endif\r\n" 53 | "\0" 54 | END 55 | 56 | ///////////////////////////////////////////////////////////////////////////// 57 | #endif // APSTUDIO_INVOKED 58 | 59 | 60 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 61 | LANGUAGE 9, 1 62 | #pragma code_page(1252) 63 | 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // 66 | // Version 67 | // 68 | 69 | VS_VERSION_INFO VERSIONINFO 70 | FILEVERSION 1,0,0,1 71 | PRODUCTVERSION 1,0,0,1 72 | FILEFLAGSMASK 0x3fL 73 | #ifdef _DEBUG 74 | FILEFLAGS 0x1L 75 | #else 76 | FILEFLAGS 0x0L 77 | #endif 78 | FILEOS 0x4L 79 | FILETYPE 0x2L 80 | FILESUBTYPE 0x0L 81 | BEGIN 82 | BLOCK "StringFileInfo" 83 | BEGIN 84 | BLOCK "040904e4" 85 | BEGIN 86 | VALUE "CompanyName", "TODO: " 87 | VALUE "FileDescription", "TODO: " 88 | VALUE "FileVersion", "1.0.0.1" 89 | VALUE "InternalName", "slCam.dll" 90 | VALUE "LegalCopyright", "TODO: (c) . All rights reserved." 91 | VALUE "OriginalFilename","slCam.dll" 92 | VALUE "ProductName", "TODO: " 93 | VALUE "ProductVersion", "1.0.0.1" 94 | END 95 | END 96 | BLOCK "VarFileInfo" 97 | BEGIN 98 | VALUE "Translation", 0x0409, 1252 99 | END 100 | END 101 | 102 | #endif 103 | #ifndef APSTUDIO_INVOKED 104 | 105 | ///////////////////////////////////////////////////////////////////////////// 106 | // 107 | // Generated from the TEXTINCLUDE 3 resource. 108 | // 109 | #define _AFX_NO_SPLITTER_RESOURCES 110 | #define _AFX_NO_OLE_RESOURCES 111 | #define _AFX_NO_TRACKER_RESOURCES 112 | #define _AFX_NO_PROPERTY_RESOURCES 113 | 114 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 115 | LANGUAGE 9, 1 116 | #pragma code_page(1252) 117 | #include "res\\slCam.rc2" // non-Microsoft Visual C++ edited resources 118 | #ifndef _AFXDLL 119 | #include "afxres.rc" // Standard components 120 | #endif 121 | #endif 122 | 123 | ///////////////////////////////////////////////////////////////////////////// 124 | #endif // not APSTUDIO_INVOKED 125 | 126 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/slCam.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {e8d0c750-f9af-4f65-a8a7-f5bda90dd4d1} 10 | 11 | 12 | {fb79265f-bd25-4a47-bad4-6eeee535b3e1} 13 | 14 | 15 | {deaa1be4-c557-4924-aace-24734f071879} 16 | 17 | 18 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 19 | h;hpp;hxx;hm;inl;inc;xsd 20 | 21 | 22 | {d6686829-328a-49af-af1b-5562758c50cb} 23 | 24 | 25 | {0a712fc7-384d-444f-ab90-473f104c32e7} 26 | 27 | 28 | {01088c27-bd13-42a4-8c2f-595e3a022e7a} 29 | 30 | 31 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 32 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 33 | 34 | 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files\Cameras 44 | 45 | 46 | Source Files\Cameras 47 | 48 | 49 | Source Files\Cameras 50 | 51 | 52 | Source Files 53 | 54 | 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Resource Files 64 | 65 | 66 | 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files\Cameras 82 | 83 | 84 | Header Files\Cameras 85 | 86 | 87 | Header Files\Cameras 88 | 89 | 90 | Header Files 91 | 92 | 93 | 94 | 95 | Resource Files 96 | 97 | 98 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/slCamd.def: -------------------------------------------------------------------------------- 1 | ; slCam.def : Declares the module parameters for the DLL. 2 | 3 | LIBRARY "slCam22d" 4 | 5 | EXPORTS 6 | ; Explicit exports can go here 7 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/src/slCamIn.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slCam/src/slCamIn.cpp -------------------------------------------------------------------------------- /SDK_LITIV/slCam/src/slCameraSynchro.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "slCameraSynchro.h" 3 | 4 | 5 | ////////////////// 6 | // slSynchroSem // 7 | ////////////////// 8 | 9 | 10 | int slSynchroSem::count_ = 0; 11 | 12 | 13 | slSynchroSem::slSynchroSem(clock_t delay): id_(count_++), baseTime_(clock()) 14 | { 15 | init(delay); 16 | } 17 | 18 | 19 | void slSynchroSem::reset(clock_t delay) 20 | { 21 | clear(); 22 | init(delay); 23 | } 24 | 25 | 26 | slSynchroSem::~slSynchroSem() 27 | { 28 | clear(); 29 | } 30 | 31 | 32 | void slSynchroSem::init(clock_t delay) 33 | { 34 | delay_ = delay; 35 | go_ = CreateSemaphore(NULL, 0, 1, NULL); 36 | done_ = CreateSemaphore(NULL, 0, 1, NULL); 37 | stop_ = false; 38 | } 39 | 40 | 41 | void slSynchroSem::clear() 42 | { 43 | CloseHandle(go_); 44 | CloseHandle(done_); 45 | } 46 | 47 | 48 | void slSynchroSem::go(clock_t baseTime) 49 | { 50 | baseTime_ = baseTime; 51 | ReleaseSemaphore(go_, 1, NULL); 52 | } 53 | 54 | 55 | void slSynchroSem::done() 56 | { 57 | ReleaseSemaphore(done_, 1, NULL); 58 | } 59 | 60 | 61 | void slSynchroSem::waitForGo() 62 | { 63 | WaitForSingleObject(go_, INFINITE); 64 | 65 | while (clock() < baseTime_ + delay_) { 66 | #if 1 67 | Sleep(0); 68 | #endif 69 | } 70 | } 71 | 72 | 73 | void slSynchroSem::waitForDone() 74 | { 75 | WaitForSingleObject(done_, INFINITE); 76 | } 77 | 78 | 79 | bool slSynchroSem::loop() const 80 | { 81 | return !stop_; 82 | } 83 | 84 | 85 | void slSynchroSem::stopLoop() 86 | { 87 | stop_ = true; 88 | go(); 89 | } 90 | 91 | 92 | bool slSynchroSem::operator<(const slSynchroSem &ss) const 93 | { 94 | return (delay_ < ss.delay_) || (delay_ == ss.delay_) && (id_ < ss.id_); 95 | } 96 | 97 | 98 | ///////////////////// 99 | // slSynchroSemPtr // 100 | ///////////////////// 101 | 102 | 103 | slSynchroSemPtr::slSynchroSemPtr(slSynchroSem *ref): ref_(ref) 104 | { 105 | } 106 | 107 | 108 | slSynchroSem* slSynchroSemPtr::operator->() const 109 | { 110 | return ref_; 111 | } 112 | 113 | 114 | bool slSynchroSemPtr::operator<(const slSynchroSemPtr &ssptr) const 115 | { 116 | return (*ref_ < *ssptr.ref_); 117 | } 118 | 119 | 120 | ///////////////////// 121 | // slCameraSynchro // 122 | ///////////////////// 123 | 124 | 125 | void slCameraSynchro::goAndWait() 126 | { 127 | clock_t baseTime = clock(); 128 | 129 | for (iterator it = begin(); it != end(); it++) { 130 | (*it)->go(baseTime); 131 | } 132 | 133 | for (iterator it = begin(); it != end(); it++) { 134 | (*it)->waitForDone(); 135 | } 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/src/slFlirCam.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slCam/src/slFlirCam.cpp -------------------------------------------------------------------------------- /SDK_LITIV/slCam/src/slIpelaCam.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slCam/src/slIpelaCam.cpp -------------------------------------------------------------------------------- /SDK_LITIV/slCam/src/slUnibrainCam.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slCam/src/slUnibrainCam.cpp -------------------------------------------------------------------------------- /SDK_LITIV/slCam/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // slCam.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | 5 | #pragma once 6 | 7 | #ifndef VC_EXTRALEAN 8 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 9 | #endif 10 | 11 | #include "targetver.h" 12 | 13 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit 14 | 15 | #include // MFC core and standard components 16 | #include // MFC extensions 17 | 18 | #ifndef _AFX_NO_OLE_SUPPORT 19 | #include // MFC OLE classes 20 | #include // MFC OLE dialog classes 21 | #include // MFC Automation classes 22 | #endif // _AFX_NO_OLE_SUPPORT 23 | 24 | #ifndef _AFX_NO_DB_SUPPORT 25 | #include // MFC ODBC database classes 26 | #endif // _AFX_NO_DB_SUPPORT 27 | 28 | #ifndef _AFX_NO_DAO_SUPPORT 29 | #include // MFC DAO database classes 30 | #endif // _AFX_NO_DAO_SUPPORT 31 | 32 | #ifndef _AFX_NO_OLE_SUPPORT 33 | #include // MFC support for Internet Explorer 4 Common Controls 34 | #endif 35 | #ifndef _AFX_NO_AFXCMN_SUPPORT 36 | #include // MFC support for Windows Common Controls 37 | #endif // _AFX_NO_AFXCMN_SUPPORT 38 | 39 | 40 | -------------------------------------------------------------------------------- /SDK_LITIV/slCam/targetver.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | // The following macros define the minimum required platform. The minimum required platform 5 | // is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 6 | // your application. The macros work by enabling all features available on platform versions up to and 7 | // including the version specified. 8 | 9 | // Modify the following defines if you have to target a platform prior to the ones specified below. 10 | // Refer to MSDN for the latest info on corresponding values for different platforms. 11 | #ifndef WINVER // Specifies that the minimum required platform is Windows Vista. 12 | #define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. 13 | #endif 14 | 15 | #ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. 16 | #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. 17 | #endif 18 | 19 | #ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. 20 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 21 | #endif 22 | 23 | #ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. 24 | #define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/include/slClock.h: -------------------------------------------------------------------------------- 1 | /*! \file slClock.h 2 | * \brief Contains a class that measures the elapsed time 3 | * 4 | * This file contains the definition of the class slClock. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date April 2011 8 | */ 9 | 10 | #ifndef SLCLOCK_H 11 | #define SLCLOCK_H 12 | 13 | 14 | #include 15 | 16 | #include "slCore.h" 17 | 18 | 19 | //! Like a chronometer, this class measures the elapsed time 20 | /*! 21 | * This class works like a chronometer that never stops. 22 | * You first need to start() it. Then, each time you stop() it, the clock will 23 | * save the elapsed time since we called start() the last time. 24 | * The function elapsed() lets you retrieve the elapsed time. 25 | * 26 | * That is not all. Since SDK_LITIV is made for video analysis, slClock 27 | * could also be aware of a period or an expected FPS (number of frames per second). 28 | * In both cases, slClock will work with a period in milliseconds with the 29 | * precision of a double data type. 30 | * For real time applications that need a clock synchronisation, we just have 31 | * to call nextDelay() in order to get the time to wait at the end of each 32 | * iteration of the process. Here is an example: 33 | * \code 34 | * slClock chronometer; 35 | * slVideoIn source; 36 | * slMat image; 37 | * slWindow outputWindow("Video"); 38 | * 39 | * source.open("video1.avi"); 40 | * chronometer.setFPS(source.getFPS()); 41 | * chronometer.start(); 42 | * 43 | * for (unsigned i = 0; i < source.getNbImages(); i++) { 44 | * source.read(image); 45 | * if (image.empty()) throw slException("First image is empty"); 46 | * 47 | * outputWindow.show(image); 48 | * waitKey(chronometer.nextDelay()); 49 | * } 50 | * 51 | * chronometer.stop(); 52 | * source.close(); 53 | * \endcode 54 | * 55 | * \author Pier-Luc St-Onge 56 | * \date April 2011 57 | */ 58 | class SLCORE_DLL_EXPORT slClock 59 | { 60 | public: 61 | slClock(double period = 1001.0 / 30000); //!< Default constructor for 29.97 fps 62 | ~slClock(); 63 | 64 | void setFPS(double fps); //!< Sets the period with the wanted FPS 65 | void setPeriod(double period); //!< Sets the period explicitly 66 | 67 | void start(); //!< Stop all, reset nbFrames and save start time 68 | clock_t nextDelay(); //!< Returns the time to wait (ms) 69 | void stop(); //!< Save stop time 70 | 71 | clock_t elapsed() const; //!< Elapsed time (ms) 72 | unsigned int nbFrames() const; //!< Number of frames 73 | double getMeasuredFPS() const; //!< Effective FPS 74 | 75 | private: 76 | double periodInClocks_; // In clock ticks (ms) 77 | 78 | clock_t startTime_, stopTime_; 79 | unsigned int nbFrames_; 80 | 81 | }; 82 | 83 | 84 | #endif // SLCLOCK_H 85 | 86 | 87 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/include/slCore.h: -------------------------------------------------------------------------------- 1 | /*! \file slCore.h 2 | * \brief This file contains some definitions like pixels and images 3 | * 4 | * The standard SDK_LITIV pixels and images types are defined here. 5 | * Example: 6 | * \code 7 | * slImage3ch source; 8 | * slImage1ch target; 9 | * 10 | * source.create(Size(width, height)); 11 | * source = HSV_WHITE; // Fill with white HSV 12 | * target = grayClone(source, SL_HSV); // Get the Value components 13 | * \endcode 14 | * 15 | * \author Pier-Luc St-Onge 16 | * \date April 2011 17 | */ 18 | 19 | #ifndef SLCORE_H 20 | #define SLCORE_H 21 | 22 | 23 | #ifndef SLCORE_DLL_EXPORT 24 | #ifdef WIN32 25 | #define SLCORE_DLL_EXPORT __declspec(dllexport) 26 | #else 27 | #define SLCORE_DLL_EXPORT 28 | #endif 29 | #endif 30 | 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | //! Constants for colors system identification 38 | /*! 39 | * - SL_BGR: the RGB color space is saved in this order: BGRBGR... 40 | * - SL_HSV: the HSV color space 41 | * - SL_GRAYSCALE: for grayscale values (uchar or float) 42 | * - COLOR_SYS_COUNT: number of supported color spaces 43 | */ 44 | typedef enum typeColorSys {SL_BGR, SL_HSV, SL_GRAYSCALE, COLOR_SYS_COUNT}; 45 | 46 | 47 | // Names and syntax for argument handling 48 | #define BGR_NAME "rgb" 49 | #define HSV_NAME "hsv" 50 | #define CSYS_SYNTAX (string(BGR_NAME) + "|" + HSV_NAME) 51 | #define CSYS_DEFAULT BGR_NAME 52 | 53 | 54 | typedef cv::Vec3b slPixel3ch; //!< Regular BGR or HSV pixel 55 | typedef uchar slPixel1ch; //!< Regular grayscale pixel (0..255) 56 | typedef float slPixel1fl; //!< Special grayscale pixel (0..1.0) 57 | 58 | typedef cv::Mat slMat; //!< Generic OpenCV matrix 59 | typedef cv::Mat_ slImage3ch; //!< Regular BGR or HSV image 60 | typedef cv::Mat_ slImage1ch; //!< Regular grayscale image (0..255) 61 | typedef cv::Mat_ slImage1fl; //!< Special grayscale image (0..1.0) 62 | 63 | #define PIXEL_1CH_BLACK ((slPixel1ch)0x00) //!< Black pixel, 1 channel 64 | #define PIXEL_1CH_WHITE ((slPixel1ch)0xFF) //!< White pixel, 1 channel 65 | #define BGR_WHITE slPixel3ch(0xff, 0xff, 0xff) //!< White pixel, 3 channels Blue-Green-Red 66 | #define HSV_WHITE slPixel3ch(0x00, 0x00, 0xff) //!< White pixel, 3 channels Hue-Saturation-Value (red white) 67 | 68 | #define slRGB(r, g, b) slPixel3ch((b), (g), (r)) //!< Convenient RGB constructor 69 | 70 | //! Converts a 3-channels image into a grayscale image 71 | /*! 72 | * This function creates a new slImage1ch (new buffer). 73 | * Then, it converts the 3-channels image into a grayscale image 74 | * according to its color space. 75 | * - For BGR images, it uses cv::cvtColor(..., ..., CV_BGR2GRAY) 76 | * - For HSV images, it returns the V component only 77 | */ 78 | SLCORE_DLL_EXPORT slImage1ch grayClone(const slImage3ch &image, typeColorSys csys = SL_BGR); 79 | 80 | 81 | #endif // SLCORE_H 82 | 83 | 84 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/include/slException.h: -------------------------------------------------------------------------------- 1 | /*! \file slException.h 2 | * \brief Contains different exception classes 3 | * 4 | * This file contains the definition of classes slException, slExceptionIO, 5 | * slExceptionArgHandler, slExceptionBgSub and slExceptionCamIn. 6 | * 7 | * \author Pier-Luc St-Onge 8 | * \date August 2008 9 | */ 10 | 11 | #ifndef _SLEXCEPTION_H_ 12 | #define _SLEXCEPTION_H_ 13 | 14 | 15 | #include "slCore.h" 16 | 17 | #include 18 | 19 | 20 | //! Base exception class 21 | /*! 22 | * This is the base class used as an exception object containing an error 23 | * message and, maybe, the name of the class from which the error was thrown. 24 | * In fact, the class name may not be the actual class that raised the error. 25 | * But, most of the time, all the details (class, function member) are in the message. 26 | * 27 | * \see slExceptionIO, slExceptionArgHandler, slExceptionBgSub, slExceptionCamIn 28 | * \author Michael Eilers-Smith, modified by Pier-Luc St-Onge 29 | * \date August 2008 30 | */ 31 | class SLCORE_DLL_EXPORT slException 32 | { 33 | public: 34 | slException(const char* error, const char* name = 0); //!< throw slException(errorMessage, name); 35 | virtual ~slException(); 36 | 37 | inline const char* getMessage() const { return err_; } //!< Returns the error message 38 | inline const char* getName() const { return name_; } //!< Returns the class name 39 | 40 | protected: 41 | char* err_; // 255 characters 42 | char* name_; // 50 characters 43 | 44 | }; 45 | 46 | 47 | //! slArgHandler Exception class 48 | /*! 49 | * The class name would be "slArgHandler". 50 | * 51 | * \see slException 52 | * \author Michael Eilers-Smith, modified by Pier-Luc St-Onge 53 | * \date August 2008 54 | */ 55 | class SLCORE_DLL_EXPORT slExceptionArgHandler : public slException 56 | { 57 | public: 58 | slExceptionArgHandler(const std::string& error); //!< Constructor 59 | 60 | }; 61 | 62 | 63 | //! slIO Exception class 64 | /*! 65 | * The class name would be "slIO". 66 | * 67 | * \see slException 68 | * \author Michael Eilers-Smith, modified by Pier-Luc St-Onge 69 | * \date August 2008 70 | */ 71 | class SLCORE_DLL_EXPORT slExceptionIO : public slException 72 | { 73 | public: 74 | slExceptionIO(const std::string& error); //!< Constructor 75 | 76 | }; 77 | 78 | 79 | //! slCamIn Exception class 80 | /*! 81 | * The class name would be "slIO (Camera issue)". 82 | * 83 | * \see slException 84 | * \author Michael Eilers-Smith, modified by Pier-Luc St-Onge 85 | * \date August 2008 86 | */ 87 | class SLCORE_DLL_EXPORT slExceptionCamIn : public slExceptionIO 88 | { 89 | public: 90 | slExceptionCamIn(const std::string& error); //!< Constructor 91 | 92 | }; 93 | 94 | 95 | //! slBgSub Exception class 96 | /*! 97 | * The class name would be "slBgSub". 98 | * 99 | * \see slException 100 | * \author Michael Eilers-Smith, modified by Pier-Luc St-Onge 101 | * \date August 2008 102 | */ 103 | class SLCORE_DLL_EXPORT slExceptionBgSub : public slException 104 | { 105 | public: 106 | slExceptionBgSub(const std::string& error); //!< Constructor 107 | 108 | }; 109 | 110 | 111 | #endif // _SLEXCEPTION_H_ 112 | 113 | 114 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/include/slHistogram3ch.h: -------------------------------------------------------------------------------- 1 | /*! \file slHistogram3ch.h 2 | * \brief Histogram used in rectangle background subtractor 3 | * 4 | * \author Michael Sills Lavoie, Pier-Luc St-Onge 5 | * \date 23.05.2007 - February 2012 6 | */ 7 | 8 | #ifndef _SLHISTOGRAM3CH_H_ 9 | #define _SLHISTOGRAM3CH_H_ 10 | 11 | 12 | #include 13 | 14 | #include "slCore.h" 15 | 16 | 17 | //! Histogram used in Rafik background subtractor. 18 | /*! 19 | * The background subtractor algorithm is implemented in slRectSimple. 20 | * \see slRectPixels, slRectSimple 21 | * \author Michael Sills Lavoie, Pier-Luc St-Onge 22 | * \date February 2012 23 | */ 24 | class SLCORE_DLL_EXPORT slHistogram3ch 25 | { 26 | public: 27 | slHistogram3ch(); //!< Constructor 28 | ~slHistogram3ch(); //!< Destructor 29 | 30 | static void setRange(int range1,int range2, int range3); //!< Static fonction used to set the range of each histogram 31 | static void setColorSpace(bool HSV); //!< HSV or not 32 | static void setDistanceMethod(bool MPDA); //!< MPDA distance or not 33 | 34 | void clear(void); //!< Reset or empty all histograms 35 | void normalize (void); //!< Normalize the sum to 1.0 36 | 37 | bool isEmpty (void) const; //!< Returns true if empty 38 | 39 | slHistogram3ch& operator += (const slHistogram3ch& right); //!< Add other histograms' values 40 | slHistogram3ch& operator += (const slPixel3ch& right); //!< Add a pixel's channels to the histograms 41 | 42 | std::vector compare (const slHistogram3ch& right) const; 43 | 44 | private: 45 | 46 | /* 47 | *Upper limit of the histogram. 48 | *Highest value possible for a pixel single chanel after quantification. 49 | */ 50 | static int RANGE1; 51 | /* 52 | *Upper limit of the histogram. 53 | *Highest value possible for a pixel single chanel after quantification. 54 | */ 55 | static int RANGE2; 56 | /* 57 | *Upper limit of the histogram. 58 | *Highest value possible for a pixel single chanel after quantification. 59 | */ 60 | static int RANGE3; 61 | /* 62 | *Define the color space used in the histogram. 63 | *True is HSV. 64 | */ 65 | static bool HSV_; 66 | /* 67 | *Define the distance computation method used to check the distance of the histogram. 68 | *True is MPDA (Supposed to be more precised. 69 | */ 70 | static bool MPDA_; 71 | /* 72 | *Histogram that contain the first chanel. 73 | */ 74 | std::vector ch1_; 75 | /* 76 | *Histogram that contain the first chanel. 77 | */ 78 | std::vector ch2_; 79 | /* 80 | *Histogram that contain the first chanel 81 | */ 82 | std::vector ch3_; 83 | /* 84 | *Used to know if the histograms are empty. 85 | */ 86 | bool isEmpty_; 87 | }; 88 | 89 | 90 | #endif //_SLHISTOGRAM3CH_H_ 91 | 92 | 93 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/include/slMedianContainer.h: -------------------------------------------------------------------------------- 1 | #ifndef _SLMEDIANCONTAINER_H_ 2 | #define _SLMEDIANCONTAINER_H_ 3 | 4 | 5 | #include 6 | 7 | 8 | using namespace std; 9 | 10 | 11 | #define MEDIAN_MIN_SIZE 1 12 | 13 | 14 | template 15 | class slMedianContainer 16 | { 17 | public: 18 | void resize(int size = MEDIAN_MIN_SIZE) 19 | { 20 | if (size >= MEDIAN_MIN_SIZE) 21 | { 22 | // Set the new size 23 | mSize = size; 24 | 25 | // Default mNbElements and next position 26 | mNbElements = 0; 27 | mNextInsPos = 0; 28 | 29 | // Resize vectors 30 | mIndex.resize(size); 31 | mValues.resize(size); 32 | } 33 | } 34 | 35 | inline const T& getMedian() const 36 | { 37 | return mValues[mIndex[mNbElements >> 1]]; 38 | } 39 | 40 | const slMedianContainer& operator+=(const T &value) 41 | { 42 | // Find the position of mNextInsPos in mIndex at the current state 43 | int indPos = getIndexPosition(); 44 | 45 | // Insert the new value at position mNextInsPos 46 | mValues[mNextInsPos] = value; 47 | 48 | // Count the new value if needed 49 | if (mNbElements < mSize) mNbElements++; 50 | 51 | // Bubble sort : going to 0 52 | while (indPos > 0 && value < mValues[mIndex[indPos - 1]]) 53 | { 54 | mIndex[indPos] = mIndex[indPos - 1]; 55 | indPos--; 56 | } 57 | 58 | // Bubble sort : going to mNbElements - 1 59 | while (indPos + 1 < mNbElements && value > mValues[mIndex[indPos + 1]]) 60 | { 61 | mIndex[indPos] = mIndex[indPos + 1]; 62 | indPos++; 63 | } 64 | 65 | // Update mIndex with mNextInsPos 66 | mIndex[indPos] = mNextInsPos; 67 | 68 | // Update mNextInsPos and loop to 0 if needed 69 | if (++mNextInsPos == mSize) mNextInsPos = 0; 70 | 71 | return *this; 72 | } 73 | 74 | private: 75 | int getIndexPosition() 76 | { 77 | if (mNbElements < mSize) 78 | { 79 | return mNbElements; 80 | } 81 | else 82 | { 83 | int indLower = 0; 84 | int indUpper = mSize; 85 | 86 | // Find the lower bound of the equivalent class 87 | while (indLower != indUpper) 88 | { 89 | int indPosit = (indLower + indUpper) >> 1; 90 | 91 | if (mValues[mIndex[indPosit]] < mValues[mNextInsPos]) 92 | { 93 | indLower = indPosit + 1; 94 | } 95 | else 96 | { 97 | indUpper = indPosit; 98 | } 99 | } 100 | 101 | // Find the position of mNextInsPos in mIndex 102 | while (mIndex[indLower] != mNextInsPos) 103 | { 104 | indLower++; 105 | } 106 | 107 | return indLower; 108 | } 109 | } 110 | 111 | private: 112 | int mSize; 113 | 114 | int mNbElements; 115 | int mNextInsPos; 116 | 117 | vector mIndex; // Sorted index pointing to values 118 | vector mValues; // Values 119 | 120 | }; 121 | 122 | 123 | #endif // _SLMEDIANCONTAINER_H_ 124 | 125 | 126 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/include/slQuantParams.h: -------------------------------------------------------------------------------- 1 | /*! \file slQuantParams.h 2 | * \brief Contains classes that quantify integers 3 | * 4 | * This file contains the definition of classes slQuant1ch and slQuant3ch 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date May 2011 8 | */ 9 | 10 | #ifndef _SLQUANTPARAMS_H_ 11 | #define _SLQUANTPARAMS_H_ 12 | 13 | 14 | #include 15 | 16 | #include "slArgHandler.h" 17 | #include "slCore.h" 18 | 19 | 20 | #define Q_MIN_LEVELS 2 //!< For binary images 21 | #define Q_H_LIMIT 180 //!< H (<180) 22 | #define Q_CHAN_LIMIT 256 //!< RGB and SV (<256) 23 | 24 | 25 | //! One channel integer quantifier 26 | /*! 27 | * This class can be used for 1-channel image quantification. 28 | * All that is needed to set is the number of levels (steps) and the limit 29 | * value (maximum allowed value plus 1). 30 | * For example, the default constructor creates 256 levels, one for each 31 | * possible value from 0 through 255. 32 | * 33 | * Internally, a lookup table (LUT) is built in order to match any given 34 | * unsigned 8-bit value to its corresponding output level. 35 | * The output levels are pre-scaled to [0, limit value[ and they are centered 36 | * in their level range. 37 | * For example, a quantifier of 3 levels over [0, 256[ would have output 38 | * values 42, 127 and 212. 39 | * 40 | * Since OpenCV typically uses 180 values for the H component of HSV pixels, it 41 | * is possible to create a quantifier of n levels, and set 180 as the limit value. 42 | * Even in that case, the LUT would be built with 255 input values, but a modulo 43 | * operator is applied: input value 180 has the same output value as 0, and so on. 44 | * 45 | * \see slQuant3ch, Q_CHAN_LIMIT, Q_H_LIMIT 46 | * \author Pier-Luc St-Onge 47 | * \date May 2011 48 | */ 49 | class SLCORE_DLL_EXPORT slQuant1ch 50 | { 51 | public: 52 | //! Default constructor (256 levels, <256) 53 | slQuant1ch(int nbLevels = Q_CHAN_LIMIT, int limitValue = Q_CHAN_LIMIT); 54 | 55 | //! Creates the lookup table 56 | void setParams(int nbLevels = Q_CHAN_LIMIT, int limitValue = Q_CHAN_LIMIT); 57 | 58 | // Compute methods 59 | void quantify(const slImage1ch &source, slImage1ch &target) const; //!< Quantifies a 1-channel image 60 | inline slPixel1ch operator[](const slPixel1ch pixel) const { return lut_[pixel]; } //!< Converts a value to its quantified level 61 | 62 | // Get methods 63 | inline int getNbLevels() const { return nbLevels_; } //!< Returns the number of quantification levels 64 | inline int getLimitValue() const { return limitValue_; } //!< Returns the limit value (255 or 180 typically) 65 | inline const slPixel1ch* getLUT() const { return &lut_[0]; } //!< Returns a pointer to the LUT, if needed 66 | 67 | private: 68 | int nbLevels_; 69 | int limitValue_; 70 | 71 | slPixel1ch lut_[Q_CHAN_LIMIT]; 72 | 73 | }; 74 | 75 | 76 | //! One channel integer quantifier 77 | /*! 78 | * This class can quantify 3-channel pixels by using three slQuant1ch 79 | * instances, one for each pixel component. 80 | * In other words, it uses 3 lookup tables (LUT). 81 | * 82 | * Here is an example of use for BGR images: 83 | * \code 84 | * slImage3ch bgrImage; 85 | * // ... 86 | * slQuant3ch quant(5, 9, 7); 87 | * quant.quantify(bgrImage, bgrImage); 88 | * \endcode 89 | * 90 | * Here is an example of use for HSV images: 91 | * \code 92 | * slImage3ch hsvImage; 93 | * // ... 94 | * quant.setParams(slQuant1ch(13, Q_H_LIMIT), 5, 9); 95 | * quant.quantify(hsvImage, hsvImage); 96 | * \endcode 97 | * 98 | * \see slQuant1ch, Q_CHAN_LIMIT, Q_H_LIMIT 99 | * \author Pier-Luc St-Onge 100 | * \date May 2011 101 | */ 102 | class SLCORE_DLL_EXPORT slQuant3ch 103 | { 104 | public: 105 | //! Default constructor (256, 256, 256) 106 | slQuant3ch(const slQuant1ch &q0 = slQuant1ch(), const slQuant1ch &q1 = slQuant1ch(), const slQuant1ch &q2 = slQuant1ch()); 107 | 108 | //! Sets the three quantifiers, the first one must be defined 109 | void setParams(const slQuant1ch &q0, const slQuant1ch &q1 = slQuant1ch(), const slQuant1ch &q2 = slQuant1ch()); 110 | 111 | // Compute methods 112 | void quantify(const slImage3ch &source, slImage3ch &target) const; //!< Quantifies a 3-channels image 113 | slPixel3ch operator[](const slPixel3ch &pixel) const; //!< Converts a pixel to its quantified levels 114 | 115 | // Get methods 116 | inline const slQuant1ch& getQ0() const { return q0_; } //!< Returns quantifier of the first component of pixels 117 | inline const slQuant1ch& getQ1() const { return q1_; } //!< Returns quantifier of the second component of pixels 118 | inline const slQuant1ch& getQ2() const { return q2_; } //!< Returns quantifier of the third component of pixels 119 | 120 | std::string getStr(typeColorSys csys) const; //!< Returns "nbLevels0 nbLevels1 nbLevels2" 121 | 122 | public: 123 | static slAH::slParamSpec& fillSyntax(slAH::slParamSpec& paramSpec); //!< Only fills the syntax of three arguments 124 | 125 | private: 126 | slQuant1ch q0_; 127 | slQuant1ch q1_; 128 | slQuant1ch q2_; 129 | 130 | }; 131 | 132 | 133 | #endif // _SLQUANTPARAMS_H_ 134 | 135 | 136 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/include/slRectPixels.h: -------------------------------------------------------------------------------- 1 | /*! \file slRectPixels.h 2 | * \brief Rectangle used in rectangle background subtractor 3 | * 4 | * \author Michael Sills Lavoie, Pier-Luc St-Onge 5 | * \date 23.05.2007 - February 2012 6 | */ 7 | 8 | #ifndef _SLRECTPIXELS_H_ 9 | #define _SLRECTPIXELS_H_ 10 | 11 | 12 | #include "slHistogram3ch.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | //! This struct contain the info about a level of slRectPixels. 20 | /*! 21 | * \see slRectSimple, slHistogram3ch 22 | * \author Michael Sills Lavoie 23 | * \date 23.05.2007 24 | */ 25 | struct slLevelStat 26 | { 27 | int RectangleHeight; 28 | int RectangleWidth; 29 | int numberOfRectangleX; 30 | int numberOfRectangleY; 31 | }; 32 | 33 | 34 | //! This struct contain the info about the texture of a slRectPixels. 35 | /*! 36 | * \see slRectSimple, slHistogram3ch 37 | * \author Michael Sills Lavoie, Pier-Luc St-Onge 38 | * \date 23.05.2007 - February 2012 39 | */ 40 | struct slTextureStat 41 | { 42 | float mean_; 43 | float var_; 44 | std::vector intensity_; 45 | }; 46 | 47 | 48 | //! slRectPixels used to store the histogram and other information. 49 | /*! 50 | * This class is used to seperate a frame into slRectPixels. 51 | * A frame is composed of a set number of level of slRectPixels. 52 | * The lower is a level, the bigger is the number of slRectPixels that it contain. 53 | * 54 | * \see slRectSimple, slHistogram3ch 55 | * \author Michael Sills Lavoie 56 | * \date 23.05.2007 57 | */ 58 | class SLCORE_DLL_EXPORT slRectPixels 59 | { 60 | public: 61 | slRectPixels(int coordX, int coordY, bool isLowestLevel, int dimX, int dimY); //!< Constructor 62 | ~slRectPixels(); //!< Destructor 63 | 64 | void addLink(slRectPixels* rect1, slRectPixels* rect2, slRectPixels* rect3, slRectPixels* rect4); //!< Add four sub-rectangle-pixels 65 | void addExternalLink(slRectPixels* rect); //!< Add other link betwen two slRectPixels 66 | 67 | void update(const slImage3ch &data, const slImage3ch &dataB); //!< Update the histograms and the textures... 68 | 69 | void clearData(void); //!< Reset object 70 | 71 | void compareRectangle (float th, float deltath, float thTexture, float dthTexture); //!< Decides if background or not 72 | 73 | void setBackground (bool isBack); //!< Force background 74 | bool getBackground (void) const; //!< Returns true if background 75 | 76 | slHistogram3ch& getHistogram (void); //!< Returns foreground's histogram 77 | slHistogram3ch& getHistogramB (void); //!< Returns background's histogram 78 | 79 | int getCoordX (void) const; //!< X offset in image 80 | int getCoordY (void) const; //!< Y offset in image 81 | int getDimX (void) const; //!< Width 82 | int getDimY (void) const; //!< Height 83 | 84 | static void setTexture (bool useTexture); //!< Force the use of textures 85 | 86 | private: 87 | 88 | int coordX_; 89 | /* 90 | * The y coord of the top left corner of the slRectPixels in the image 91 | */ 92 | int coordY_; 93 | /* 94 | * The x dimention of the slRectPixels (in pixel) 95 | */ 96 | int dimX_; 97 | /* 98 | * The y dimention of the slRectPixels (in pixel) 99 | */ 100 | int dimY_; 101 | /* 102 | * The variance of intensity in this rectangle + 103 | * The intensity vector for this rectangle for the foreground data 104 | */ 105 | slTextureStat texture_; 106 | /* 107 | * The variance of intensity in this rectangle + 108 | * The intensity vector for this rectangle for the background data 109 | */ 110 | slTextureStat textureB_; 111 | /* 112 | * The histogram of this slRectPixels for the foreground data 113 | */ 114 | slHistogram3ch histogram_; 115 | /* 116 | * The histogram of this slRectPixels for the background data 117 | */ 118 | slHistogram3ch histogramB_; 119 | /* 120 | * A vector of pointers to the small slRectPixels contained in this slRectPixels. 121 | * (only a level lower) 122 | */ 123 | std::vector contain_; 124 | /* 125 | * A vector of pointers to the small slRectPixels that are at the border of this slRectPixels. 126 | * (only a level lower) 127 | */ 128 | std::vector external_; 129 | /* 130 | * True if the slRectPixels is at the lowest level (contain no other slRectPixels 131 | */ 132 | bool isLowestLevel_; 133 | /* 134 | * True if this slRectPixels is in the background (no moving object detected) 135 | */ 136 | bool isBackground_; 137 | /* 138 | * True if this slRectPixels have already been checked (in the same loop) 139 | */ 140 | bool isChecked_; 141 | /* 142 | * True if we use the texture 143 | */ 144 | static bool useTexture_; 145 | }; 146 | 147 | 148 | #endif //_SLRECTPIXELS_H_ 149 | 150 | 151 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/include/slWindow.h: -------------------------------------------------------------------------------- 1 | /*! \file slWindow.h 2 | * \brief Contains a class managing an OpenCV window 3 | * 4 | * This file contains the definition of the class slWindow. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date 14/06/2010 8 | */ 9 | 10 | #ifndef SLWINDOW_H 11 | #define SLWINDOW_H 12 | 13 | 14 | #include "slCore.h" 15 | 16 | 17 | //! This is the class used for showing slImage objects 18 | /*! 19 | * As soon as a slWindow is created with a provided text, this text is 20 | * formatted in order to create a unique window name (caption text). 21 | * In fact, if several slWindow instances are created with the same input 22 | * text, the resulting caption text will be "text (ID)". 23 | * So, the window is created with the appropriate OpenCV function and with 24 | * the caption text. 25 | * Finally, the window will be destroyed when the corresponding slWindow 26 | * will be destroyed too. 27 | * 28 | * To show an image, simply call function show(). 29 | * 30 | * Mouse events could be managed by creating a class that derivates from slWindow. 31 | * By reimplementing mouseEvent(), it is then possible to catch all mouse 32 | * events detected by OpenCV. Example: 33 | * \code 34 | * class ClickMe: public slWindow 35 | * { 36 | * public: 37 | * ClickMe(const char *text): slWindow(text), image_(imread("test.png")) 38 | * { 39 | * show(image_); // Show image test.png 40 | * } 41 | * 42 | * protected: 43 | * virtual void mouseEvent(int cvEvent, int x, int y, int eventFlags) 44 | * { 45 | * if (cvEvent == CV_EVENT_LBUTTONUP) { // Left click 46 | * // Print orange circle at mouse position 47 | * circle(image_, cvPoint(x, y), 16, CV_RGB(255, 128, 0), -1); 48 | * show(image_); // Show modified image 49 | * } 50 | * } 51 | * 52 | * private: 53 | * slImage3ch image_; 54 | * 55 | * }; 56 | * \endcode 57 | * 58 | * \see slImage3ch, slImage1ch 59 | * \author Pier-Luc St-Onge 60 | * \date 15/04/2011 61 | */ 62 | class SLCORE_DLL_EXPORT slWindow 63 | { 64 | public: 65 | slWindow(const char *text); //!< Constructor with the unformatted caption text 66 | slWindow(const slWindow& c); 67 | 68 | virtual ~slWindow(); //!< Virtual destructor 69 | 70 | slWindow& operator=(const slWindow& c); 71 | 72 | void show(const slMat& image, typeColorSys csys = SL_BGR); //!< Shows an image, manual call 73 | 74 | protected: 75 | //! Receives the mouse events and sends a signal if needed 76 | virtual void mouseEvent(int cvEvent, int x, int y, int eventFlags); 77 | 78 | static void mouseCallback(int cvEvent, int x, int y, int eventFlags, void* window); 79 | 80 | private: 81 | slWindow(); 82 | 83 | std::string generateCaption(const std::string& text) const; 84 | 85 | private: 86 | std::string text_; 87 | std::string caption_; 88 | 89 | static std::map *indexes_; 90 | 91 | }; 92 | 93 | 94 | #endif // SLWINDOW_H 95 | 96 | 97 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/slCore.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/src/slClock.cpp: -------------------------------------------------------------------------------- 1 | #include "slClock.h" 2 | 3 | 4 | slClock::slClock(double period) 5 | { 6 | setPeriod(period); 7 | start(); 8 | } 9 | 10 | 11 | slClock::~slClock() 12 | { 13 | } 14 | 15 | 16 | void slClock::setFPS(double fps) 17 | { 18 | setPeriod(1.0 / fps); 19 | } 20 | 21 | 22 | void slClock::setPeriod(double period) 23 | { 24 | periodInClocks_ = period * CLOCKS_PER_SEC; 25 | } 26 | 27 | 28 | void slClock::start() 29 | { 30 | stop(); 31 | nbFrames_ = 0; 32 | 33 | startTime_ = clock(); 34 | } 35 | 36 | 37 | clock_t slClock::nextDelay() 38 | { 39 | stop(); 40 | nbFrames_++; 41 | 42 | clock_t delay = (clock_t)floor(periodInClocks_ * nbFrames_) - elapsed(); 43 | return (delay > 0 ? delay : 1); 44 | } 45 | 46 | 47 | void slClock::stop() 48 | { 49 | stopTime_ = clock(); 50 | } 51 | 52 | 53 | clock_t slClock::elapsed() const 54 | { 55 | return (stopTime_ - startTime_ + 1); 56 | } 57 | 58 | 59 | unsigned int slClock::nbFrames() const 60 | { 61 | return nbFrames_; 62 | } 63 | 64 | 65 | double slClock::getMeasuredFPS() const 66 | { 67 | double nb = (nbFrames_ > 0 ? nbFrames_ : 1); 68 | clock_t temps = elapsed(); 69 | temps = (temps > 0 ? temps : 1); 70 | 71 | return nb * CLOCKS_PER_SEC / temps; 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/src/slContours.cpp: -------------------------------------------------------------------------------- 1 | #include "slContours.h" 2 | 3 | 4 | using namespace cv; 5 | 6 | 7 | enum Direction {NEXT, PREVIOUS, CHILD, PARENT}; 8 | 9 | 10 | slContours::slContours() 11 | { 12 | } 13 | 14 | slContours::slContours(const slContour &contour) 15 | { 16 | contours_.push_back(contour); 17 | hierarchy_.push_back(Vec4i(-1, -1, -1, -1)); 18 | } 19 | 20 | 21 | void slContours::clear() 22 | { 23 | contours_.clear(); 24 | hierarchy_.clear(); 25 | } 26 | 27 | 28 | void slContours::findAll(slImage1ch &image) 29 | { 30 | clear(); 31 | cv::findContours(image, contours_, hierarchy_, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE); 32 | } 33 | 34 | 35 | slContours::iterator slContours::begin() 36 | { 37 | return slContours_iterator(this, hierarchy_.size() > 0 ? 0 : -1); 38 | } 39 | 40 | slContours::const_iterator slContours::begin() const 41 | { 42 | return slContours_const_iterator(this, hierarchy_.size() > 0 ? 0 : -1); 43 | } 44 | 45 | 46 | slContours_iterator::slContours_iterator(slContours *ref, int index) 47 | : ref_(ref), index_(index) 48 | { 49 | } 50 | 51 | slContours_const_iterator::slContours_const_iterator(const slContours *ref, int index) 52 | : ref_(ref), index_(index) 53 | { 54 | } 55 | 56 | slContours_const_iterator::slContours_const_iterator(const slContours_iterator &it) 57 | : ref_(it.ref_), index_(it.index_) 58 | { 59 | } 60 | 61 | 62 | slContours_iterator slContours_iterator::next() const 63 | { 64 | return slContours_iterator(ref_, ref_->hierarchy_[index_][NEXT]); 65 | } 66 | 67 | slContours_const_iterator slContours_const_iterator::next() const 68 | { 69 | return slContours_const_iterator(ref_, ref_->hierarchy_[index_][NEXT]); 70 | } 71 | 72 | 73 | slContours_iterator slContours_iterator::previous() const 74 | { 75 | return slContours_iterator(ref_, ref_->hierarchy_[index_][PREVIOUS]); 76 | } 77 | 78 | slContours_const_iterator slContours_const_iterator::previous() const 79 | { 80 | return slContours_const_iterator(ref_, ref_->hierarchy_[index_][PREVIOUS]); 81 | } 82 | 83 | 84 | slContours_iterator slContours_iterator::child() const 85 | { 86 | return slContours_iterator(ref_, ref_->hierarchy_[index_][CHILD]); 87 | } 88 | 89 | slContours_const_iterator slContours_const_iterator::child() const 90 | { 91 | return slContours_const_iterator(ref_, ref_->hierarchy_[index_][CHILD]); 92 | } 93 | 94 | 95 | slContours_iterator slContours_iterator::parent() const 96 | { 97 | return slContours_iterator(ref_, ref_->hierarchy_[index_][PARENT]); 98 | } 99 | 100 | slContours_const_iterator slContours_const_iterator::parent() const 101 | { 102 | return slContours_const_iterator(ref_, ref_->hierarchy_[index_][PARENT]); 103 | } 104 | 105 | 106 | bool slContours_iterator::isNull() const 107 | { 108 | return (index_ < 0 || ref_ == NULL); 109 | } 110 | 111 | bool slContours_const_iterator::isNull() const 112 | { 113 | return (index_ < 0 || ref_ == NULL); 114 | } 115 | 116 | 117 | cv::Mat slContours_iterator::mat() 118 | { 119 | return Mat(ref_->contours_[index_]); 120 | } 121 | 122 | const cv::Mat slContours_const_iterator::mat() const 123 | { 124 | return Mat(ref_->contours_[index_]); 125 | } 126 | 127 | 128 | slContour& slContours_iterator::operator*() 129 | { 130 | return ref_->contours_[index_]; 131 | } 132 | 133 | const slContour& slContours_const_iterator::operator*() const 134 | { 135 | return ref_->contours_[index_]; 136 | } 137 | 138 | 139 | slContour* slContours_iterator::operator->() 140 | { 141 | return &ref_->contours_[index_]; 142 | } 143 | 144 | const slContour* slContours_const_iterator::operator->() const 145 | { 146 | return &ref_->contours_[index_]; 147 | } 148 | 149 | 150 | bool slContours_iterator::operator<(const slContours_iterator &it) const 151 | { 152 | return (index_ < it.index_ || (index_ == it.index_ && ref_ < it.ref_)); 153 | } 154 | 155 | bool slContours_const_iterator::operator<(const slContours_const_iterator &it) const 156 | { 157 | return (index_ < it.index_ || (index_ == it.index_ && ref_ < it.ref_)); 158 | } 159 | 160 | 161 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/src/slCore.cpp: -------------------------------------------------------------------------------- 1 | #include "slCore.h" 2 | 3 | 4 | #ifdef WIN32 5 | #include 6 | 7 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved) 8 | { 9 | return TRUE; 10 | } 11 | #endif // WIN32 12 | 13 | 14 | slImage1ch grayClone(const slImage3ch &image, typeColorSys csys) 15 | { 16 | slImage1ch tmp; 17 | 18 | if (csys == SL_BGR) { 19 | // BGR to gray 20 | cvtColor(image, tmp, CV_BGR2GRAY); 21 | } 22 | else { 23 | // HSV to V (gray) 24 | slImage1ch hsv[3]; 25 | split(image, &hsv[0]); 26 | tmp = hsv[2]; 27 | } 28 | 29 | return tmp; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/src/slException.cpp: -------------------------------------------------------------------------------- 1 | #include "slException.h" 2 | 3 | 4 | using namespace std; 5 | 6 | 7 | #define SL_ERR_MESSAGE_SIZE 255 8 | #define SL_CLASS_NAME_SIZE 50 9 | 10 | 11 | slException::slException(const char* error, const char* name): 12 | err_(new char[SL_ERR_MESSAGE_SIZE]), name_(new char[SL_CLASS_NAME_SIZE]) 13 | { 14 | *err_ = 0; 15 | strcat_s(err_, SL_ERR_MESSAGE_SIZE, error); 16 | 17 | *name_ = 0; 18 | if (name != NULL) strcat_s(name_, SL_CLASS_NAME_SIZE, name); 19 | } 20 | 21 | 22 | slException::~slException() 23 | { 24 | delete [] err_; 25 | delete [] name_; 26 | } 27 | 28 | 29 | /**************************************************************************** 30 | * Description : Constructor with parameters 31 | * Parameters : - name (string): the name of the sample 32 | * Return value : No 33 | ***************************************************************************/ 34 | slExceptionArgHandler::slExceptionArgHandler(const std::string& error) 35 | : slException(error.c_str(), "slArgHandler") 36 | { 37 | } 38 | 39 | 40 | /**************************************************************************** 41 | * Description : Constructor with parameters 42 | * Parameters : - name (string): the name of the sample 43 | * Return value : No 44 | ***************************************************************************/ 45 | slExceptionIO::slExceptionIO(const std::string& error) 46 | : slException(error.c_str(), "slIO") 47 | { 48 | }; 49 | 50 | 51 | /**************************************************************************** 52 | * Description : Constructor with parameters 53 | * Parameters : - name (string): the name of the sample 54 | * Return value : No 55 | ***************************************************************************/ 56 | slExceptionCamIn::slExceptionCamIn(const std::string& error) 57 | : slExceptionIO(error) 58 | { 59 | strcat_s(name_, SL_CLASS_NAME_SIZE, " (Camera issue)"); 60 | }; 61 | 62 | 63 | /**************************************************************************** 64 | * Description : Constructor with parameters 65 | * Parameters : - name (string): the name of the sample 66 | * Return value : No 67 | ***************************************************************************/ 68 | slExceptionBgSub::slExceptionBgSub(const std::string& error) 69 | : slException(error.c_str(), "slBgSub") 70 | { 71 | } 72 | 73 | 74 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/src/slQuantParams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "slQuantParams.h" 5 | 6 | 7 | using namespace cv; 8 | using namespace std; 9 | using namespace slAH; 10 | 11 | 12 | //////////////// 13 | // slQuant1ch // 14 | //////////////// 15 | 16 | 17 | slQuant1ch::slQuant1ch(int nbLevels, int limitValue) 18 | { 19 | setParams(nbLevels, limitValue); 20 | } 21 | 22 | 23 | void slQuant1ch::setParams(int nbLevels, int limitValue) 24 | { 25 | limitValue_ = limitValue; 26 | nbLevels_ = nbLevels; 27 | 28 | // Q_MIN_LEVELS <= limitValue_ <= Q_CHAN_LIMIT 29 | if (limitValue_ < Q_MIN_LEVELS) limitValue_ = Q_MIN_LEVELS; 30 | if (limitValue_ > Q_CHAN_LIMIT) limitValue_ = Q_CHAN_LIMIT; 31 | 32 | // Q_MIN_LEVELS <= nbLevels_ <= limitValue_ 33 | if (nbLevels_ < Q_MIN_LEVELS) nbLevels_ = Q_MIN_LEVELS; 34 | if (nbLevels_ > limitValue_) nbLevels_ = limitValue_; 35 | 36 | double step = (double)limitValue_ / nbLevels_; 37 | slPixel1ch offset = (slPixel1ch)(int)floor(step / 2); 38 | 39 | // Compute all values of lut_ 40 | for (int ind = 0; ind < Q_CHAN_LIMIT; ind++) { 41 | lut_[ind] = (slPixel1ch)(int)( step * floor((ind % limitValue_) / step) ) + offset; 42 | } 43 | } 44 | 45 | 46 | void slQuant1ch::quantify(const slImage1ch &source, slImage1ch &target) const 47 | { 48 | if (source.empty() || target.empty()) return; 49 | 50 | if (source.rows != target.rows || source.cols != target.cols) { 51 | target.create(source.size()); 52 | } 53 | 54 | for (int i = 0; i < source.rows; i++) { 55 | const slPixel1ch *src = source[i]; 56 | slPixel1ch *tgt = target[i]; 57 | 58 | for (int j = 0; j < source.cols; j++) { 59 | tgt[j] = lut_[src[j]]; 60 | } 61 | } 62 | } 63 | 64 | 65 | //////////////// 66 | // slQuant3ch // 67 | //////////////// 68 | 69 | 70 | slQuant3ch::slQuant3ch(const slQuant1ch &q0, const slQuant1ch &q1, const slQuant1ch &q2): 71 | q0_(q0), 72 | q1_(q1), 73 | q2_(q2) 74 | { 75 | } 76 | 77 | 78 | void slQuant3ch::setParams(const slQuant1ch &q0, const slQuant1ch &q1, const slQuant1ch &q2) 79 | { 80 | q0_ = q0; 81 | q1_ = q1; 82 | q2_ = q2; 83 | } 84 | 85 | 86 | void slQuant3ch::quantify(const slImage3ch &source, slImage3ch &target) const 87 | { 88 | if (source.empty() || target.empty()) return; 89 | 90 | if (source.rows != target.rows || source.cols != target.cols) { 91 | target.create(source.size()); 92 | } 93 | 94 | const slPixel1ch *q0 = q0_.getLUT(); 95 | const slPixel1ch *q1 = q1_.getLUT(); 96 | const slPixel1ch *q2 = q2_.getLUT(); 97 | 98 | for (int i = 0; i < source.rows; i++) { 99 | const slPixel3ch *src = source[i]; 100 | slPixel3ch *tgt = target[i]; 101 | 102 | for (int j = 0; j < source.cols; j++) { 103 | tgt[j] = slPixel3ch( q0[src[j].val[0]], q1[src[j].val[1]], q2[src[j].val[2]] ); 104 | } 105 | } 106 | } 107 | 108 | 109 | slPixel3ch slQuant3ch::operator[](const slPixel3ch &pixel) const 110 | { 111 | return slPixel3ch(q0_[pixel.val[0]], q1_[pixel.val[1]], q2_[pixel.val[2]]); 112 | } 113 | 114 | 115 | string slQuant3ch::getStr(typeColorSys csys) const 116 | { 117 | ostringstream ostr; 118 | 119 | ostr << q0_.getNbLevels() << " " << q1_.getNbLevels() << " " << q2_.getNbLevels(); 120 | 121 | return ostr.str(); 122 | } 123 | 124 | 125 | slParamSpec& slQuant3ch::fillSyntax(slParamSpec& paramSpec) 126 | { 127 | { 128 | ostringstream ostr; 129 | ostr << Q_MIN_LEVELS << ".." << "(" << Q_CHAN_LIMIT << "|" << Q_H_LIMIT << ")"; 130 | paramSpec << slSyntax(ostr.str()); 131 | } 132 | 133 | { 134 | ostringstream ostr; 135 | ostr << Q_MIN_LEVELS << ".." << Q_CHAN_LIMIT; 136 | paramSpec << slSyntax(ostr.str()); 137 | } 138 | 139 | { 140 | ostringstream ostr; 141 | ostr << Q_MIN_LEVELS << ".." << Q_CHAN_LIMIT; 142 | paramSpec << slSyntax(ostr.str()); 143 | } 144 | 145 | return paramSpec; 146 | } 147 | 148 | 149 | -------------------------------------------------------------------------------- /SDK_LITIV/slCore/src/slWindow.cpp: -------------------------------------------------------------------------------- 1 | /*! \file slWindow.cpp 2 | * \brief Contains a class managing an OpenCV window 3 | * 4 | * This file contains the implementation of the class slWindow. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date 14/06/2010 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "slWindow.h" 14 | 15 | 16 | using namespace cv; 17 | using namespace std; 18 | 19 | 20 | map *slWindow::indexes_ = NULL; 21 | 22 | 23 | /*! 24 | * This function calls \c cv::namedWindow() to create the window. 25 | * If another window has already the same input text, a unique id 26 | * is appended to \c text: text (id). 27 | * 28 | * Finally, all mouse events are set to be received. 29 | * 30 | * \param text is the title of the window. 31 | * Examples: Output, Foreground, etc. 32 | */ 33 | slWindow::slWindow(const char *text) 34 | : text_(text), caption_(generateCaption(text_)) 35 | { 36 | namedWindow(caption_); 37 | setMouseCallback(caption_, mouseCallback, this); 38 | } 39 | 40 | 41 | slWindow::slWindow(const slWindow& c) 42 | : text_(c.text_), caption_(generateCaption(text_)) 43 | { 44 | namedWindow(caption_); 45 | setMouseCallback(caption_, mouseCallback, this); 46 | } 47 | 48 | 49 | slWindow::~slWindow() 50 | { 51 | destroyWindow(caption_); 52 | } 53 | 54 | 55 | slWindow& slWindow::operator=(const slWindow& c) 56 | { 57 | if (this != &c) { 58 | destroyWindow(caption_); 59 | text_ = c.text_; 60 | caption_ = generateCaption(text_); 61 | namedWindow(caption_); 62 | } 63 | 64 | return *this; 65 | } 66 | 67 | 68 | void slWindow::show(const slMat& image, typeColorSys csys) 69 | { 70 | if (!image.empty()) { 71 | if (csys != SL_HSV) { 72 | imshow(caption_, image); 73 | } 74 | else { 75 | slMat tmp; 76 | 77 | cvtColor(image, tmp, CV_HSV2BGR); 78 | imshow(caption_, tmp); 79 | } 80 | } 81 | } 82 | 83 | 84 | void slWindow::mouseCallback(int cvEvent, int x, int y, int eventFlags, void* window) 85 | { 86 | if (window != NULL) { 87 | ((slWindow*)window)->mouseEvent(cvEvent, x, y, eventFlags); 88 | } 89 | } 90 | 91 | 92 | void slWindow::mouseEvent(int cvEvent, int x, int y, int eventFlags) 93 | { 94 | // Do nothing by default 95 | } 96 | 97 | 98 | string slWindow::generateCaption(const std::string& text) const 99 | { 100 | if (indexes_ == NULL) { 101 | indexes_ = new map; 102 | } 103 | 104 | if (indexes_->find(text) == indexes_->end()) { 105 | (*indexes_)[text] = 0; 106 | } 107 | 108 | unsigned int id = ++((*indexes_)[text]); 109 | 110 | ostringstream oss; 111 | 112 | oss << text; 113 | 114 | if (id > 1) { 115 | oss << " (" << id << ")"; 116 | } 117 | 118 | return oss.str(); 119 | } 120 | 121 | 122 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/include/slIO.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | FILE : slIO.h 3 | AUTHOR : Michael Eilers-Smith 4 | CREATED : June 2008 5 | DESCRIPTION : Interface for the use of the slIO server. 6 | ******************************************************************************/ 7 | 8 | #ifndef _SLIO_H 9 | #define _SLIO_H 10 | 11 | 12 | #ifndef SLIO_DLL_EXPORT 13 | #ifdef WIN32 14 | #define SLIO_DLL_EXPORT __declspec(dllexport) 15 | #else 16 | #define SLIO_DLL_EXPORT 17 | #endif 18 | #endif 19 | 20 | 21 | #include "slCore.h" 22 | #include "slException.h" 23 | 24 | 25 | #endif // _SLIO_H 26 | 27 | 28 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/include/slImageIn.h: -------------------------------------------------------------------------------- 1 | /*! \file slImageIn.h 2 | * \brief Contains a class that loads an image from a file 3 | * 4 | * This file contains the definition of the class slImageIn. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date August 2010 8 | */ 9 | 10 | #ifndef SLIMAGEIN_H 11 | #define SLIMAGEIN_H 12 | 13 | 14 | #include "slIn.h" 15 | 16 | 17 | //! Class used to load a slImage3ch (or Mat) object from a file 18 | /*! 19 | * Example: 20 | * \code 21 | * slImage3ch image; 22 | * slImageIn().open("test.png").read(image); 23 | * \endcode 24 | * 25 | * It is also possible to read a sequence of images: 26 | * \code 27 | * slImageIn imageIn("output%04d.png", 1); 28 | * 29 | * imageIn.read(image); // loads output0001.png 30 | * imageIn.read(image); // loads output0002.png 31 | * \endcode 32 | * 33 | * \see slIn, slImageOut, slVideoIn, slVideoOut 34 | * \author Pier-Luc St-Onge 35 | * \date August 2010 36 | */ 37 | class SLIO_DLL_EXPORT slImageIn: public slIn 38 | { 39 | public: 40 | slImageIn(const std::string &filename_format = "", int index = 0); //!< Constructor, sets filename format and first index 41 | virtual ~slImageIn(); 42 | 43 | slImageIn& open(const std::string &filename_format); //!< Sets a new filename format and loads image attributes 44 | void read(slMat &image); //!< Loads one image 45 | void close(); //!< Clears the filename format and resets index to 0 46 | 47 | slImageIn& setFormat(const std::string &filename_format); //!< Sets the filename format 48 | slImageIn& setIndex(int index); //!< Sets the first index 49 | 50 | private: 51 | std::string format_; 52 | int index_; 53 | 54 | }; 55 | 56 | 57 | #endif // SLIMAGEIN_H 58 | 59 | 60 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/include/slImageOut.h: -------------------------------------------------------------------------------- 1 | /*! \file slImageOut.h 2 | * \brief Contains a class for saving images 3 | * 4 | * This file contains the definition of the class slImageOut. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date August 2010 8 | */ 9 | 10 | #ifndef SLIMAGEOUT_H 11 | #define SLIMAGEOUT_H 12 | 13 | 14 | #include "slOut.h" 15 | 16 | 17 | //! This is the class used to save images 18 | /*! 19 | * It is possible to save an image manually: 20 | * \code 21 | * slImageOut("output.png").write(slImage3ch(cvSize(320, 240))); 22 | * \endcode 23 | * 24 | * This class can also be used to save sequences of images. The filename 25 | * format follows the rules of function \c printf(). An index (32 bits 26 | * integer) is used to create a different file for each image. 27 | * \code 28 | * slImage3ch image(cvSize(320, 240)); 29 | * slImageOut imageOut("output%04d.png", 1); 30 | * 31 | * imageOut.write(image); // creates output0001.png 32 | * image = slRGB(255, 0, 0); 33 | * imageOut.write(image); // creates output0002.png 34 | * \endcode 35 | * 36 | * \see slOut, slImageIn, slVideoOut, slVideoIn 37 | * \author Pier-Luc St-Onge 38 | * \date August 2010 39 | */ 40 | class SLIO_DLL_EXPORT slImageOut: public slOut 41 | { 42 | public: 43 | slImageOut(const std::string &filename_format = "", int index = 0); //!< Constructor, sets filename format and first index 44 | virtual ~slImageOut(); 45 | 46 | slImageOut& open(const std::string &filename_format); //!< Sets the filename format 47 | void write(const slMat &image); //!< Saves one image 48 | void close(); //!< Clears the filename format and resets index to 0 49 | 50 | slImageOut& setFormat(const std::string &filename_format); //!< Sets the filename format 51 | slImageOut& setIndex(int index); //!< Sets the first index 52 | 53 | private: 54 | std::string format_; 55 | int index_; 56 | 57 | }; 58 | 59 | 60 | #endif // SLIMAGEOUT_H 61 | 62 | 63 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/include/slIn.h: -------------------------------------------------------------------------------- 1 | /*! \file slIn.h 2 | * \brief Contains an abstract class for image sources 3 | * 4 | * This file contains the definition of the class slIn. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date April 2010 8 | */ 9 | 10 | #ifndef SLIN_H 11 | #define SLIN_H 12 | 13 | 14 | #include "slIO.h" 15 | 16 | 17 | //! Base class for all image sources 18 | /*! 19 | * This class gives a basic common interface for image sources like slImageIn 20 | * and slVideoIn. 21 | * With function read(slMat &), it is possible to load one image at a time. 22 | * 23 | * \see slImageIn, slVideoIn, slOut 24 | * \author Pier-Luc St-Onge 25 | * \date April 2010 26 | */ 27 | class SLIO_DLL_EXPORT slIn 28 | { 29 | public: 30 | slIn(); 31 | virtual ~slIn(); 32 | 33 | virtual slIn& open(const std::string &name) = 0; //!< Opens a video or a camera connection 34 | virtual void read(slMat &image) = 0; //!< Reads the next image from a video or the image file 35 | virtual void close() = 0; //!< Closes a video file or a camera connection 36 | 37 | double getFPS() const; //!< Returns number of frames per second 38 | int getHeight() const; //!< Returns image(s) height 39 | unsigned int getNbImages() const; //!< Returns number of images 40 | cv::Size getSize() const; //!< Returns image(s) size 41 | int getWidth() const; //!< Returns image(s) width 42 | 43 | protected: 44 | void resetSpecs(); 45 | 46 | protected: 47 | int width_; 48 | int height_; 49 | 50 | double fps_; 51 | unsigned int nbImages_; 52 | 53 | }; 54 | 55 | 56 | #endif // SLIN_H 57 | 58 | 59 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/include/slOut.h: -------------------------------------------------------------------------------- 1 | /*! \file slOut.h 2 | * \brief Contains an abstract class for saving images as images or videos 3 | * 4 | * This file contains the definition of the class slOut. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date June 2010 8 | */ 9 | 10 | #ifndef SLOUT_H 11 | #define SLOUT_H 12 | 13 | 14 | #include "slIO.h" 15 | 16 | 17 | //! Abstract class for saving images 18 | /*! 19 | * This class gives a basic common interface for slImageOut and slVideoOut. 20 | * With function write(const slMat &), it is possible to save one image at a time. 21 | * 22 | * \see slImageOut, slVideoOut, slIn 23 | * \author Pier-Luc St-Onge 24 | * \date June 2010 25 | */ 26 | class SLIO_DLL_EXPORT slOut 27 | { 28 | public: 29 | slOut(); 30 | virtual ~slOut(); 31 | 32 | virtual slOut& open(const std::string &name) = 0; //!< Opens target file 33 | virtual void write(const slMat &image) = 0; //!< Saves one image 34 | virtual void close() = 0; //!< Close any opened file 35 | 36 | }; 37 | 38 | 39 | #endif // SLOUT_H 40 | 41 | 42 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/include/slVideoIn.h: -------------------------------------------------------------------------------- 1 | /*! \file slVideoIn.h 2 | * \brief Contains a class for loading videos 3 | * 4 | * This file contains the definition of the class slVideoIn. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date April 2010 8 | */ 9 | 10 | #ifndef SLVIDEOIN_H 11 | #define SLVIDEOIN_H 12 | 13 | 14 | #include "slIn.h" 15 | 16 | 17 | //! Class used to load one frame at a time from a video file 18 | /*! 19 | * This is the class used to load videos and get access to one frame after the 20 | * other. 21 | * Example: 22 | * \code 23 | * slMat image; 24 | * slWindow monitor("Monitor"); 25 | * 26 | * slVideoIn video; 27 | * video.open("video1.avi"); 28 | * 29 | * slClock myClock; 30 | * myClock.setFPS(video.getFPS()); 31 | * myClock.start(); 32 | * 33 | * for (unsigned i = 0; i < video.getNbImages(); i++) { 34 | * video.read(image); 35 | * if (image.empty()) throw slExceptionIO("First image is empty"); 36 | * 37 | * monitor.show(image); 38 | * if (waitKey(myClock.nextDelay()) != -1) throw slExceptionIO("Problem in video playback"); 39 | * } 40 | * 41 | * myClock.stop(); 42 | * video.close(); 43 | * \endcode 44 | * 45 | * \see slIn, slVideoOut, slImageIn, slImageOut 46 | * \author Pier-Luc St-Onge 47 | * \date April 2010 48 | */ 49 | class SLIO_DLL_EXPORT slVideoIn: public slIn 50 | { 51 | public: 52 | slVideoIn(); //!< Constructor 53 | virtual ~slVideoIn(); 54 | 55 | slVideoIn& open(const std::string &name); //!< Opens the video file 56 | void read(slMat &image); //!< Reads next frame from video file 57 | void close(); //!< Closes video file 58 | 59 | private: 60 | void releaseCapture(); 61 | 62 | private: 63 | cv::VideoCapture *capture_; 64 | 65 | }; 66 | 67 | 68 | #endif // SLVIDEOIN_H 69 | 70 | 71 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/include/slVideoOut.h: -------------------------------------------------------------------------------- 1 | /*! \file slVideoOut.h 2 | * \brief Contains a class for saving videos 3 | * 4 | * This file contains the definition of the class slVideoOut. 5 | * 6 | * \author Pier-Luc St-Onge 7 | * \date June 2010 8 | */ 9 | 10 | #ifndef SLVIDEOOUT_H 11 | #define SLVIDEOOUT_H 12 | 13 | 14 | #include "slOut.h" 15 | 16 | 17 | //! Opens a file, saves images and closes the file 18 | /*! 19 | * This is the class used to save videos. 20 | * Example: 21 | * \code 22 | * slWindow monitor("Monitor"); 23 | * 24 | * slVideoIn videoReader; 25 | * videoReader.open("video1.avi"); 26 | * 27 | * slImage3ch inputImage, outputImage; 28 | * const Size size(320, 240); 29 | * 30 | * slVideoOut videoWriter; 31 | * videoWriter.setFPS(videoReader.getFPS()); 32 | * videoWriter.setSize(size); 33 | * videoWriter.open("output.avi"); 34 | * 35 | * for (unsigned i = 0; i < videoReader.getNbImages(); i++) { 36 | * videoReader.read(inputImage); 37 | * resize(inputImage, outputImage, size); 38 | * videoWriter.write(outputImage); 39 | * 40 | * monitor.show(outputImage); 41 | * if (waitKey(33) != -1) throw slExceptionIO("Problem in video recording"); 42 | * } 43 | * 44 | * videoWriter.close(); 45 | * videoReader.close(); 46 | * \endcode 47 | * 48 | * \see slOut, slVideoIn, slImageOut, slImageIn 49 | * \author Pier-Luc St-Onge 50 | * \date June 2010 51 | */ 52 | class SLIO_DLL_EXPORT slVideoOut: public slOut 53 | { 54 | public: 55 | slVideoOut(); // Constructor 56 | virtual ~slVideoOut(); 57 | 58 | void setCodec(int fourcc = -1); //!< When FOURCC is -1, a popup list shows all available codecs 59 | void setFPS(double fps); //!< To set the frame rate of the video 60 | void setIsColor(bool isColor = true); //!< True: color images (default), False: grayscale images 61 | void setSize(cv::Size size); //!< To set the size of each frame 62 | 63 | slVideoOut& open(const std::string &name); //!< Opens the video file 64 | void write(const slMat &image); //!< Saves one image 65 | void close(); //!< Close the video file 66 | 67 | private: 68 | void releaseWriter(); 69 | 70 | private: 71 | int fourcc_; 72 | int width_; 73 | int height_; 74 | double fps_; 75 | bool isColor_; 76 | 77 | cv::VideoWriter *writer_; 78 | 79 | }; 80 | 81 | 82 | #endif // SLVIDEOOUT_H 83 | 84 | 85 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/slIO.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | 64 | 65 | Resource Files 66 | 67 | 68 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/slIO_Parameters.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/SDK_LITIV/slIO/slIO_Parameters.txt -------------------------------------------------------------------------------- /SDK_LITIV/slIO/src/slIO.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * FILE : slIO.cpp 3 | * DESCRIPTION : This is the implementation of the interface for the use of 4 | the slIO server. 5 | * AUTHORS : Michael Eilers-Smith 6 | * DATE : June 2008 7 | ******************************************************************************/ 8 | 9 | #include "slIO.h" 10 | 11 | 12 | #ifdef WIN32 13 | #include 14 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved) 15 | { 16 | return TRUE; 17 | } 18 | #endif // WIN32 19 | 20 | 21 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/src/slImageIn.cpp: -------------------------------------------------------------------------------- 1 | #include "slImageIn.h" 2 | 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | 8 | slImageIn::slImageIn(const std::string &filename_format, int index) 9 | : slIn() 10 | { 11 | setFormat(filename_format); 12 | setIndex(index); 13 | } 14 | 15 | 16 | slImageIn::~slImageIn() 17 | { 18 | } 19 | 20 | 21 | void slImageIn::close() 22 | { 23 | setFormat(""); 24 | setIndex(0); 25 | resetSpecs(); 26 | } 27 | 28 | 29 | slImageIn& slImageIn::open(const std::string &filename_format) 30 | { 31 | setFormat(filename_format); 32 | int index = index_; 33 | 34 | try { 35 | slMat image; 36 | read(image); 37 | 38 | index_ = index; 39 | width_ = image.cols; 40 | height_ = image.rows; 41 | fps_ = 1; 42 | nbImages_ = 1; // TODO: Count numbered image files 43 | } 44 | catch (...) { 45 | index_ = index; 46 | resetSpecs(); 47 | throw; 48 | } 49 | 50 | return *this; 51 | } 52 | 53 | 54 | void slImageIn::read(slMat &image) 55 | { 56 | if (!format_.empty()) { 57 | char filename[512]; 58 | 59 | sprintf_s(filename, 512, format_.c_str(), index_++); 60 | filename[511] = 0; 61 | 62 | image = imread(filename); 63 | 64 | if (image.empty()) { 65 | throw slExceptionIO(string("slImageIn::compute(): cannot open \"") + filename + "\""); 66 | } 67 | } 68 | } 69 | 70 | 71 | slImageIn& slImageIn::setFormat(const std::string &filename_format) 72 | { 73 | format_ = filename_format; 74 | return *this; 75 | } 76 | 77 | 78 | slImageIn& slImageIn::setIndex(int index) 79 | { 80 | index_ = index; 81 | return *this; 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/src/slImageOut.cpp: -------------------------------------------------------------------------------- 1 | #include "slImageOut.h" 2 | 3 | 4 | using namespace cv; 5 | 6 | 7 | slImageOut::slImageOut(const std::string &filename_format, int index) 8 | : slOut() 9 | { 10 | setFormat(filename_format); 11 | setIndex(index); 12 | } 13 | 14 | 15 | slImageOut::~slImageOut() 16 | { 17 | } 18 | 19 | 20 | void slImageOut::close() 21 | { 22 | setFormat(""); 23 | setIndex(0); 24 | } 25 | 26 | 27 | slImageOut& slImageOut::open(const std::string &filename_format) 28 | { 29 | setFormat(filename_format); 30 | return *this; 31 | } 32 | 33 | 34 | void slImageOut::write(const slMat &image) 35 | { 36 | if (!format_.empty() && !image.empty()) { 37 | char filename[512]; 38 | 39 | sprintf_s(filename, 512, format_.c_str(), index_++); 40 | filename[511] = 0; 41 | 42 | imwrite(filename, image); 43 | } 44 | } 45 | 46 | 47 | slImageOut& slImageOut::setFormat(const std::string &filename_format) 48 | { 49 | format_ = filename_format; 50 | return *this; 51 | } 52 | 53 | 54 | slImageOut& slImageOut::setIndex(int index) 55 | { 56 | index_ = index; 57 | return *this; 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/src/slIn.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "slIn.h" 4 | 5 | 6 | using namespace cv; 7 | 8 | 9 | slIn::slIn() 10 | { 11 | resetSpecs(); 12 | } 13 | 14 | 15 | slIn::~slIn() 16 | { 17 | } 18 | 19 | 20 | void slIn::resetSpecs() 21 | { 22 | width_ = 0; 23 | height_ = 0; 24 | fps_ = 1; 25 | nbImages_ = 0; 26 | } 27 | 28 | 29 | double slIn::getFPS() const 30 | { 31 | return fps_; 32 | } 33 | 34 | 35 | int slIn::getHeight() const 36 | { 37 | return height_; 38 | } 39 | 40 | 41 | unsigned int slIn::getNbImages() const 42 | { 43 | return nbImages_; 44 | } 45 | 46 | 47 | Size slIn::getSize() const 48 | { 49 | return Size(width_, height_); 50 | } 51 | 52 | 53 | int slIn::getWidth() const 54 | { 55 | return width_; 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/src/slOut.cpp: -------------------------------------------------------------------------------- 1 | #include "slOut.h" 2 | 3 | 4 | slOut::slOut() 5 | { 6 | } 7 | 8 | 9 | slOut::~slOut() 10 | { 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/src/slVideoIn.cpp: -------------------------------------------------------------------------------- 1 | #include "slVideoIn.h" 2 | 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | 8 | slVideoIn::slVideoIn() 9 | : slIn(), capture_(NULL) 10 | { 11 | } 12 | 13 | 14 | slVideoIn::~slVideoIn() 15 | { 16 | releaseCapture(); 17 | } 18 | 19 | 20 | void slVideoIn::releaseCapture() 21 | { 22 | delete capture_; 23 | capture_ = NULL; 24 | } 25 | 26 | 27 | void slVideoIn::close() 28 | { 29 | releaseCapture(); 30 | resetSpecs(); 31 | } 32 | 33 | 34 | slVideoIn& slVideoIn::open(const std::string &name) 35 | { 36 | VideoCapture *capture = new VideoCapture(name); 37 | 38 | if (capture == NULL || capture->isOpened() == false) { 39 | delete capture; 40 | throw slExceptionIO(string("slVideoIn::open(): cannot open \"") + name + "\""); 41 | } 42 | 43 | releaseCapture(); 44 | capture_ = capture; 45 | 46 | width_ = (int)capture_->get(CV_CAP_PROP_FRAME_WIDTH); 47 | height_ = (int)capture_->get(CV_CAP_PROP_FRAME_HEIGHT); 48 | fps_ = capture_->get(CV_CAP_PROP_FPS); 49 | nbImages_ = (unsigned int)capture_->get(CV_CAP_PROP_FRAME_COUNT); 50 | 51 | return *this; 52 | } 53 | 54 | 55 | void slVideoIn::read(slMat &image) 56 | { 57 | if (capture_ != NULL) { 58 | (*capture_) >> image; 59 | } 60 | } 61 | 62 | 63 | -------------------------------------------------------------------------------- /SDK_LITIV/slIO/src/slVideoOut.cpp: -------------------------------------------------------------------------------- 1 | #include "slVideoOut.h" 2 | 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | 8 | slVideoOut::slVideoOut() 9 | : slOut(), fourcc_(-1), width_(0), height_(0), fps_(1), isColor_(true), writer_(NULL) 10 | { 11 | } 12 | 13 | 14 | slVideoOut::~slVideoOut() 15 | { 16 | releaseWriter(); 17 | } 18 | 19 | 20 | void slVideoOut::releaseWriter() 21 | { 22 | delete writer_; 23 | writer_ = NULL; 24 | } 25 | 26 | 27 | void slVideoOut::close() 28 | { 29 | releaseWriter(); 30 | } 31 | 32 | 33 | void slVideoOut::setCodec(int fourcc) 34 | { 35 | fourcc_ = fourcc; 36 | } 37 | 38 | 39 | void slVideoOut::setFPS(double fps) 40 | { 41 | fps_ = fps; 42 | } 43 | 44 | 45 | void slVideoOut::setIsColor(bool isColor) 46 | { 47 | isColor_ = isColor; 48 | } 49 | 50 | 51 | void slVideoOut::setSize(cv::Size size) 52 | { 53 | width_ = size.width; 54 | height_ = size.height; 55 | } 56 | 57 | 58 | slVideoOut& slVideoOut::open(const std::string &name) 59 | { 60 | VideoWriter *writer = new VideoWriter(name, fourcc_, fps_, Size(width_, height_), isColor_); 61 | 62 | if (writer == NULL || writer->isOpened() == false) { 63 | delete writer; 64 | throw slExceptionIO(string("slVideoIn::open(): cannot open \"") + name + "\""); 65 | } 66 | 67 | releaseWriter(); 68 | writer_ = writer; 69 | 70 | return *this; 71 | } 72 | 73 | 74 | void slVideoOut::write(const slMat &image) 75 | { 76 | if (writer_ != NULL) { 77 | (*writer_) << image; 78 | } 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /blobAnalyzer/.gitignore: -------------------------------------------------------------------------------- 1 | 3rdparty 2 | Debug 3 | Release 4 | *.sln 5 | *.suo 6 | *.doc 7 | *.vcxproj 8 | *.user -------------------------------------------------------------------------------- /blobAnalyzer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "slBlobAnalyzer.h" 9 | #include "slContourEngine.h" 10 | 11 | 12 | using namespace cv; 13 | using namespace slAH; 14 | using namespace std; 15 | 16 | void paint(const slImage1ch &fg, const slContours &contours, const slBlobAnalyzer *ba, slImage3ch &output); 17 | void paintKeyPoints(const slKeyPoints &kPt, cv::Scalar color, slImage3ch &output); 18 | 19 | 20 | // Usage: -i ..\..\..\mediaFiles\stereo1_thermal.avi bgSub: -a tempAVG -bf 8 -bfg contour: -c 3 3 blobAn: -a 5 -ba dce -n 16 21 | // Usage: -i ..\..\..\mediaFiles\stereo1_thermal.avi bgSub: -a tempAVG -bf 8 -bfg contour: -c 3 3 blobAn: -a 5 -ba skel 22 | 23 | int main(int argc, char **argv) 24 | { 25 | slArgProcess argProcess; 26 | slArgHandler argHbgSub("bgSub"), argHContour("contour"), argHBlobAn("blobAn"); 27 | 28 | // Get all possible parameters 29 | argProcess 30 | .addGlobal(slParamSpec("-i", "Video source", MANDATORY) << slSyntax("video.avi")) 31 | .addGlobal(slParamSpec("-h", "Help")); 32 | slBgSub::fillAllParamSpecs(argHbgSub); 33 | slContourEngine::fillParamSpecs(argHContour); 34 | slBlobAnalyzer::fillAllParamSpecs(argHBlobAn); 35 | 36 | argProcess << argHbgSub << argHContour << argHBlobAn; 37 | 38 | slVideoIn videoIn; 39 | slBgSub *bgSub = NULL; 40 | slContourEngine *contourEngine = new slContourEngine; 41 | slBlobAnalyzer *ba = NULL; 42 | slWindow winGraph("Graph from contours"); 43 | 44 | try { 45 | // Load parameters from command line 46 | argProcess.parse(argc, argv); 47 | const slParameters &globalParams = argProcess.getParameters(""); 48 | 49 | if (globalParams.isParsed("-h")) { // Help wanted 50 | argProcess.printUsage(); 51 | return 0; 52 | } 53 | 54 | // Configure all compute nodes and others 55 | videoIn.open(globalParams.getValue("-i").c_str()); 56 | bgSub = slBgSubFactory::createInstance(argProcess.getParameters("bgSub")); 57 | contourEngine->setParameters(argProcess.getParameters("contour")); 58 | ba = slBlobAnalyzerFactory::createInstance(argProcess.getParameters("blobAn")); 59 | 60 | // Show configuration 61 | bgSub->showParameters(); 62 | contourEngine->showParameters(); 63 | ba->showParameters(); 64 | } 65 | catch (const slExceptionArgHandler &err) 66 | { 67 | argProcess.printUsage(); 68 | fprintf(stderr, "Error: %s\n", err.getMessage()); 69 | return -1; 70 | } 71 | catch (const slException &err) 72 | { 73 | fprintf(stderr, "Error: %s\n", err.getMessage()); 74 | return -1; 75 | } 76 | 77 | // Start main process 78 | try { 79 | slClock horloge; 80 | slImage3ch imSource; 81 | slImage1ch bForeground, fgTemp; 82 | 83 | /*slImageOut imOut1, imOut2; 84 | imOut1.open("contour.png"); 85 | imOut2.open("foreground.png");*/ 86 | 87 | horloge.setFPS(videoIn.getFPS()); 88 | horloge.start(); 89 | 90 | for (unsigned int ind = 0; ind < videoIn.getNbImages(); ind++) { 91 | videoIn.read(imSource); 92 | bgSub->compute(imSource, bForeground); 93 | 94 | //fgTemp = bForeground.clone(); 95 | 96 | contourEngine->findContours(bForeground); 97 | ba->analyzeAllBlobs(contourEngine->getContours()); 98 | 99 | paint(bForeground, contourEngine->getContours(), ba, imSource); 100 | winGraph.show(imSource); 101 | waitKey(horloge.nextDelay()); 102 | 103 | /*if (ind == 153) 104 | { 105 | imOut1.write(imSource); 106 | imOut2.write(fgTemp); 107 | 108 | cout << "Index : " << ind << endl; 109 | waitKey(); 110 | }*/ 111 | } 112 | 113 | horloge.stop(); 114 | } 115 | catch (const slException &err) 116 | { 117 | fprintf(stderr, "Error: %s\n", err.getMessage()); 118 | return -1; 119 | } 120 | 121 | videoIn.close(); 122 | delete ba; 123 | delete contourEngine; 124 | delete bgSub; 125 | return 0; 126 | } 127 | 128 | 129 | void paint(const slImage1ch &fg, const slContours &contours, const slBlobAnalyzer *ba, slImage3ch &output) 130 | { 131 | // Empty output image 132 | output.create(fg.size()); 133 | output = 0; 134 | 135 | // For each external contour 136 | for (slContours::const_iterator contour = contours.begin(); 137 | !contour.isNull(); contour = contour.next()) 138 | { 139 | if (ba->hasKeyPoints(contour)) { 140 | paintKeyPoints(ba->getKeyPoints(contour), CV_RGB(0, 255, 0), output); 141 | 142 | // For each hole or internal contour 143 | /*for (slContours::const_iterator child = contour.child(); 144 | !child.isNull(); child = child.next()) 145 | { 146 | if (ba->hasKeyPoints(child)) { 147 | paintKeyPoints(ba->getKeyPoints(child), CV_RGB(255, 0, 0), output); 148 | } 149 | }*/ 150 | } 151 | } 152 | } 153 | 154 | 155 | void paintKeyPoints(const slKeyPoints &kPt, cv::Scalar color, slImage3ch &output) 156 | { 157 | for (slKeyPoints::const_iterator itPoint = kPt.begin(); 158 | itPoint != kPt.end(); itPoint++) 159 | { 160 | circle(output, Point(itPoint->first), 2, CV_RGB(0, 0, 255), 2, 8, 0); 161 | 162 | for (CvPt2fVector_t::const_iterator itNb = itPoint->second.beginNeighbors(); 163 | itNb != itPoint->second.endNeighbors(); itNb++) 164 | { 165 | if (CvPoint2fLessThan()(itPoint->first, *itNb)) { 166 | line(output, Point(itPoint->first), Point(*itNb), color); 167 | } 168 | } 169 | } 170 | } 171 | 172 | 173 | -------------------------------------------------------------------------------- /pointsMatcher/.gitignore: -------------------------------------------------------------------------------- 1 | 3rdparty 2 | Debug 3 | Release 4 | *.sln 5 | *.suo 6 | *.doc 7 | *.vcxproj 8 | *.vcxproj.filters 9 | *.vcxproj.user 10 | *.rc 11 | *.user 12 | FD 13 | Results 14 | *.txt 15 | *.props 16 | *.CompareBoundingBox 17 | *.freak 18 | *.seq1to9_CompareGroundtruth 19 | transMat 20 | video.pass 21 | lib 22 | socheat.cpp 23 | tanumain.cpp 24 | main4.cpp 25 | main100.cpp 26 | mainseq1.cpp 27 | mainseq1to9_FindBestFrame.cpp 28 | mymain.cpp 29 | mymain2.cpp 30 | mymain3.cpp 31 | main5.cpp 32 | resource.h -------------------------------------------------------------------------------- /pointsMatcher/KeyPt.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/pointsMatcher/KeyPt.cpp -------------------------------------------------------------------------------- /pointsMatcher/KeyPt.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEY_PT_H__ 2 | #define __KEY_PT_H__ 3 | 4 | #include "slBlobAnalyzer.h" 5 | #include 6 | 7 | #define S_GAUCHE_HAUT 1 8 | #define S_DROITE_HAUT 10 9 | 10 | #define S_DROITE_BAS -1 11 | #define S_GAUCHE_BAS -10 12 | 13 | #define CONVEXE 5 14 | #define CONCAVE 6 15 | 16 | using namespace std; 17 | 18 | class KeyPt 19 | { 20 | public: 21 | KeyPt(); 22 | KeyPt(cv::Point2f position, cv::Point2f centroid, int secteur, int convexite, float angle, cv::Point2f directionAngle, std::vector distancesVoisins, std::pair boundingBox); 23 | 24 | ~KeyPt(); 25 | 26 | void determinerSecteur(cv::Point2f ptMin, cv::Point2f ptMax); 27 | void determinerConvexite(); 28 | void determinerDistanceCentroid(); 29 | void determinerDistancesVoisins(); 30 | void determinerAngle(); 31 | void determinerDirectionAngle(); 32 | //void determinerDirectionAngle(); 33 | void clearVoisins(); 34 | void clearDistancesVoisins(); 35 | 36 | // GET 37 | cv::Point2f getPosition(){return position_;} 38 | cv::Point2f getCentroid(){return centroid_;} 39 | int getSecteur(){return secteur_;} 40 | int getConvexite(){return convexite_;} 41 | std::vector getVoisins(){return voisins_;} 42 | float getAngle(){return angle_;} 43 | cv::Point2f getDirectionAngle(){return directionAngle_;} 44 | //cv::Point2f getDirectionAngle(){return directionAngle_;} 45 | float getDistancesCentroid(){return distanceCentroid_;} 46 | std::vector getDistancesVoisins(){return distancesVoisins_;} 47 | std::pair getBoundingBox(){return boundingBox_;} 48 | 49 | // SET 50 | void setPosition(cv::Point2f position){position_ = position;} 51 | void setCentroid(cv::Point2f centroid){centroid_ = centroid;} 52 | void setSecteur(int secteur){secteur_ = secteur;} 53 | void setConvexite(int convexite){convexite_ = convexite;} 54 | void setVoisins(std::vector voisins){voisins_ = voisins;} 55 | void setAngle(float angle){angle_ = angle;} 56 | void setDirectionAngle(cv::Point2f directionAngle){directionAngle_ = directionAngle;} 57 | //void setDirectionAngle(cv::Point2f directionAngle){directionAngle_ = directionAngle;} 58 | void setDistancesCentroid(float distancesCentroid){distancesCentroid = distancesCentroid;} 59 | void setDistancesVoisins(std::vector distancesVoisins){distancesVoisins_ = distancesVoisins;} 60 | void setBoundingBox(std::pair boundingBox){boundingBox_ = boundingBox;} 61 | void clear(); 62 | private: 63 | cv::Point2f position_; 64 | cv::Point2f centroid_; 65 | int secteur_; 66 | int convexite_; 67 | std::vector voisins_; 68 | float angle_; 69 | cv::Point2f directionAngle_; 70 | //cv::Point2f directionAngle_; 71 | float distanceCentroid_; 72 | std::vector distancesVoisins_; 73 | std::pair boundingBox_; 74 | }; 75 | 76 | #endif -------------------------------------------------------------------------------- /pointsMatcher/Outils.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/pointsMatcher/Outils.cpp -------------------------------------------------------------------------------- /pointsMatcher/Outils.h: -------------------------------------------------------------------------------- 1 | #ifndef __OUTILS_H__ 2 | #define __OUTILS_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "slBlobAnalyzer.h" 15 | #include "slContourEngine.h" 16 | #include "opencv2/calib3d/calib3d.hpp" 17 | #include "opencv2/contrib/contrib.hpp" 18 | #include "opencv2/features2d/features2d.hpp" 19 | #include 20 | #include 21 | #include 22 | 23 | #include "KeyPt.h"; 24 | 25 | using namespace cv; 26 | using namespace slAH; 27 | 28 | #define PI 3.141592653589793 29 | #define RADIUS_MIN 65 30 | #define ERREUR_ANGLE_MAX 40 31 | #define BEGIN_FRAME 0 32 | #define NB_FRAME_MEMORY 100 33 | 34 | namespace Outils 35 | { 36 | std::vector extractKeysPoints(const slContours &contours, const slBlobAnalyzer *ba); 37 | std::vector extractPoints(std::vector keysPoints); 38 | std::vector extractPoints(std::vector keysPoints); 39 | void drawImage (std::vector points, slImage3ch &output); 40 | 41 | void paint(const slImage1ch fg, const slContours &contours, const slBlobAnalyzer *ba, slImage3ch &output); 42 | void paintKeyPoints(const slKeyPoints &kPt, cv::Scalar color, slImage3ch &output); 43 | void paintKeyPoints(const slImage1ch fg, std::vector> vecKeyPts, cv::Scalar vertexColor, cv::Scalar edgeColor, slImage3ch &output); 44 | void writeMatToFile(cv::Mat& m, const std::string& filename); 45 | 46 | 47 | CvMat* Ransac(std::vector &points1, std::vector &points2); 48 | CvMat* Ransac(std::vector &points1, std::vector &points2); 49 | 50 | std::vector CV_Ransac_Simple(std::vector points1, std::vector points2); 51 | 52 | std::vector convertPoints2KeyPoints(std::vector points); 53 | std::vector convert2KeyPt(std::vector> &sortedKeysPoints); 54 | 55 | std::vector extractKeyPoints(std::vector keysPoints); 56 | 57 | std::vector pointsTransform(std::vector points, cv::Mat transMat); 58 | std::vector pointsTransform(std::vector points, cv::Mat transMat); 59 | std::vector> pointsTransform(std::vector> points, cv::Mat transMat); 60 | 61 | float computeMeanEuclideanError(std::vector points1, std::vector points2, unsigned int frameNumber); 62 | float computeMeanEuclideanError(std::vector points1, std::vector points2, unsigned int frameNumber); 63 | 64 | void descriptorMatchLSS(slImage3ch im1, slImage3ch im2, std::vector &points1, std::vector &points2); 65 | float LSSDescriptorDistance(std::vector descriptor1, std::vector descriptor2); 66 | std::vector convert2KeyPt(std::vector &sortedKeysPoints); 67 | 68 | void computeBlobBoundingBox(cv::Point2f &bbMin, cv::Point2f &bbMax, std::vector &sortedKeysPoints); 69 | void computeBlobBoundingBox(cv::Point2f &bbMin, cv::Point2f &bbMax, std::vector &sortedKeysPoints); 70 | 71 | std::vector sortKeyPoints(slKeyPoints &keysPoints); 72 | 73 | void convertAndSortKeyPoints(std::vector &keys, std::vector> &vecNewKeyPts); 74 | 75 | float rad2Deg(float radian); 76 | float deg2Rad(float degree); 77 | 78 | std::vector getCentroid(std::vector> keyPoints); 79 | cv::Point2f getCentroid(std::vector keyPoints); 80 | cv::Point2f getCentroid(std::vector &keyPoints); 81 | 82 | float determinerAngle(cv::Point2f vect1, cv::Point2f vect2, cv::Point2f vect3); 83 | void matchBlobs(std::vector> vecKeyPoints1, std::vector> vecKeyPoints2, std::vector &matchedPoints1, std::vector &matchedPoints2); 84 | void matchBlobs(std::vector> vecKeyPoints1, std::vector> vecKeyPoints2, std::vector> &matchedPoints1, std::vector> &matchedPoints2); 85 | void matchBlobs(std::vector> vecKeyPoints1, std::vector> vecKeyPoints2, std::vector &matchedPoints1, std::vector &matchedPoints2); 86 | void matchPoints(std::vector keyPoints1, std::vector keyPoints2, std::vector &matchedPoints1, std::vector &matchedPoints2); 87 | void matchPoints(std::vector keyPoints1, std::vector keyPoints2, std::vector &matchedPoints1, std::vector &matchedPoints2); 88 | float computeDistance(cv::Point2f pt1, cv::Point2f pt2); 89 | 90 | Point2f findBlobCentroid(Mat &src_gray); 91 | void update_map( slImage3ch src, Mat &dest, Mat map_x, Mat map_y); 92 | 93 | void switchBlackAndWhite(Mat &src); 94 | void transformGroundTruth(Mat src, Mat &dest, string pathFile, string pathVisForegroundFile); 95 | int computeBlobsSurface(Mat src); 96 | 97 | std::vector computeTranslate(std::vector> modifiedPoints, std::vector> points2Compare); 98 | void substractRegion(Mat &src, Mat region2Substract); 99 | int countWhitePixel(Mat &src); 100 | } 101 | 102 | #endif -------------------------------------------------------------------------------- /pointsMatcher/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/pointsMatcher/main.cpp -------------------------------------------------------------------------------- /pointsMatcher/pointsMatcher.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinbycos/Automatic-Image-Registration/737c376a18bc88e8947d837a8f100873221282b0/pointsMatcher/pointsMatcher.sdf --------------------------------------------------------------------------------