aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.CodeGeneration/Templates/ProtoEnumFile.cshtml
blob: d659a028e48ef78b4bdac6c9a21f67c23666b01e (plain)
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
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Tango PMR Generator
// 
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. Do not modify!
// </auto-generated>
//------------------------------------------------------------------------------

syntax = "proto3";

@foreach (var import in Model.Imports)
{
    <div>
        import "@(import)";
    </div>
}

package @(Model.Package);
option java_package = "com.twine.@(Model.Package.ToLower())";

enum @(Model.Name)
{
    @foreach (var prop in Model.Fields)
    {
    <div>
        @(prop.Description != null ? ("//" + prop.Description) : "")
        @(prop.Name) = @(prop.Value);
    </div>
    }
}
adding-left: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*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*/

#include "tldEnsembleClassifier.hpp"

namespace cv
{
	namespace tld
	{
		// Constructor
		TLDEnsembleClassifier::TLDEnsembleClassifier(const std::vector<Vec4b>& meas, int beg, int end) :lastStep_(-1)
		{
			int posSize = 1, mpc = end - beg;
			for (int i = 0; i < mpc; i++)
				posSize *= 2;
			posAndNeg.assign(posSize, Point2i(0, 0));
			measurements.assign(meas.begin() + beg, meas.begin() + end);
			offset.assign(mpc, Point2i(0, 0));
		}
		// Calculate measure locations from 15x15 grid on minSize patches
		void TLDEnsembleClassifier::stepPrefSuff(std::vector<Vec4b>& arr, int pos, int len, int gridSize)
		{
		#if 0
			int step = len / (gridSize - 1), pref = (len - step * (gridSize - 1)) / 2;
			for (int i = 0; i < (int)(sizeof(x1) / sizeof(x1[0])); i++)
				arr[i] = pref + arr[i] * step;
		#else
			int total = len - gridSize;
			int quo = total / (gridSize - 1), rem = total % (gridSize - 1);
			int smallStep = quo, bigStep = quo + 1;
			int bigOnes = rem, smallOnes = gridSize - bigOnes - 1;
			int bigOnes_front = bigOnes / 2, bigOnes_back = bigOnes - bigOnes_front;
			for (int i = 0; i < (int)arr.size(); i++)
			{
				if (arr[i].val[pos] < bigOnes_back)
				{
					arr[i].val[pos] = (uchar)(arr[i].val[pos] * bigStep + arr[i].val[pos]);
					continue;
				}
				if (arr[i].val[pos] < (bigOnes_front + smallOnes))
				{
					arr[i].val[pos] = (uchar)(bigOnes_front * bigStep + (arr[i].val[pos] - bigOnes_front) * smallStep + arr[i].val[pos]);
					continue;
				}
				if (arr[i].val[pos] < (bigOnes_front + smallOnes + bigOnes_back))
				{
					arr[i].val[pos] =
						(uchar)(bigOnes_front * bigStep + smallOnes * smallStep +
						(arr[i].val[pos] - (bigOnes_front + smallOnes)) * bigStep + arr[i].val[pos]);
					continue;
				}
				arr[i].val[pos] = (uchar)(len - 1);
			}
#endif
		}

		// Calculate offsets for classifier
		void TLDEnsembleClassifier::prepareClassifier(int rowstep)
		{
			if (lastStep_ != rowstep)
			{
				lastStep_ = rowstep;
				for (int i = 0; i < (int)offset.size(); i++)
				{
					offset[i].x = rowstep * measurements[i].val[2] + measurements[i].val[0];
					offset[i].y = rowstep * measurements[i].val[3] + measurements[i].val[1];
				}
			}
		}

		// Integrate patch into the Ensemble Classifier model
		void TLDEnsembleClassifier::integrate(const Mat_<uchar>& patch, bool isPositive)
		{
			int position = code(patch.data, (int)patch.step[0]);
			if (isPositive)
				posAndNeg[position].x++;
			else
				posAndNeg[position].y++;
		}

		// Calculate posterior probability on the patch
		double TLDEnsembleClassifier::posteriorProbability(const uchar* data, int rowstep) const
		{
			int position = code(data, rowstep);
			double posNum = (double)posAndNeg[position].x, negNum = (double)posAndNeg[position].y;
			if (posNum == 0.0 && negNum == 0.0)
				return 0.0;
			else
				return posNum / (posNum + negNum);
		}
		double TLDEnsembleClassifier::posteriorProbabilityFast(const uchar* data) const
		{
			int position = codeFast(data);
			double posNum = (double)posAndNeg[position].x, negNum = (double)posAndNeg[position].y;
			if (posNum == 0.0 && negNum == 0.0)
				return 0.0;
			else
				return posNum / (posNum + negNum);
		}

		// Calculate the 13-bit fern index
		int TLDEnsembleClassifier::codeFast(const uchar* data) const
		{
			int position = 0;
			for (int i = 0; i < (int)measurements.size(); i++)
			{
				position = position << 1;
				if (data[offset[i].x] < data[offset[i].y])
					position++;
			}
			return position;
		}
		int TLDEnsembleClassifier::code(const uchar* data, int rowstep) const
		{
			int position = 0;
			for (int i = 0; i < (int)measurements.size(); i++)
			{
				position = position << 1;
				if (*(data + rowstep * measurements[i].val[2] + measurements[i].val[0]) <
					*(data + rowstep * measurements[i].val[3] + measurements[i].val[1]))
				{
					position++;
				}
			}
			return position;
		}

		// Create fern classifiers
		int TLDEnsembleClassifier::makeClassifiers(Size size, int measurePerClassifier, int gridSize,
			std::vector<TLDEnsembleClassifier>& classifiers)
		{

			std::vector<Vec4b> measurements;

			//Generate random measures for 10 ferns x 13 measures
			for (int i = 0; i < 10*measurePerClassifier; i++)
			{
				Vec4b m;
				m.val[0] = rand() % 15;
				m.val[1] = rand() % 15;
				m.val[2] = rand() % 15;
				m.val[3] = rand() % 15;
				measurements.push_back(m);
			}

			//Warp measures to minSize patch coordinates
			stepPrefSuff(measurements, 0, size.width, gridSize);
			stepPrefSuff(measurements, 1, size.width, gridSize);
			stepPrefSuff(measurements, 2, size.height, gridSize);
			stepPrefSuff(measurements, 3, size.height, gridSize);

			//Compile fern classifiers
			for (int i = 0, howMany = (int)measurements.size() / measurePerClassifier; i < howMany; i++)
				classifiers.push_back(TLDEnsembleClassifier(measurements, i * measurePerClassifier, (i + 1) * measurePerClassifier));

			return (int)classifiers.size();
		}

	}
}