helper.hpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011. Philipp Wagner <bytefish[at]gmx[dot]de>.
00003  * Released to public domain under terms of the BSD Simplified license.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *   * Redistributions of source code must retain the above copyright
00008  *     notice, this list of conditions and the following disclaimer.
00009  *   * Redistributions in binary form must reproduce the above copyright
00010  *     notice, this list of conditions and the following disclaimer in the
00011  *     documentation and/or other materials provided with the distribution.
00012  *   * Neither the name of the organization nor the names of its contributors
00013  *     may be used to endorse or promote products derived from this software
00014  *     without specific prior written permission.
00015  *
00016  *   See <http://www.opensource.org/licenses/bsd-license>
00017  */
00018 
00019 #ifndef __HELPER_HPP__
00020 #define __HELPER_HPP__
00021 
00022 #include "opencv2/core/core.hpp"
00023 
00024 #include <vector>
00025 #include <set>
00026 
00027 using namespace std;
00028 
00029 // Removes duplicate elements in a given vector.
00030 template<typename _Tp>
00031 inline vector<_Tp>remove_dups(const vector<_Tp>& src)
00032 {
00033         typedef typename set<_Tp>::const_iterator constSetIterator;
00034         typedef typename vector<_Tp>::const_iterator constVecIterator;
00035         set<_Tp>set_elems;
00036         for (constVecIterator it = src.begin(); it != src.end(); ++it)
00037                 set_elems.insert(*it);
00038         vector<_Tp>elems;
00039         for (constSetIterator it = set_elems.begin(); it != set_elems.end(); ++it)
00040                 elems.push_back(*it);
00041         return elems;
00042 }
00043 
00044 // The namespace cv provides opencv related helper functions.
00045 namespace cv
00046 {
00047 
00048 // Checks if a given matrix is symmetric, with an epsilon for floating point
00049 // matrices (1E-16 by default).
00050 //
00051 //      Mat mSymmetric = (Mat_<double>(2,2) << 1, 2, 2, 1);
00052 //      Mat mNonSymmetric = (Mat_<double>(2,2) << 1, 2, 3, 4);
00053 //      bool symmetric = isSymmetric(mSymmetric); // true
00054 //      bool not_symmetric = isSymmetric(mNonSymmetric); // false
00055 //
00056 bool isSymmetric(InputArray src, double eps = 1E-16);
00057 
00058 // Sorts a 1D Matrix by given sort order and returns the sorted indices.
00059 // This is just a wrapper to simplify cv::sortIdx:
00060 //
00061 //      Mat mNotSorted = (Mat_<double>(1,4) << 1.0, 0.0, 3.0, -1.0);
00062 //      // to sort the vector use
00063 //      Mat sorted_indices = cv::argsort(mNotSorted, true);
00064 //      // make a conversion to vector<int>
00065 //      vector<int> sorted_indices = cv::argsort(mNotSorted, true);
00066 //
00067 Mat argsort(InputArray src, bool ascending = true);
00068 
00069 // Calculates a histogram for a given integral matrix. The minimum inclusive
00070 // value (minVal) and maximum inclusive value can be specified (optionally normed).
00071 Mat histc(InputArray src, int minVal = 0, int maxVal = 255, bool normed = false);
00072 
00073 // Reads a sequence from a FileNode::SEQ with type _Tp into a result vector.
00074 template<typename _Tp>
00075 inline void readFileNodeList(const FileNode& fn, vector<_Tp>& result)
00076 {
00077         if (fn.type() == FileNode::SEQ)
00078         {
00079                 for (FileNodeIterator it = fn.begin(); it != fn.end();)
00080                 {
00081                         _Tp item;
00082                         it >> item;
00083                         result.push_back(item);
00084                 }
00085         }
00086 }
00087 
00088 // Writes the a list of given items to a cv::FileStorage.
00089 template<typename _Tp>
00090 inline void writeFileNodeList(FileStorage& fs, const string& name, const vector<_Tp>& items)
00091 {
00092         // typedefs
00093         typedef typename vector<_Tp>::const_iterator constVecIterator;
00094         // write the elements in item to fs
00095         fs << name << "[";
00096         for (constVecIterator it = items.begin(); it != items.end(); ++it)
00097         {
00098                 fs << *it;
00099         }
00100         fs << "]";
00101 }
00102 
00103 // Sorts a given matrix src by column for given indices.
00104 //
00105 // Note: create is called on dst.
00106 void sortMatrixColumnsByIndices(InputArray src, InputArray indices, OutputArray dst);
00107 
00108 // Sorts a given matrix src by row for given indices.
00109 Mat sortMatrixColumnsByIndices(InputArray src, InputArray indices);
00110 
00111 // Sorts a given matrix src by row for given indices.
00112 //
00113 // Note: create is called on dst.
00114 void sortMatrixRowsByIndices(InputArray src, InputArray indices, OutputArray dst);
00115 
00116 // Sorts a given matrix src by row for given indices.
00117 Mat sortMatrixRowsByIndices(InputArray src, InputArray indices);
00118 
00119 // Turns a vector of matrices into a row matrix.
00120 Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha = 1, double beta = 0);
00121 
00122 // Turns a vector of matrices into a column matrix.
00123 Mat asColumnMatrix(InputArrayOfArrays src, int rtype, double alpha = 1, double beta = 0);
00124 
00125 } // //namespace cv
00126 
00127 #endif


cob_people_detection
Author(s): Richard Bormann , Thomas Zwölfer
autogenerated on Fri Aug 28 2015 10:24:13