tldDetector.hpp 4.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                           License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of the copyright holders may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

Vladimir's avatar
Vladimir committed
42 43 44 45
#ifndef OPENCV_TLD_DETECTOR
#define OPENCV_TLD_DETECTOR

#include "precomp.hpp"
46
#include "opencl_kernels_tracking.hpp"
Vladimir's avatar
Vladimir committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#include "tldEnsembleClassifier.hpp"
#include "tldUtils.hpp"

namespace cv
{
	namespace tld
	{
		const int STANDARD_PATCH_SIZE = 15;
		const int NEG_EXAMPLES_IN_INIT_MODEL = 300;
		const int MAX_EXAMPLES_IN_MODEL = 500;
		const int MEASURES_PER_CLASSIFIER = 13;
		const int GRIDSIZE = 15;
		const int DOWNSCALE_MODE = cv::INTER_LINEAR;
		const double THETA_NN = 0.50;
		const double CORE_THRESHOLD = 0.5;
		const double SCALE_STEP = 1.2;
		const double ENSEMBLE_THRESHOLD = 0.5;
		const double VARIANCE_THRESHOLD = 0.5;
		const double NEXPERT_THRESHOLD = 0.2;

		static const cv::Size GaussBlurKernelSize(3, 3);

		class TLDDetector
		{
		public:
			TLDDetector(){}
			~TLDDetector(){}
			inline double ensembleClassifierNum(const uchar* data);
			inline void prepareClassifiers(int rowstep);
			double Sr(const Mat_<uchar>& patch);
77
			double ocl_Sr(const Mat_<uchar>& patch);
Vladimir's avatar
Vladimir committed
78
			double Sc(const Mat_<uchar>& patch);
79
			double ocl_Sc(const Mat_<uchar>& patch);
80
			void ocl_batchSrSc(const Mat_<uchar>& patches, double *resultSr, double *resultSc, int numOfPatches);
Vladimir's avatar
Vladimir committed
81 82

			std::vector<TLDEnsembleClassifier> classifiers;
83 84
			Mat *posExp, *negExp;
			int *posNum, *negNum;
Vladimir's avatar
Vladimir committed
85 86
			std::vector<Mat_<uchar> > *positiveExamples, *negativeExamples;
			std::vector<int> *timeStampsPositive, *timeStampsNegative;
Vladimir's avatar
Vladimir committed
87
			double *originalVariancePtr;
Vladimir's avatar
Vladimir committed
88 89 90 91 92 93 94 95

			static void generateScanGrid(int rows, int cols, Size initBox, std::vector<Rect2d>& res, bool withScaling = false);
			struct LabeledPatch
			{
				Rect2d rect;
				bool isObject, shouldBeIntegrated;
			};
			bool detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize);
96
			bool ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize);
Vladimir's avatar
Vladimir committed
97
		protected:
Vladimir's avatar
Vladimir committed
98 99


Vladimir's avatar
Vladimir committed
100 101 102

			friend class MyMouseCallbackDEBUG;
			void computeIntegralImages(const Mat& img, Mat_<double>& intImgP, Mat_<double>& intImgP2){ integral(img, intImgP, intImgP2, CV_64F); }
Vladimir's avatar
Vladimir committed
103
			inline bool patchVariance(Mat_<double>& intImgP, Mat_<double>& intImgP2, double *originalVariance, Point pt, Size size);
Vladimir's avatar
Vladimir committed
104 105 106 107 108
		};
	}
}

#endif