Commit 8c90b54f authored by jaco's avatar jaco

Pull Request mandatory changes 2

parent 255d83ac
/*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) 2014, 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*/
#ifndef KYHEADER_H
#define KYHEADER_H
#include <assert.h>
#include <string>
#include <vector>
#include <functional>
#include <list>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <time.h>
#include <fstream>
#include <stdint.h>
//#include <omp.h>
// TODO: reference additional headers your program requires here
//#include "LibLinear/linear.h"
//#include <opencv2/opencv.hpp>
#include "opencv2/core.hpp"
#define CV_VERSION_ID CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)
#ifdef _DEBUG
#define cvLIB(name) "opencv_" name CV_VERSION_ID "d"
#else
#define cvLIB(name) "opencv_" name CV_VERSION_ID
#endif
//#pragma comment( lib, cvLIB("core"))
//#pragma comment( lib, cvLIB("imgproc"))
//#pragma comment( lib, cvLIB("highgui"))
#ifdef WIN32
/* windows stuff */
#else
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned int UNINT32;
typedef bool BOOL;
typedef void *HANDLE;
#endif
#ifndef _MSC_VER
typedef unsigned char BYTE;
#else
#include <windows.h>
#endif
namespace cv
{
namespace saliency
{
typedef std::vector<int> vecI;
typedef const std::string CStr;
typedef const cv::Mat CMat;
typedef std::vector<std::string> vecS;
typedef std::vector<cv::Mat> vecM;
typedef std::vector<float> vecF;
typedef std::vector<double> vecD;
enum
{
CV_FLIP_BOTH = -1,
CV_FLIP_VERTICAL = 0,
CV_FLIP_HORIZONTAL = 1
};
#define _S(str) ((str).c_str())
#define CHK_IND(p) ((p).x >= 0 && (p).x < _w && (p).y >= 0 && (p).y < _h)
#define CV_Assert_(expr, args) \
{\
if(!(expr)) {\
String msg = cv::format args; \
printf("%s in %s:%d\n", msg.c_str(), __FILE__, __LINE__); \
cv::error(cv::Exception(CV_StsAssert, msg, __FUNCTION__, __FILE__, __LINE__) ); }\
}
// Return -1 if not in the list
template<typename T>
static inline int findFromList( const T &word, const std::vector<T> &strList )
{
//TODO delete test code
//cout << "\n\n" << "word" <<" "<< word << endl;
for ( int i = 0; i < strList.size(); i++ )
{
//cout <<"test word:"<< word << " " << endl;
//cout << "Size w " << word.size() << " Size L "<< strList[i].size() << endl;
}
std::vector<cv::String>::iterator it = std::find( strList.begin(), strList.end(), word );
if( it == strList.end() )
{
return -1;
}
else
{
int index = it - strList.begin();
return index;
//vector<String>::iterator index = std::distance( strList.begin(), it );
//cout << "index" <<" "<< index << endl;
//return int( index );
}
}
/*template<typename T>
static inline int findFromList(const string &word, const vector<T> &strList) {
//for(int i=0; i<strList.size(); i++){
//cout <<"element: " <<strList[i]<<" "<<word << endl;
//if (std::strcmp(word.c_str(),strList[i].c_str())==0) return i;
}
return -1;
}
*/
template<typename T> inline T sqr( T x )
{
return x * x;
} // out of range risk for T = byte, ...
template<class T, int D> inline T vecSqrDist( const cv::Vec<T, D> &v1, const cv::Vec<T, D> &v2 )
{
T s = 0;
for ( int i = 0; i < D; i++ )
s += sqr( v1[i] - v2[i] );
return s;
} // out of range risk for T = byte, ...
template<class T, int D> inline T vecDist( const cv::Vec<T, D> &v1, const cv::Vec<T, D> &v2 )
{
return sqrt( vecSqrDist( v1, v2 ) );
} // out of range risk for T = byte, ...
inline cv::Rect Vec4i2Rect( cv::Vec4i &v )
{
return cv::Rect( cv::Point( v[0] - 1, v[1] - 1 ), cv::Point( v[2], v[3] ) );
}
/*
#ifdef __WIN32
#define INT64 long long
#else
#define INT64 long
typedef unsigned long UINT64_;
//#define UINT64 unsigned long
#endif
*/
#if defined(_MSC_VER)
# include <intrin.h>
# define POPCNT(x) __popcnt(x)
# define POPCNT64(x) __popcnt64(x)
#endif
#if defined(__GNUC__)
# define POPCNT(x) __builtin_popcount(x)
# define POPCNT64(x) __builtin_popcountll(x)
#endif
inline int popcnt64( register uint64_t u )
{
u = ( u & 0x5555555555555555 ) + ( ( u >> 1 ) & 0x5555555555555555 );
u = ( u & 0x3333333333333333 ) + ( ( u >> 2 ) & 0x3333333333333333 );
u = ( u & 0x0f0f0f0f0f0f0f0f ) + ( ( u >> 4 ) & 0x0f0f0f0f0f0f0f0f );
u = ( u & 0x00ff00ff00ff00ff ) + ( ( u >> 8 ) & 0x00ff00ff00ff00ff );
u = ( u & 0x0000ffff0000ffff ) + ( ( u >> 16 ) & 0x0000ffff0000ffff );
u = ( u & 0x00000000ffffffff ) + ( ( u >> 32 ) & 0x00000000ffffffff );
return (int)u;
}
inline int popcnt( register uint32_t u )
{
u = ( u & 0x55555555 ) + ( ( u >> 1 ) & 0x55555555 );
u = ( u & 0x33333333 ) + ( ( u >> 2 ) & 0x33333333 );
u = ( u & 0x0f0f0f0f ) + ( ( u >> 4 ) & 0x0f0f0f0f );
u = ( u & 0x00ff00ff ) + ( ( u >> 8 ) & 0x00ff00ff );
u = ( u & 0x0000ffff ) + ( ( u >> 16 ) & 0x0000ffff );
return (int)u;
}
inline int popcnt64_nibble( register uint64_t u )
{
static const uint8_t Table[] =
{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
int c = 0;
while ( u )
{
c += Table[u & 0xf];
u >>= 4;
}
return (int)c;
}
inline int popcnt_nibble( register uint32_t u )
{
static const uint8_t Table[] =
{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
int c = 0;
while ( u )
{
c += Table[u & 0xf];
u >>= 4;
}
return (int)c;
}
inline int popcnt64_byte( register uint64_t u )
{
#define B2(k) k, k+1, k+1, k+2
#define B4(k) B2(k), B2(k+1), B2(k+1), B2(k+2)
#define B6(k) B4(k), B4(k+1), B4(k+1), B4(k+2)
static const uint8_t Table[] =
{ B6( 0 ), B6( 1 ), B6( 1 ), B6( 2 ) };
#undef B6
#undef B4
#undef B2
int c = 0;
while ( u )
{
c += Table[u & 0xff];
u >>= 8;
}
return (int)c;
}
inline int popcnt_byte( register uint32_t u )
{
#define B2(k) k, k+1, k+1, k+2
#define B4(k) B2(k), B2(k+1), B2(k+1), B2(k+2)
#define B6(k) B4(k), B4(k+1), B4(k+1), B4(k+2)
static const uint8_t Table[] =
{ B6( 0 ), B6( 1 ), B6( 1 ), B6( 2 ) };
#undef B6
#undef B4
#undef B2
int c = 0;
while ( u )
{
c += Table[u & 0xff];
u >>= 8;
}
return (int)c;
}
}
}
/////
#endif // KYHEADER_H
......@@ -49,7 +49,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <dirent.h>
#include "opencv2/saliency/kyheader.hpp"
#include "BING/kyheader.hpp"
#endif
namespace cv
......
......@@ -42,7 +42,7 @@
#ifndef __OPENCV_CM_SHOW_HPP__
#define __OPENCV_CM_SHOW_HPP__
#include "opencv2/saliency/kyheader.hpp"
#include "BING/kyheader.hpp"
namespace cv
{
......
......@@ -42,6 +42,8 @@
#ifndef __OPENCV_CM_TIMER_HPP__
#define __OPENCV_CM_TIMER_HPP__
#include "BING/kyheader.hpp"
namespace cv
{
namespace saliency
......
......@@ -67,7 +67,7 @@ float ObjectnessBING::FilterTIG::dot( const int64_t tig1, const int64_t tig2, co
return _coeffs1[0] * ( bc01 + bc02 + bc04 + bc08 ) + _coeffs1[1] * ( bc11 + bc12 + bc14 + bc18 );
}
void ObjectnessBING::FilterTIG::update( CMat &w1f )
void ObjectnessBING::FilterTIG::update( Mat &w1f )
{
CV_Assert( w1f.cols * w1f.rows == D && w1f.type() == CV_32F && w1f.isContinuous() );
float b[D], residuals[D];
......@@ -149,5 +149,5 @@ Mat ObjectnessBING::FilterTIG::matchTemplate( const Mat &mag1u )
return matchCost1f;
}
} // namespace saliency
} // namespace cv
} // namespace saliency
} // namespace cv
......@@ -41,6 +41,7 @@
#include "precomp.hpp"
#include "BING/kyheader.hpp"
#include "CmTimer.hpp"
#include "CmFile.hpp"
......@@ -126,7 +127,7 @@ int ObjectnessBING::loadTrainedModel( std::string modelName ) // Return -1, 0,
return 1;
}
void ObjectnessBING::predictBBoxSI( CMat &img3u, ValStructVec<float, Vec4i> &valBoxes, vecI &sz, int NUM_WIN_PSZ, bool fast )
void ObjectnessBING::predictBBoxSI( Mat &img3u, ValStructVec<float, Vec4i> &valBoxes, std::vector<int> &sz, int NUM_WIN_PSZ, bool fast )
{
const int numSz = (int) _svmSzIdxs.size();
const int imgW = img3u.cols, imgH = img3u.rows;
......@@ -173,7 +174,7 @@ void ObjectnessBING::predictBBoxSI( CMat &img3u, ValStructVec<float, Vec4i> &val
}
void ObjectnessBING::predictBBoxSII( ValStructVec<float, Vec4i> &valBoxes, const vecI &sz )
void ObjectnessBING::predictBBoxSII( ValStructVec<float, Vec4i> &valBoxes, const std::vector<int> &sz )
{
int numI = valBoxes.size();
for ( int i = 0; i < numI; i++ )
......@@ -190,7 +191,7 @@ void ObjectnessBING::predictBBoxSII( ValStructVec<float, Vec4i> &valBoxes, const
// Get potential bounding boxes, each of which is represented by a Vec4i for (minX, minY, maxX, maxY).
// The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII().
// Use numDet to control the final number of proposed bounding boxes, and number of per size (scale and aspect ratio)
void ObjectnessBING::getObjBndBoxes( CMat &img3u, ValStructVec<float, Vec4i> &valBoxes, int numDetPerSize )
void ObjectnessBING::getObjBndBoxes( Mat &img3u, ValStructVec<float, Vec4i> &valBoxes, int numDetPerSize )
{
//CV_Assert_(filtersLoaded() , ("SVM filters should be initialized before getting object proposals\n"));
vecI sz;
......@@ -199,7 +200,7 @@ void ObjectnessBING::getObjBndBoxes( CMat &img3u, ValStructVec<float, Vec4i> &va
return;
}
void ObjectnessBING::nonMaxSup( CMat &matchCost1f, ValStructVec<float, Point> &matchCost, int NSS, int maxPoint, bool fast )
void ObjectnessBING::nonMaxSup( Mat &matchCost1f, ValStructVec<float, Point> &matchCost, int NSS, int maxPoint, bool fast )
{
const int _h = matchCost1f.rows, _w = matchCost1f.cols;
Mat isMax1u = Mat::ones( _h, _w, CV_8U ), costSmooth1f;
......@@ -249,7 +250,7 @@ void ObjectnessBING::nonMaxSup( CMat &matchCost1f, ValStructVec<float, Point> &m
}
}
void ObjectnessBING::gradientMag( CMat &imgBGR3u, Mat &mag1u )
void ObjectnessBING::gradientMag( Mat &imgBGR3u, Mat &mag1u )
{
switch ( _Clr )
{
......@@ -267,7 +268,7 @@ void ObjectnessBING::gradientMag( CMat &imgBGR3u, Mat &mag1u )
}
}
void ObjectnessBING::gradientRGB( CMat &bgr3u, Mat &mag1u )
void ObjectnessBING::gradientRGB( Mat &bgr3u, Mat &mag1u )
{
const int H = bgr3u.rows, W = bgr3u.cols;
Mat Ix( H, W, CV_32S ), Iy( H, W, CV_32S );
......@@ -303,7 +304,7 @@ void ObjectnessBING::gradientRGB( CMat &bgr3u, Mat &mag1u )
gradientXY( Ix, Iy, mag1u );
}
void ObjectnessBING::gradientGray( CMat &bgr3u, Mat &mag1u )
void ObjectnessBING::gradientGray( Mat &bgr3u, Mat &mag1u )
{
Mat g1u;
cvtColor( bgr3u, g1u, COLOR_BGR2GRAY );
......@@ -335,7 +336,7 @@ void ObjectnessBING::gradientGray( CMat &bgr3u, Mat &mag1u )
gradientXY( Ix, Iy, mag1u );
}
void ObjectnessBING::gradientHSV( CMat &bgr3u, Mat &mag1u )
void ObjectnessBING::gradientHSV( Mat &bgr3u, Mat &mag1u )
{
Mat hsv3u;
cvtColor( bgr3u, hsv3u, COLOR_BGR2HSV );
......@@ -367,7 +368,7 @@ void ObjectnessBING::gradientHSV( CMat &bgr3u, Mat &mag1u )
gradientXY( Ix, Iy, mag1u );
}
void ObjectnessBING::gradientXY( CMat &x1i, CMat &y1i, Mat &mag1u )
void ObjectnessBING::gradientXY( Mat &x1i, Mat &y1i, Mat &mag1u )
{
const int H = x1i.rows, W = x1i.cols;
mag1u.create( H, W, CV_8U );
......
/*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) 2014, 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*/
#ifndef __OPENCV_FILTER_TIG_HPP__
#define __OPENCV_FILTER_TIG_HPP__
#include "src/kyheader.hpp"
namespace cv
{
namespace saliency
{
class FilterTIG
{
public:
void update( CMat &w );
// For a W by H gradient magnitude map, find a W-7 by H-7 CV_32F matching score map
cv::Mat matchTemplate( const cv::Mat &mag1u );
inline float dot( const int64_t tig1, const int64_t tig2, const int64_t tig4, const int64_t tig8 );
public:
void reconstruct( cv::Mat &w ); // For illustration purpose
private:
static const int NUM_COMP = 2; // Number of components
static const int D = 64; // Dimension of TIG
int64_t _bTIGs[NUM_COMP]; // Binary TIG features
float _coeffs1[NUM_COMP]; // Coefficients of binary TIG features
// For efficiently deals with different bits in CV_8U gradient map
float _coeffs2[NUM_COMP], _coeffs4[NUM_COMP], _coeffs8[NUM_COMP];
};
inline float FilterTIG::dot( const int64_t tig1, const int64_t tig2, const int64_t tig4, const int64_t tig8 )
{
int64_t bcT1 = (int64_t) POPCNT64( tig1 );
int64_t bcT2 = (int64_t) POPCNT64( tig2 );
int64_t bcT4 = (int64_t) POPCNT64( tig4 );
int64_t bcT8 = (int64_t) POPCNT64( tig8 );
int64_t bc01 = (int64_t) ( POPCNT64(_bTIGs[0] & tig1) << 1 ) - bcT1;
int64_t bc02 = (int64_t) ( ( POPCNT64(_bTIGs[0] & tig2) << 1 ) - bcT2 ) << 1;
int64_t bc04 = (int64_t) ( ( POPCNT64(_bTIGs[0] & tig4) << 1 ) - bcT4 ) << 2;
int64_t bc08 = (int64_t) ( ( POPCNT64(_bTIGs[0] & tig8) << 1 ) - bcT8 ) << 3;
int64_t bc11 = (int64_t) ( POPCNT64(_bTIGs[1] & tig1) << 1 ) - bcT1;
int64_t bc12 = (int64_t) ( ( POPCNT64(_bTIGs[1] & tig2) << 1 ) - bcT2 ) << 1;
int64_t bc14 = (int64_t) ( ( POPCNT64(_bTIGs[1] & tig4) << 1 ) - bcT4 ) << 2;
int64_t bc18 = (int64_t) ( ( POPCNT64(_bTIGs[1] & tig8) << 1 ) - bcT8 ) << 3;
return _coeffs1[0] * ( bc01 + bc02 + bc04 + bc08 ) + _coeffs1[1] * ( bc11 + bc12 + bc14 + bc18 );
}
} /* namespace saliency */
} /* namespace cv */
#endif //__OPENCV_FILTER_TIG_HPP__
/*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) 2014, 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*/
#ifndef __OPENCV_VAL_STRUCT_VEC_HPP__
#define __OPENCV_VAL_STRUCT_VEC_HPP__
/************************************************************************/
/* A value struct vector that supports efficient sorting */
/************************************************************************/
namespace cv
{
namespace saliency
{
template<typename VT, typename ST>
struct ValStructVec
{
ValStructVec()
{
clear();
}
inline int size() const
{
return sz;
}
inline void clear()
{
sz = 0;
structVals.clear();
valIdxes.clear();
}
inline void reserve( int resSz )
{
clear();
structVals.reserve( resSz );
valIdxes.reserve( resSz );
}
inline void pushBack( const VT& val, const ST& structVal )
{
valIdxes.push_back( std::make_pair( val, sz ) );
structVals.push_back( structVal );
sz++;
}
inline const VT& operator ()( int i ) const
{
return valIdxes[i].first;
} // Should be called after sort
inline const ST& operator []( int i ) const
{
return structVals[valIdxes[i].second];
} // Should be called after sort
inline VT& operator ()( int i )
{
return valIdxes[i].first;
} // Should be called after sort
inline ST& operator []( int i )
{
return structVals[valIdxes[i].second];
} // Should be called after sort
void sort( bool descendOrder = true );
const std::vector<ST> &getSortedStructVal();
std::vector<std::pair<VT, int> > getvalIdxes();
void append( const ValStructVec<VT, ST> &newVals, int startV = 0 );
std::vector<ST> structVals; // struct values
private:
int sz; // size of the value struct vector
std::vector<std::pair<VT, int> > valIdxes; // Indexes after sort
bool smaller()
{
return true;
}
;
std::vector<ST> sortedStructVals;
};
template<typename VT, typename ST>
void ValStructVec<VT, ST>::append( const ValStructVec<VT, ST> &newVals, int startV )
{
int newValsSize = newVals.size();
for ( int i = 0; i < newValsSize; i++ )
pushBack( (float) ( ( i + 300 ) * startV ), newVals[i] );
}
template<typename VT, typename ST>
void ValStructVec<VT, ST>::sort( bool descendOrder /* = true */)
{
if( descendOrder )
std::sort( valIdxes.begin(), valIdxes.end(), std::greater<std::pair<VT, int> >() );
else
std::sort( valIdxes.begin(), valIdxes.end(), std::less<std::pair<VT, int> >() );
}
template<typename VT, typename ST>
const std::vector<ST>& ValStructVec<VT, ST>::getSortedStructVal()
{
sortedStructVals.resize( sz );
for ( int i = 0; i < sz; i++ )
sortedStructVals[i] = structVals[valIdxes[i].second];
return sortedStructVals;
}
template<typename VT, typename ST>
std::vector<std::pair<VT, int> > ValStructVec<VT, ST>::getvalIdxes()
{
return valIdxes;
}
} /* namespace saliency */
} /* namespace cv */
#endif //__OPENCV_VAL_STRUCT_VEC_HPP__
/*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) 2014, 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*/
#ifndef KYHEADER_H
#define KYHEADER_H
#include <assert.h>
#include <string>
#include <vector>
#include <functional>
#include <list>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <time.h>
#include <fstream>
#include <stdint.h>
//#include <omp.h>
// TODO: reference additional headers your program requires here
//#include "LibLinear/linear.h"
//#include <opencv2/opencv.hpp>
#include "opencv2/core.hpp"
#define CV_VERSION_ID CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)
#ifdef _DEBUG
#define cvLIB(name) "opencv_" name CV_VERSION_ID "d"
#else
#define cvLIB(name) "opencv_" name CV_VERSION_ID
#endif
//#pragma comment( lib, cvLIB("core"))
//#pragma comment( lib, cvLIB("imgproc"))
//#pragma comment( lib, cvLIB("highgui"))
#ifdef WIN32
/* windows stuff */
#else
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned int UNINT32;
typedef bool BOOL;
typedef void *HANDLE;
#endif
#ifndef _MSC_VER
typedef unsigned char BYTE;
#else
#include <windows.h>
#endif
namespace cv
{
namespace saliency
{
typedef std::vector<int> vecI;
typedef const std::string CStr;
typedef const cv::Mat CMat;
typedef std::vector<std::string> vecS;
typedef std::vector<cv::Mat> vecM;
typedef std::vector<float> vecF;
typedef std::vector<double> vecD;
enum
{
CV_FLIP_BOTH = -1,
CV_FLIP_VERTICAL = 0,
CV_FLIP_HORIZONTAL = 1
};
#define _S(str) ((str).c_str())
#define CHK_IND(p) ((p).x >= 0 && (p).x < _w && (p).y >= 0 && (p).y < _h)
#define CV_Assert_(expr, args) \
{\
if(!(expr)) {\
String msg = cv::format args; \
printf("%s in %s:%d\n", msg.c_str(), __FILE__, __LINE__); \
cv::error(cv::Exception(CV_StsAssert, msg, __FUNCTION__, __FILE__, __LINE__) ); }\
}
// Return -1 if not in the list
template<typename T>
static inline int findFromList( const T &word, const std::vector<T> &strList )
{
//TODO delete test code
//cout << "\n\n" << "word" <<" "<< word << endl;
for ( int i = 0; i < strList.size(); i++ )
{
//cout <<"test word:"<< word << " " << endl;
//cout << "Size w " << word.size() << " Size L "<< strList[i].size() << endl;
}
std::vector<cv::String>::iterator it = std::find( strList.begin(), strList.end(), word );
if( it == strList.end() )
{
return -1;
}
else
{
int index = it - strList.begin();
return index;
//vector<String>::iterator index = std::distance( strList.begin(), it );
//cout << "index" <<" "<< index << endl;
//return int( index );
}
}
/*template<typename T>
static inline int findFromList(const string &word, const vector<T> &strList) {
//for(int i=0; i<strList.size(); i++){
//cout <<"element: " <<strList[i]<<" "<<word << endl;
//if (std::strcmp(word.c_str(),strList[i].c_str())==0) return i;
}
return -1;
}
*/
template<typename T> inline T sqr( T x )
{
return x * x;
} // out of range risk for T = byte, ...
template<class T, int D> inline T vecSqrDist( const cv::Vec<T, D> &v1, const cv::Vec<T, D> &v2 )
{
T s = 0;
for ( int i = 0; i < D; i++ )
s += sqr( v1[i] - v2[i] );
return s;
} // out of range risk for T = byte, ...
template<class T, int D> inline T vecDist( const cv::Vec<T, D> &v1, const cv::Vec<T, D> &v2 )
{
return sqrt( vecSqrDist( v1, v2 ) );
} // out of range risk for T = byte, ...
inline cv::Rect Vec4i2Rect( cv::Vec4i &v )
{
return cv::Rect( cv::Point( v[0] - 1, v[1] - 1 ), cv::Point( v[2], v[3] ) );
}
/*
#ifdef __WIN32
#define INT64 long long
#else
#define INT64 long
typedef unsigned long UINT64_;
//#define UINT64 unsigned long
#endif
*/
#if defined(_MSC_VER)
# include <intrin.h>
# define POPCNT(x) __popcnt(x)
# define POPCNT64(x) __popcnt64(x)
#endif
#if defined(__GNUC__)
# define POPCNT(x) __builtin_popcount(x)
# define POPCNT64(x) __builtin_popcountll(x)
#endif
inline int popcnt64( register uint64_t u )
{
u = ( u & 0x5555555555555555 ) + ( ( u >> 1 ) & 0x5555555555555555 );
u = ( u & 0x3333333333333333 ) + ( ( u >> 2 ) & 0x3333333333333333 );
u = ( u & 0x0f0f0f0f0f0f0f0f ) + ( ( u >> 4 ) & 0x0f0f0f0f0f0f0f0f );
u = ( u & 0x00ff00ff00ff00ff ) + ( ( u >> 8 ) & 0x00ff00ff00ff00ff );
u = ( u & 0x0000ffff0000ffff ) + ( ( u >> 16 ) & 0x0000ffff0000ffff );
u = ( u & 0x00000000ffffffff ) + ( ( u >> 32 ) & 0x00000000ffffffff );
return (int)u;
}
inline int popcnt( register uint32_t u )
{
u = ( u & 0x55555555 ) + ( ( u >> 1 ) & 0x55555555 );
u = ( u & 0x33333333 ) + ( ( u >> 2 ) & 0x33333333 );
u = ( u & 0x0f0f0f0f ) + ( ( u >> 4 ) & 0x0f0f0f0f );
u = ( u & 0x00ff00ff ) + ( ( u >> 8 ) & 0x00ff00ff );
u = ( u & 0x0000ffff ) + ( ( u >> 16 ) & 0x0000ffff );
return (int)u;
}
inline int popcnt64_nibble( register uint64_t u )
{
static const uint8_t Table[] =
{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
int c = 0;
while ( u )
{
c += Table[u & 0xf];
u >>= 4;
}
return (int)c;
}
inline int popcnt_nibble( register uint32_t u )
{
static const uint8_t Table[] =
{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
int c = 0;
while ( u )
{
c += Table[u & 0xf];
u >>= 4;
}
return (int)c;
}
inline int popcnt64_byte( register uint64_t u )
{
#define B2(k) k, k+1, k+1, k+2
#define B4(k) B2(k), B2(k+1), B2(k+1), B2(k+2)
#define B6(k) B4(k), B4(k+1), B4(k+1), B4(k+2)
static const uint8_t Table[] =
{ B6( 0 ), B6( 1 ), B6( 1 ), B6( 2 ) };
#undef B6
#undef B4
#undef B2
int c = 0;
while ( u )
{
c += Table[u & 0xff];
u >>= 8;
}
return (int)c;
}
inline int popcnt_byte( register uint32_t u )
{
#define B2(k) k, k+1, k+1, k+2
#define B4(k) B2(k), B2(k+1), B2(k+1), B2(k+2)
#define B6(k) B4(k), B4(k+1), B4(k+1), B4(k+2)
static const uint8_t Table[] =
{ B6( 0 ), B6( 1 ), B6( 1 ), B6( 2 ) };
#undef B6
#undef B4
#undef B2
int c = 0;
while ( u )
{
c += Table[u & 0xff];
u >>= 8;
}
return (int)c;
}
}
}
/////
#endif // KYHEADER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment