Removing 'using namespace std' from header files, closes bugs #730 and #846

This commit is contained in:
Marius Muja 2011-02-16 06:36:15 +00:00
parent 6b34532901
commit 7d42dbdd71
22 changed files with 110 additions and 126 deletions

View File

@ -132,7 +132,7 @@ public:
private: private:
void computeRNG(Graph &rng, std::vector<cv::Point2f> &vectors, cv::Mat *drawImage = 0) const; void computeRNG(Graph &rng, std::vector<cv::Point2f> &vectors, cv::Mat *drawImage = 0) const;
void rng2gridGraph(Graph &rng, std::vector<cv::Point2f> &vectors) const; void rng2gridGraph(Graph &rng, std::vector<cv::Point2f> &vectors) const;
void eraseUsedGraph(vector<Graph> &basisGraphs) const; void eraseUsedGraph(std::vector<Graph> &basisGraphs) const;
void filterOutliersByDensity(const std::vector<cv::Point2f> &samples, std::vector<cv::Point2f> &filteredSamples); void filterOutliersByDensity(const std::vector<cv::Point2f> &samples, std::vector<cv::Point2f> &filteredSamples);
void findBasis(const std::vector<cv::Point2f> &samples, std::vector<cv::Point2f> &basis, void findBasis(const std::vector<cv::Point2f> &samples, std::vector<cv::Point2f> &basis,
std::vector<Graph> &basisGraphs); std::vector<Graph> &basisGraphs);
@ -164,12 +164,12 @@ private:
//if endpoint is on a segment then function return false //if endpoint is on a segment then function return false
static bool areSegmentsIntersecting(Segment seg1, Segment seg2); static bool areSegmentsIntersecting(Segment seg1, Segment seg2);
static bool doesIntersectionExist(const vector<Segment> &corner, const vector<vector<Segment> > &segments); static bool doesIntersectionExist(const std::vector<Segment> &corner, const std::vector<std::vector<Segment> > &segments);
void getCornerSegments(const vector<vector<size_t> > &points, vector<vector<Segment> > &segments, void getCornerSegments(const std::vector<std::vector<size_t> > &points, std::vector<std::vector<Segment> > &segments,
vector<cv::Point> &cornerIndices, vector<cv::Point> &firstSteps, std::vector<cv::Point> &cornerIndices, std::vector<cv::Point> &firstSteps,
vector<cv::Point> &secondSteps) const; std::vector<cv::Point> &secondSteps) const;
size_t getFirstCorner(vector<cv::Point> &largeCornerIndices, vector<cv::Point> &smallCornerIndices, size_t getFirstCorner(std::vector<cv::Point> &largeCornerIndices, std::vector<cv::Point> &smallCornerIndices,
vector<cv::Point> &firstSteps, vector<cv::Point> &secondSteps) const; std::vector<cv::Point> &firstSteps, std::vector<cv::Point> &secondSteps) const;
static double getDirection(cv::Point2f p1, cv::Point2f p2, cv::Point2f p3); static double getDirection(cv::Point2f p1, cv::Point2f p2, cv::Point2f p3);
std::vector<cv::Point2f> keypoints; std::vector<cv::Point2f> keypoints;

View File

@ -53,11 +53,11 @@ namespace cv
using std::queue; using std::queue;
typedef pair<int,int> coordinate_t; typedef std::pair<int,int> coordinate_t;
typedef float orientation_t;; typedef float orientation_t;
typedef vector<coordinate_t> template_coords_t; typedef std::vector<coordinate_t> template_coords_t;
typedef vector<orientation_t> template_orientations_t; typedef std::vector<orientation_t> template_orientations_t;
typedef pair<Point, float> location_scale_t; typedef std::pair<Point, float> location_scale_t;
class ChamferMatcher class ChamferMatcher
{ {
@ -106,7 +106,7 @@ private:
class LocationImageRange : public ImageRange class LocationImageRange : public ImageRange
{ {
const vector<Point>& locations_; const std::vector<Point>& locations_;
int scales_; int scales_;
float min_scale_; float min_scale_;
@ -116,7 +116,7 @@ private:
LocationImageRange& operator=(const LocationImageRange&); LocationImageRange& operator=(const LocationImageRange&);
public: public:
LocationImageRange(const vector<Point>& locations, int scales = 5, float min_scale = 0.6, float max_scale = 1.6) : LocationImageRange(const std::vector<Point>& locations, int scales = 5, float min_scale = 0.6, float max_scale = 1.6) :
locations_(locations), scales_(scales), min_scale_(min_scale), max_scale_(max_scale) locations_(locations), scales_(scales), min_scale_(min_scale), max_scale_(max_scale)
{ {
} }
@ -130,13 +130,13 @@ private:
class LocationScaleImageRange : public ImageRange class LocationScaleImageRange : public ImageRange
{ {
const vector<Point>& locations_; const std::vector<Point>& locations_;
const vector<float>& scales_; const std::vector<float>& scales_;
LocationScaleImageRange(const LocationScaleImageRange&); LocationScaleImageRange(const LocationScaleImageRange&);
LocationScaleImageRange& operator=(const LocationScaleImageRange&); LocationScaleImageRange& operator=(const LocationScaleImageRange&);
public: public:
LocationScaleImageRange(const vector<Point>& locations, const vector<float>& scales) : LocationScaleImageRange(const std::vector<Point>& locations, const std::vector<float>& scales) :
locations_(locations), scales_(scales) locations_(locations), scales_(scales)
{ {
assert(locations.size()==scales.size()); assert(locations.size()==scales.size());
@ -162,8 +162,8 @@ public:
public: public:
vector<Template*> scaled_templates; std::vector<Template*> scaled_templates;
vector<int> addr; std::vector<int> addr;
int addr_width; int addr_width;
float scale; float scale;
template_coords_t coords; template_coords_t coords;
@ -200,7 +200,7 @@ public:
*/ */
Template* rescale(float scale); Template* rescale(float scale);
vector<int>& getTemplateAddresses(int width); std::vector<int>& getTemplateAddresses(int width);
}; };
@ -217,7 +217,7 @@ public:
const Template* tpl; const Template* tpl;
}; };
typedef vector<Match> Matches; typedef std::vector<Match> Matches;
private: private:
/** /**
@ -230,7 +230,7 @@ private:
float truncate_; float truncate_;
bool use_orientation_; bool use_orientation_;
vector<Template*> templates; std::vector<Template*> templates;
public: public:
Matching(bool use_orientation = true, float truncate = 10) : truncate_(truncate), use_orientation_(use_orientation) Matching(bool use_orientation = true, float truncate = 10) : truncate_(truncate), use_orientation_(use_orientation)
{ {
@ -347,7 +347,7 @@ private:
class LocationImageIterator : public ImageIterator class LocationImageIterator : public ImageIterator
{ {
const vector<Point>& locations_; const std::vector<Point>& locations_;
size_t iter_; size_t iter_;
@ -365,7 +365,7 @@ private:
LocationImageIterator& operator=(const LocationImageIterator&); LocationImageIterator& operator=(const LocationImageIterator&);
public: public:
LocationImageIterator(const vector<Point>& locations, int scales, float min_scale, float max_scale); LocationImageIterator(const std::vector<Point>& locations, int scales, float min_scale, float max_scale);
bool hasNext() const { bool hasNext() const {
return has_next_; return has_next_;
@ -376,8 +376,8 @@ private:
class LocationScaleImageIterator : public ImageIterator class LocationScaleImageIterator : public ImageIterator
{ {
const vector<Point>& locations_; const std::vector<Point>& locations_;
const vector<float>& scales_; const std::vector<float>& scales_;
size_t iter_; size_t iter_;
@ -387,7 +387,7 @@ private:
LocationScaleImageIterator& operator=(const LocationScaleImageIterator&); LocationScaleImageIterator& operator=(const LocationScaleImageIterator&);
public: public:
LocationScaleImageIterator(const vector<Point>& locations, const vector<float>& scales) : LocationScaleImageIterator(const std::vector<Point>& locations, const std::vector<float>& scales) :
locations_(locations), scales_(scales) locations_(locations), scales_(scales)
{ {
assert(locations.size()==scales.size()); assert(locations.size()==scales.size());
@ -511,7 +511,7 @@ ChamferMatcher::SlidingWindowImageIterator::SlidingWindowImageIterator( int widt
location_scale_t ChamferMatcher::SlidingWindowImageIterator::next() location_scale_t ChamferMatcher::SlidingWindowImageIterator::next()
{ {
location_scale_t next_val = make_pair(Point(x_,y_),scale_); location_scale_t next_val = std::make_pair(Point(x_,y_),scale_);
x_ += x_step_; x_ += x_step_;
@ -544,7 +544,7 @@ ChamferMatcher::ImageIterator* ChamferMatcher::SlidingWindowImageRange::iterator
ChamferMatcher::LocationImageIterator::LocationImageIterator(const vector<Point>& locations, ChamferMatcher::LocationImageIterator::LocationImageIterator(const std::vector<Point>& locations,
int scales = 5, int scales = 5,
float min_scale = 0.6, float min_scale = 0.6,
float max_scale = 1.6) : float max_scale = 1.6) :
@ -562,7 +562,7 @@ ChamferMatcher::LocationImageIterator::LocationImageIterator(const vector<Point>
location_scale_t ChamferMatcher::LocationImageIterator:: next() location_scale_t ChamferMatcher::LocationImageIterator:: next()
{ {
location_scale_t next_val = make_pair(locations_[iter_],scale_); location_scale_t next_val = std::make_pair(locations_[iter_],scale_);
iter_ ++; iter_ ++;
if (iter_==locations_.size()) { if (iter_==locations_.size()) {
@ -583,7 +583,7 @@ location_scale_t ChamferMatcher::LocationImageIterator:: next()
location_scale_t ChamferMatcher::LocationScaleImageIterator::next() location_scale_t ChamferMatcher::LocationScaleImageIterator::next()
{ {
location_scale_t next_val = make_pair(locations_[iter_],scales_[iter_]); location_scale_t next_val = std::make_pair(locations_[iter_],scales_[iter_]);
iter_ ++; iter_ ++;
if (iter_==locations_.size()) { if (iter_==locations_.size()) {
@ -738,7 +738,7 @@ void ChamferMatcher::Matching::findContourOrientations(const template_coords_t&
const int M = 5; const int M = 5;
int coords_size = coords.size(); int coords_size = coords.size();
vector<float> angles(2*M); std::vector<float> angles(2*M);
orientations.insert(orientations.begin(), coords_size, float(-3*CV_PI)); // mark as invalid in the beginning orientations.insert(orientations.begin(), coords_size, float(-3*CV_PI)); // mark as invalid in the beginning
if (coords_size<2*M+1) { // if contour not long enough to estimate orientations, abort if (coords_size<2*M+1) { // if contour not long enough to estimate orientations, abort
@ -948,7 +948,7 @@ void ChamferMatcher::Matching::computeDistanceTransform(Mat& edges_img, Mat& dis
int w = s.width; int w = s.width;
int h = s.height; int h = s.height;
// set distance to the edge pixels to 0 and put them in the queue // set distance to the edge pixels to 0 and put them in the queue
queue<pair<int,int> > q; std::queue<std::pair<int,int> > q;
@ -957,7 +957,7 @@ void ChamferMatcher::Matching::computeDistanceTransform(Mat& edges_img, Mat& dis
unsigned char edge_val = edges_img.at<uchar>(y,x); unsigned char edge_val = edges_img.at<uchar>(y,x);
if ( (edge_val!=0) ) { if ( (edge_val!=0) ) {
q.push(make_pair(x,y)); q.push(std::make_pair(x,y));
dist_img.at<float>(y,x)= 0; dist_img.at<float>(y,x)= 0;
if (&annotate_img!=NULL) { if (&annotate_img!=NULL) {
@ -972,7 +972,7 @@ void ChamferMatcher::Matching::computeDistanceTransform(Mat& edges_img, Mat& dis
} }
// breadth first computation of distance transform // breadth first computation of distance transform
pair<int,int> crt; std::pair<int,int> crt;
while (!q.empty()) { while (!q.empty()) {
crt = q.front(); crt = q.front();
q.pop(); q.pop();
@ -1000,7 +1000,7 @@ void ChamferMatcher::Matching::computeDistanceTransform(Mat& edges_img, Mat& dis
if (dt==-1 || dt>dist) { if (dt==-1 || dt>dist) {
dist_img.at<float>(ny,nx) = dist; dist_img.at<float>(ny,nx) = dist;
q.push(make_pair(nx,ny)); q.push(std::make_pair(nx,ny));
if (&annotate_img!=NULL) { if (&annotate_img!=NULL) {
annotate_img.at<Vec2i>(ny,nx)[0]=annotate_img.at<Vec2i>(y,x)[0]; annotate_img.at<Vec2i>(ny,nx)[0]=annotate_img.at<Vec2i>(y,x)[0];
@ -1082,7 +1082,7 @@ ChamferMatcher::Match* ChamferMatcher::Matching::localChamferDistance(Point offs
float beta = 1-alpha; float beta = 1-alpha;
vector<int>& addr = tpl->getTemplateAddresses(dist_img.cols); std::vector<int>& addr = tpl->getTemplateAddresses(dist_img.cols);
float* ptr = dist_img.ptr<float>(y)+x; float* ptr = dist_img.ptr<float>(y)+x;
@ -1271,7 +1271,7 @@ void ChamferMatcher::addMatch(float cost, Point offset, const Template* tpl)
void ChamferMatcher::showMatch(Mat& img, int index) void ChamferMatcher::showMatch(Mat& img, int index)
{ {
if (index>=count) { if (index>=count) {
cout << "Index too big.\n" << endl; std::cout << "Index too big.\n" << std::endl;
} }
assert(img.channels()==3); assert(img.channels()==3);
@ -1347,7 +1347,7 @@ const ChamferMatcher::Matches& ChamferMatcher::matching(Template& tpl, Mat& imag
int chamerMatching( Mat& img, Mat& templ, int chamerMatching( Mat& img, Mat& templ,
vector<vector<Point> >& results, vector<float>& costs, std::vector<std::vector<Point> >& results, std::vector<float>& costs,
double templScale, int maxMatches, double minMatchDistance, int padX, double templScale, int maxMatches, double minMatchDistance, int padX,
int padY, int scales, double minScale, double maxScale, int padY, int scales, double minScale, double maxScale,
double orientationWeight, double truncate ) double orientationWeight, double truncate )
@ -1381,7 +1381,7 @@ int chamerMatching( Mat& img, Mat& templ,
costs[i] = (float)cval; costs[i] = (float)cval;
const template_coords_t& templ_coords = match.tpl->coords; const template_coords_t& templ_coords = match.tpl->coords;
vector<Point>& templPoints = results[i]; std::vector<Point>& templPoints = results[i];
size_t j, npoints = templ_coords.size(); size_t j, npoints = templ_coords.size();
templPoints.resize(npoints); templPoints.resize(npoints);

View File

@ -224,8 +224,8 @@ private:
float totalCost; float totalCost;
}; };
typedef pair<CostData, KDTreeIndexParams> KDTreeCostData; typedef std::pair<CostData, KDTreeIndexParams> KDTreeCostData;
typedef pair<CostData, KMeansIndexParams> KMeansCostData; typedef std::pair<CostData, KMeansIndexParams> KMeansCostData;
void evaluate_kmeans(CostData& cost, const KMeansIndexParams& kmeans_params) void evaluate_kmeans(CostData& cost, const KMeansIndexParams& kmeans_params)
@ -338,7 +338,7 @@ private:
int kmeansParamSpaceSize = ARRAY_LEN(maxIterations)*ARRAY_LEN(branchingFactors); int kmeansParamSpaceSize = ARRAY_LEN(maxIterations)*ARRAY_LEN(branchingFactors);
vector<KMeansCostData> kmeansCosts(kmeansParamSpaceSize); std::vector<KMeansCostData> kmeansCosts(kmeansParamSpaceSize);
// CostData* kmeansCosts = new CostData[kmeansParamSpaceSize]; // CostData* kmeansCosts = new CostData[kmeansParamSpaceSize];
@ -417,7 +417,7 @@ private:
int testTrees[] = { 1, 4, 8, 16, 32 }; int testTrees[] = { 1, 4, 8, 16, 32 };
size_t kdtreeParamSpaceSize = ARRAY_LEN(testTrees); size_t kdtreeParamSpaceSize = ARRAY_LEN(testTrees);
vector<KDTreeCostData> kdtreeCosts(kdtreeParamSpaceSize); std::vector<KDTreeCostData> kdtreeCosts(kdtreeParamSpaceSize);
// evaluate kdtree for all parameter combinations // evaluate kdtree for all parameter combinations
int cnt = 0; int cnt = 0;
@ -484,7 +484,7 @@ private:
IndexParams* estimateBuildParams() IndexParams* estimateBuildParams()
{ {
int sampleSize = int(index_params.sample_fraction*dataset.rows); int sampleSize = int(index_params.sample_fraction*dataset.rows);
int testSampleSize = min(sampleSize/10, 1000); int testSampleSize = std::min(sampleSize/10, 1000);
logger().info("Entering autotuning, dataset size: %d, sampleSize: %d, testSampleSize: %d\n",dataset.rows, sampleSize, testSampleSize); logger().info("Entering autotuning, dataset size: %d, sampleSize: %d, testSampleSize: %d\n",dataset.rows, sampleSize, testSampleSize);
@ -550,7 +550,7 @@ private:
float speedup = 0; float speedup = 0;
int samples = (int)min(dataset.rows/10, SAMPLE_COUNT); int samples = (int)std::min(dataset.rows/10, SAMPLE_COUNT);
if (samples>0) { if (samples>0) {
Matrix<ELEM_TYPE> testDataset = random_sample(dataset,samples); Matrix<ELEM_TYPE> testDataset = random_sample(dataset,samples);

View File

@ -32,7 +32,6 @@
#define _OPENCV_DIST_H_ #define _OPENCV_DIST_H_
#include <cmath> #include <cmath>
using namespace std;
#include "opencv2/flann/general.h" #include "opencv2/flann/general.h"

View File

@ -109,7 +109,7 @@ public:
template<typename T> template<typename T>
NNIndex<T>* load_saved_index(const Matrix<T>& dataset, const string& filename) NNIndex<T>* load_saved_index(const Matrix<T>& dataset, const std::string& filename)
{ {
FILE* fin = fopen(filename.c_str(), "rb"); FILE* fin = fopen(filename.c_str(), "rb");
if (fin==NULL) { if (fin==NULL) {
@ -208,7 +208,7 @@ int Index<T>::radiusSearch(const Matrix<T>& query, Matrix<int>& indices, Matrix<
// TODO: optimise here // TODO: optimise here
int* neighbors = resultSet.getNeighbors(); int* neighbors = resultSet.getNeighbors();
float* distances = resultSet.getDistances(); float* distances = resultSet.getDistances();
size_t count_nn = min(resultSet.size(), indices.cols); size_t count_nn = std::min(resultSet.size(), indices.cols);
assert (dists.cols>=count_nn); assert (dists.cols>=count_nn);
@ -222,7 +222,7 @@ int Index<T>::radiusSearch(const Matrix<T>& query, Matrix<int>& indices, Matrix<
template<typename T> template<typename T>
void Index<T>::save(string filename) void Index<T>::save(std::string filename)
{ {
FILE* fout = fopen(filename.c_str(), "wb"); FILE* fout = fopen(filename.c_str(), "wb");
if (fout==NULL) { if (fout==NULL) {

View File

@ -66,8 +66,8 @@ void find_nearest(const Matrix<T>& dataset, T* query, int* matches, int nn, int
int j = dcnt-1; int j = dcnt-1;
// bubble up // bubble up
while (j>=1 && dists[j]<dists[j-1]) { while (j>=1 && dists[j]<dists[j-1]) {
swap(dists[j],dists[j-1]); std::swap(dists[j],dists[j-1]);
swap(match[j],match[j-1]); std::swap(match[j],match[j-1]);
j--; j--;
} }
} }

View File

@ -33,7 +33,6 @@
#include <algorithm> #include <algorithm>
using namespace std;
namespace cvflann namespace cvflann
{ {
@ -162,7 +161,7 @@ public:
} }
/* Switch first node with last. */ /* Switch first node with last. */
swap(heap[1],heap[count]); std::swap(heap[1],heap[count]);
count -= 1; count -= 1;
heapify(1); /* Move new node 1 to right position. */ heapify(1); /* Move new node 1 to right position. */
@ -197,7 +196,7 @@ public:
/* If a child was smaller, than swap parent with it and Heapify. */ /* If a child was smaller, than swap parent with it and Heapify. */
if (minloc != parent) { if (minloc != parent) {
swap(heap[parent],heap[minloc]); std::swap(heap[parent],heap[minloc]);
heapify(minloc); heapify(minloc);
} }
} }

View File

@ -41,7 +41,6 @@
#include "opencv2/flann/timer.h" #include "opencv2/flann/timer.h"
using namespace std;
namespace cvflann namespace cvflann
{ {
@ -207,7 +206,7 @@ float test_index_precisions(NNIndex<ELEM_TYPE>& index, const Matrix<ELEM_TYPE>&
const float SEARCH_EPS = 0.001; const float SEARCH_EPS = 0.001;
// make sure precisions array is sorted // make sure precisions array is sorted
sort(precisions, precisions+precisions_length); std::sort(precisions, precisions+precisions_length);
int pindex = 0; int pindex = 0;
float precision = precisions[pindex]; float precision = precisions[pindex];

View File

@ -45,8 +45,6 @@
#include "opencv2/flann/random.h" #include "opencv2/flann/random.h"
#include "opencv2/flann/saving.h" #include "opencv2/flann/saving.h"
using namespace std;
namespace cvflann namespace cvflann
{ {
@ -232,7 +230,7 @@ public:
/* Randomize the order of vectors to allow for unbiased sampling. */ /* Randomize the order of vectors to allow for unbiased sampling. */
for (int j = (int)size_; j > 0; --j) { for (int j = (int)size_; j > 0; --j) {
int rnd = rand_int(j); int rnd = rand_int(j);
swap(vind[j-1], vind[rnd]); std::swap(vind[j-1], vind[rnd]);
} }
trees[i] = divideTree(0, (int)size_ - 1); trees[i] = divideTree(0, (int)size_ - 1);
} }
@ -384,7 +382,7 @@ private:
/* Compute mean values. Only the first SAMPLE_MEAN values need to be /* Compute mean values. Only the first SAMPLE_MEAN values need to be
sampled to get a good estimate. sampled to get a good estimate.
*/ */
int end = min(first + SAMPLE_MEAN, last); int end = std::min(first + SAMPLE_MEAN, last);
for (int j = first; j <= end; ++j) { for (int j = first; j <= end; ++j) {
ELEM_TYPE* v = dataset[vind[j]]; ELEM_TYPE* v = dataset[vind[j]];
for (size_t k=0; k<veclen_; ++k) { for (size_t k=0; k<veclen_; ++k) {
@ -432,7 +430,7 @@ private:
/* Bubble end value down to right location by repeated swapping. */ /* Bubble end value down to right location by repeated swapping. */
int j = num - 1; int j = num - 1;
while (j > 0 && v[topind[j]] > v[topind[j-1]]) { while (j > 0 && v[topind[j]] > v[topind[j-1]]) {
swap(topind[j], topind[j-1]); std::swap(topind[j], topind[j-1]);
--j; --j;
} }
} }
@ -459,7 +457,7 @@ private:
++i; ++i;
} else { } else {
/* Move to end of list by swapping vind i and j. */ /* Move to end of list by swapping vind i and j. */
swap(vind[i], vind[j]); std::swap(vind[i], vind[j]);
--j; --j;
} }
} }
@ -506,7 +504,7 @@ private:
int checkCount = 0; int checkCount = 0;
Heap<BranchSt>* heap = new Heap<BranchSt>((int)size_); Heap<BranchSt>* heap = new Heap<BranchSt>((int)size_);
vector<bool> checked(size_,false); std::vector<bool> checked(size_,false);
/* Search once through each tree down to root. */ /* Search once through each tree down to root. */
for (i = 0; i < numTrees; ++i) { for (i = 0; i < numTrees; ++i) {
@ -530,7 +528,7 @@ private:
* at least "mindistsq". * at least "mindistsq".
*/ */
void searchLevel(ResultSet<ELEM_TYPE>& result, const ELEM_TYPE* vec, Tree node, float mindistsq, int& checkCount, int maxCheck, void searchLevel(ResultSet<ELEM_TYPE>& result, const ELEM_TYPE* vec, Tree node, float mindistsq, int& checkCount, int maxCheck,
Heap<BranchSt>* heap, vector<bool>& checked) Heap<BranchSt>* heap, std::vector<bool>& checked)
{ {
if (result.worstDist()<mindistsq) { if (result.worstDist()<mindistsq) {
// printf("Ignoring branch, too far\n"); // printf("Ignoring branch, too far\n");

View File

@ -46,12 +46,10 @@
#include "opencv2/flann/allocator.h" #include "opencv2/flann/allocator.h"
#include "opencv2/flann/random.h" #include "opencv2/flann/random.h"
using namespace std;
namespace cvflann namespace cvflann
{ {
struct CV_EXPORTS KMeansIndexParams : public IndexParams { struct CV_EXPORTS KMeansIndexParams : public IndexParams {
KMeansIndexParams(int branching_ = 32, int iterations_ = 11, KMeansIndexParams(int branching_ = 32, int iterations_ = 11,
flann_centers_init_t centers_init_ = CENTERS_RANDOM, float cb_index_ = 0.2 ) : flann_centers_init_t centers_init_ = CENTERS_RANDOM, float cb_index_ = 0.2 ) :
@ -353,7 +351,7 @@ class KMeansIndex : public NNIndex<ELEM_TYPE>
// Compute the new potential // Compute the new potential
double newPot = 0; double newPot = 0;
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
newPot += min( flann_dist(dataset[indices[i]], dataset[indices[i]] + dataset.cols, dataset[indices[index]]), closestDistSq[i] ); newPot += std::min( flann_dist(dataset[indices[i]], dataset[indices[i]] + dataset.cols, dataset[indices[index]]), closestDistSq[i] );
// Store the best result // Store the best result
if (bestNewPot < 0 || newPot < bestNewPot) { if (bestNewPot < 0 || newPot < bestNewPot) {
@ -366,7 +364,7 @@ class KMeansIndex : public NNIndex<ELEM_TYPE>
centers[centerCount] = indices[bestNewIndex]; centers[centerCount] = indices[bestNewIndex];
currentPot = bestNewPot; currentPot = bestNewPot;
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
closestDistSq[i] = min( flann_dist(dataset[indices[i]], dataset[indices[i]]+dataset.cols, dataset[indices[bestNewIndex]]), closestDistSq[i] ); closestDistSq[i] = std::min( flann_dist(dataset[indices[i]], dataset[indices[i]]+dataset.cols, dataset[indices[bestNewIndex]]), closestDistSq[i] );
} }
centers_length = centerCount; centers_length = centerCount;
@ -402,7 +400,7 @@ public:
branching = params.branching; branching = params.branching;
max_iter = params.iterations; max_iter = params.iterations;
if (max_iter<0) { if (max_iter<0) {
max_iter = numeric_limits<int>::max(); max_iter = (std::numeric_limits<int>::max)();
} }
flann_centers_init_t centersInit = params.centers_init; flann_centers_init_t centersInit = params.centers_init;
@ -711,7 +709,7 @@ private:
if (indices_length < branching) { if (indices_length < branching) {
node->indices = indices; node->indices = indices;
sort(node->indices,node->indices+indices_length); std::sort(node->indices,node->indices+indices_length);
node->childs = NULL; node->childs = NULL;
return; return;
} }
@ -722,7 +720,7 @@ private:
if (centers_length<branching) { if (centers_length<branching) {
node->indices = indices; node->indices = indices;
sort(node->indices,node->indices+indices_length); std::sort(node->indices,node->indices+indices_length);
node->childs = NULL; node->childs = NULL;
return; return;
} }
@ -859,8 +857,8 @@ private:
double d = flann_dist(dataset[indices[i]],dataset[indices[i]]+veclen_,zero()); double d = flann_dist(dataset[indices[i]],dataset[indices[i]]+veclen_,zero());
variance += d; variance += d;
mean_radius += sqrt(d); mean_radius += sqrt(d);
swap(indices[i],indices[end]); std::swap(indices[i],indices[end]);
swap(belongs_to[i],belongs_to[end]); std::swap(belongs_to[i],belongs_to[end]);
end++; end++;
} }
} }
@ -1072,7 +1070,7 @@ private:
float meanVariance = root->variance*root->size; float meanVariance = root->variance*root->size;
while (clusterCount<clusters_length) { while (clusterCount<clusters_length) {
float minVariance = numeric_limits<float>::max(); float minVariance = (std::numeric_limits<float>::max)();
int splitIndex = -1; int splitIndex = -1;
for (int i=0;i<clusterCount;++i) { for (int i=0;i<clusterCount;++i) {

View File

@ -36,7 +36,6 @@
#include <stdarg.h> #include <stdarg.h>
#include "opencv2/flann/general.h" #include "opencv2/flann/general.h"
using namespace std;
namespace cvflann namespace cvflann
{ {

View File

@ -36,8 +36,6 @@
#include "opencv2/flann/general.h" #include "opencv2/flann/general.h"
#include "opencv2/flann/matrix.h" #include "opencv2/flann/matrix.h"
using namespace std;
namespace cvflann namespace cvflann
{ {

View File

@ -35,7 +35,6 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
using namespace std;
namespace cvflann namespace cvflann
{ {
@ -109,7 +108,7 @@ public:
// int rand = cast(int) (drand48() * n); // int rand = cast(int) (drand48() * n);
int rnd = rand_int(i); int rnd = rand_int(i);
assert(rnd >=0 && rnd < i); assert(rnd >=0 && rnd < i);
swap(vals[i-1], vals[rnd]); std::swap(vals[i-1], vals[rnd]);
} }
counter = 0; counter = 0;

View File

@ -37,8 +37,6 @@
#include <vector> #include <vector>
#include "opencv2/flann/dist.h" #include "opencv2/flann/dist.h"
using namespace std;
namespace cvflann namespace cvflann
{ {
@ -181,8 +179,8 @@ public:
// bubble up // bubble up
while (i>=1 && (dists[i]<dists[i-1] || (dists[i]==dists[i-1] && indices[i]<indices[i-1]) ) ) { while (i>=1 && (dists[i]<dists[i-1] || (dists[i]==dists[i-1] && indices[i]<indices[i-1]) ) ) {
// while (i>=1 && (dists[i]<dists[i-1]) ) { // while (i>=1 && (dists[i]<dists[i-1]) ) {
swap(indices[i],indices[i-1]); std::swap(indices[i],indices[i-1]);
swap(dists[i],dists[i-1]); std::swap(dists[i],dists[i-1]);
i--; i--;
} }
@ -191,7 +189,7 @@ public:
float worstDist() const float worstDist() const
{ {
return (count<capacity) ? numeric_limits<float>::max() : dists[count-1]; return (count<capacity) ? (std::numeric_limits<float>::max)() : dists[count-1];
} }
}; };
@ -215,7 +213,7 @@ class RadiusResultSet : public ResultSet<ELEM_TYPE>
} }
}; };
vector<Item> items; std::vector<Item> items;
float radius; float radius;
bool sorted; bool sorted;

View File

@ -56,7 +56,7 @@ Matrix<T> random_sample(Matrix<T>& srcMatrix, long size, bool remove = false)
dest = srcMatrix[srcMatrix.rows-i-1]; dest = srcMatrix[srcMatrix.rows-i-1];
src = srcMatrix[r]; src = srcMatrix[r];
for (size_t j=0;j<srcMatrix.cols;++j) { for (size_t j=0;j<srcMatrix.cols;++j) {
swap(*src,*dest); std::swap(*src,*dest);
src++; src++;
dest++; dest++;
} }

View File

@ -89,7 +89,7 @@ int countCorrectMatches(int* neighbors, int* groundTruth, int n)
return count; return count;
} }
// ----------------------- logger().cpp --------------------------- // ----------------------- logger.cpp ---------------------------
Logger logger_; Logger logger_;

View File

@ -42,8 +42,6 @@
#ifndef _CV_GCGRAPH_H_ #ifndef _CV_GCGRAPH_H_
#define _CV_GCGRAPH_H_ #define _CV_GCGRAPH_H_
using namespace std;
template <class TWeight> class GCGraph template <class TWeight> class GCGraph
{ {
public: public:
@ -76,8 +74,8 @@ private:
TWeight weight; TWeight weight;
}; };
vector<Vtx> vtcs; std::vector<Vtx> vtcs;
vector<Edge> edges; std::vector<Edge> edges;
TWeight flow; TWeight flow;
}; };
@ -158,7 +156,7 @@ TWeight GCGraph<TWeight>::maxFlow()
Vtx *vtxPtr = &vtcs[0]; Vtx *vtxPtr = &vtcs[0];
Edge *edgePtr = &edges[0]; Edge *edgePtr = &edges[0];
vector<Vtx*> orphans; std::vector<Vtx*> orphans;
// initialize the active queue and the graph vertices // initialize the active queue and the graph vertices
for( int i = 0; i < (int)vtcs.size(); i++ ) for( int i = 0; i < (int)vtcs.size(); i++ )

View File

@ -16,11 +16,11 @@
int main() int main()
{ {
#if !defined(HAVE_CUDA) #if !defined(HAVE_CUDA)
cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n"; std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n";
#endif #endif
#if !defined(HAVE_TBB) #if !defined(HAVE_TBB)
cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n"; std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n";
#endif #endif
return 0; return 0;
@ -44,7 +44,7 @@ inline void safeCall_(int code, const char* expr, const char* file, int line)
{ {
if (code != CUDA_SUCCESS) if (code != CUDA_SUCCESS)
{ {
cout << "CUDA driver API error: code " << code << ", expr " << expr std::cout << "CUDA driver API error: code " << code << ", expr " << expr
<< ", file " << file << ", line " << line << endl; << ", file " << file << ", line " << line << endl;
destroyContexts(); destroyContexts();
exit(-1); exit(-1);
@ -59,7 +59,7 @@ int main()
int num_devices = getCudaEnabledDeviceCount(); int num_devices = getCudaEnabledDeviceCount();
if (num_devices < 2) if (num_devices < 2)
{ {
cout << "Two or more GPUs are required\n"; std::cout << "Two or more GPUs are required\n";
return -1; return -1;
} }
@ -68,7 +68,7 @@ int main()
DeviceInfo dev_info(i); DeviceInfo dev_info(i);
if (!dev_info.isCompatible()) if (!dev_info.isCompatible())
{ {
cout << "GPU module isn't built for GPU #" << i << " (" std::cout << "GPU module isn't built for GPU #" << i << " ("
<< dev_info.name() << ", CC " << dev_info.majorVersion() << dev_info.name() << ", CC " << dev_info.majorVersion()
<< dev_info.minorVersion() << "\n"; << dev_info.minorVersion() << "\n";
return -1; return -1;
@ -122,7 +122,7 @@ void Worker::operator()(int device_id) const
// Check results // Check results
bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3; bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3;
cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): " std::cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): "
<< (passed ? "passed" : "FAILED") << endl; << (passed ? "passed" : "FAILED") << endl;
// Deallocate data here, otherwise deallocation will be performed // Deallocate data here, otherwise deallocation will be performed

View File

@ -18,11 +18,11 @@
int main() int main()
{ {
#if !defined(HAVE_CUDA) #if !defined(HAVE_CUDA)
cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n"; std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n";
#endif #endif
#if !defined(HAVE_TBB) #if !defined(HAVE_TBB)
cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n"; std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n";
#endif #endif
return 0; return 0;
@ -46,7 +46,7 @@ inline void safeCall_(int code, const char* expr, const char* file, int line)
{ {
if (code != CUDA_SUCCESS) if (code != CUDA_SUCCESS)
{ {
cout << "CUDA driver API error: code " << code << ", expr " << expr std::cout << "CUDA driver API error: code " << code << ", expr " << expr
<< ", file " << file << ", line " << line << endl; << ", file " << file << ", line " << line << endl;
destroyContexts(); destroyContexts();
exit(-1); exit(-1);
@ -80,14 +80,14 @@ int main(int argc, char** argv)
{ {
if (argc < 3) if (argc < 3)
{ {
cout << "Usage: stereo_multi_gpu <left_image> <right_image>\n"; std::cout << "Usage: stereo_multi_gpu <left_image> <right_image>\n";
return -1; return -1;
} }
int num_devices = getCudaEnabledDeviceCount(); int num_devices = getCudaEnabledDeviceCount();
if (num_devices < 2) if (num_devices < 2)
{ {
cout << "Two or more GPUs are required\n"; std::cout << "Two or more GPUs are required\n";
return -1; return -1;
} }
@ -96,7 +96,7 @@ int main(int argc, char** argv)
DeviceInfo dev_info(i); DeviceInfo dev_info(i);
if (!dev_info.isCompatible()) if (!dev_info.isCompatible())
{ {
cout << "GPU module isn't built for GPU #" << i << " (" std::cout << "GPU module isn't built for GPU #" << i << " ("
<< dev_info.name() << ", CC " << dev_info.majorVersion() << dev_info.name() << ", CC " << dev_info.majorVersion()
<< dev_info.minorVersion() << "\n"; << dev_info.minorVersion() << "\n";
return -1; return -1;
@ -108,12 +108,12 @@ int main(int argc, char** argv)
Mat right = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE); Mat right = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if (left.empty()) if (left.empty())
{ {
cout << "Cannot open '" << argv[1] << "'\n"; std::cout << "Cannot open '" << argv[1] << "'\n";
return -1; return -1;
} }
if (right.empty()) if (right.empty())
{ {
cout << "Cannot open '" << argv[2] << "'\n"; std::cout << "Cannot open '" << argv[2] << "'\n";
return -1; return -1;
} }
@ -180,7 +180,7 @@ void Worker::operator()(int device_id) const
bm[device_id]->operator()(d_left[device_id], d_right[device_id], bm[device_id]->operator()(d_left[device_id], d_right[device_id],
d_result[device_id]); d_result[device_id]);
cout << "GPU #" << device_id << " (" << DeviceInfo().name() std::cout << "GPU #" << device_id << " (" << DeviceInfo().name()
<< "): finished\n"; << "): finished\n";
contextOff(); contextOff();

View File

@ -16,11 +16,11 @@
int main() int main()
{ {
#if !defined(HAVE_CUDA) #if !defined(HAVE_CUDA)
cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n"; std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n";
#endif #endif
#if !defined(HAVE_TBB) #if !defined(HAVE_TBB)
cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n"; std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n";
#endif #endif
return 0; return 0;
@ -43,7 +43,7 @@ int main()
int num_devices = getCudaEnabledDeviceCount(); int num_devices = getCudaEnabledDeviceCount();
if (num_devices < 2) if (num_devices < 2)
{ {
cout << "Two or more GPUs are required\n"; std::cout << "Two or more GPUs are required\n";
return -1; return -1;
} }
for (int i = 0; i < num_devices; ++i) for (int i = 0; i < num_devices; ++i)
@ -51,7 +51,7 @@ int main()
DeviceInfo dev_info(i); DeviceInfo dev_info(i);
if (!dev_info.isCompatible()) if (!dev_info.isCompatible())
{ {
cout << "GPU module isn't built for GPU #" << i << " (" std::cout << "GPU module isn't built for GPU #" << i << " ("
<< dev_info.name() << ", CC " << dev_info.majorVersion() << dev_info.name() << ", CC " << dev_info.majorVersion()
<< dev_info.minorVersion() << "\n"; << dev_info.minorVersion() << "\n";
return -1; return -1;
@ -88,7 +88,7 @@ void Worker::operator()(int device_id) const
// Check results // Check results
bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3; bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3;
cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): " std::cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): "
<< (passed ? "passed" : "FAILED") << endl; << (passed ? "passed" : "FAILED") << endl;
// Deallocate data here, otherwise deallocation will be performed // Deallocate data here, otherwise deallocation will be performed

View File

@ -18,11 +18,11 @@
int main() int main()
{ {
#if !defined(HAVE_CUDA) #if !defined(HAVE_CUDA)
cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n"; std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n";
#endif #endif
#if !defined(HAVE_TBB) #if !defined(HAVE_TBB)
cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n"; std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n";
#endif #endif
return 0; return 0;
@ -53,14 +53,14 @@ int main(int argc, char** argv)
{ {
if (argc < 3) if (argc < 3)
{ {
cout << "Usage: stereo_multi_gpu <left_image> <right_image>\n"; std::cout << "Usage: stereo_multi_gpu <left_image> <right_image>\n";
return -1; return -1;
} }
int num_devices = getCudaEnabledDeviceCount(); int num_devices = getCudaEnabledDeviceCount();
if (num_devices < 2) if (num_devices < 2)
{ {
cout << "Two or more GPUs are required\n"; std::cout << "Two or more GPUs are required\n";
return -1; return -1;
} }
for (int i = 0; i < num_devices; ++i) for (int i = 0; i < num_devices; ++i)
@ -68,7 +68,7 @@ int main(int argc, char** argv)
DeviceInfo dev_info(i); DeviceInfo dev_info(i);
if (!dev_info.isCompatible()) if (!dev_info.isCompatible())
{ {
cout << "GPU module isn't built for GPU #" << i << " (" std::cout << "GPU module isn't built for GPU #" << i << " ("
<< dev_info.name() << ", CC " << dev_info.majorVersion() << dev_info.name() << ", CC " << dev_info.majorVersion()
<< dev_info.minorVersion() << "\n"; << dev_info.minorVersion() << "\n";
return -1; return -1;
@ -80,12 +80,12 @@ int main(int argc, char** argv)
Mat right = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE); Mat right = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if (left.empty()) if (left.empty())
{ {
cout << "Cannot open '" << argv[1] << "'\n"; std::cout << "Cannot open '" << argv[1] << "'\n";
return -1; return -1;
} }
if (right.empty()) if (right.empty())
{ {
cout << "Cannot open '" << argv[2] << "'\n"; std::cout << "Cannot open '" << argv[2] << "'\n";
return -1; return -1;
} }
@ -139,7 +139,7 @@ void Worker::operator()(int device_id) const
bm[device_id]->operator()(d_left[device_id], d_right[device_id], bm[device_id]->operator()(d_left[device_id], d_right[device_id],
d_result[device_id]); d_result[device_id]);
cout << "GPU #" << device_id << " (" << DeviceInfo().name() std::cout << "GPU #" << device_id << " (" << DeviceInfo().name()
<< "): finished\n"; << "): finished\n";
multi_gpu_mgr.gpuOff(); multi_gpu_mgr.gpuOff();

View File

@ -55,7 +55,6 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
using namespace std;
using namespace cv; using namespace cv;
#define CV_NBAYES "nbayes" #define CV_NBAYES "nbayes"
@ -83,13 +82,13 @@ protected:
virtual int validate_test_results( int testCaseIdx ) = 0; virtual int validate_test_results( int testCaseIdx ) = 0;
int train( int testCaseIdx ); int train( int testCaseIdx );
float get_error( int testCaseIdx, int type, vector<float> *resp = 0 ); float get_error( int testCaseIdx, int type, std::vector<float> *resp = 0 );
void save( const char* filename ); void save( const char* filename );
void load( const char* filename ); void load( const char* filename );
CvMLData data; CvMLData data;
string modelName, validationFN; string modelName, validationFN;
vector<string> dataSetNames; std::vector<string> dataSetNames;
FileStorage validationFS; FileStorage validationFS;
// MLL models // MLL models
@ -103,7 +102,7 @@ protected:
CvRTrees* rtrees; CvRTrees* rtrees;
CvERTrees* ertrees; CvERTrees* ertrees;
map<int, int> cls_map; std::map<int, int> cls_map;
int64 initSeed; int64 initSeed;
}; };
@ -125,7 +124,7 @@ protected:
virtual int run_test_case( int testCaseIdx ); virtual int run_test_case( int testCaseIdx );
virtual int validate_test_results( int testCaseIdx ); virtual int validate_test_results( int testCaseIdx );
vector<float> test_resps1, test_resps2; // predicted responses for test data std::vector<float> test_resps1, test_resps2; // predicted responses for test data
char fname1[50], fname2[50]; char fname1[50], fname2[50];
}; };