Merge pull request #17722 from pemmanuelviel:pev--replace-asserts
* Clean: replace C style asserts by CV_Assert and CV_DbgAssert * Try fixing warning on Windows compilation * Another way trying to fix warnings on Win * Fixing warnings with some compilers: Some compilers warn on systematic exit preventing to execute the code that follows. This is why assert(0) that exits only in debug was working, but not CV_Assert or CV_Error that exit both in release and debug, even if with different behavior. In addition, other compilers complain when return 0 is removed from getKey(), even if before we have a statement leading to systematic exit. * Disable "unreachable code" warnings for Win compilers so we can use proper CV_Error
This commit is contained in:
parent
8f5b453a96
commit
65f87b114b
@ -497,7 +497,7 @@ private:
|
||||
const int nn = 1;
|
||||
const size_t SAMPLE_COUNT = 1000;
|
||||
|
||||
assert(bestIndex_ != NULL); // must have a valid index
|
||||
CV_Assert(bestIndex_ != NULL && "Requires a valid index"); // must have a valid index
|
||||
|
||||
float speedup = 0;
|
||||
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
//! @cond IGNORED
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
#include "general.h"
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
@ -153,7 +152,7 @@ private:
|
||||
int n = indices_length;
|
||||
|
||||
int rnd = rand_int(n);
|
||||
assert(rnd >=0 && rnd < n);
|
||||
CV_DbgAssert(rnd >=0 && rnd < n);
|
||||
|
||||
centers[0] = dsindices[rnd];
|
||||
|
||||
@ -208,7 +207,7 @@ private:
|
||||
|
||||
// Choose one random center and set the closestDistSq values
|
||||
int index = rand_int(n);
|
||||
assert(index >=0 && index < n);
|
||||
CV_DbgAssert(index >=0 && index < n);
|
||||
centers[0] = dsindices[index];
|
||||
|
||||
// Computing distance^2 will have the advantage of even higher probability further to pick new centers
|
||||
@ -295,7 +294,7 @@ private:
|
||||
|
||||
// Choose one random center and set the closestDistSq values
|
||||
int index = rand_int(n);
|
||||
assert(index >=0 && index < n);
|
||||
CV_DbgAssert(index >=0 && index < n);
|
||||
centers[0] = dsindices[index];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
@ -564,10 +563,10 @@ public:
|
||||
NodePtr node = branch.node;
|
||||
findNN(node, result, vec, checks, maxChecks, heap, checked);
|
||||
}
|
||||
assert(result.full());
|
||||
|
||||
delete heap;
|
||||
|
||||
CV_Assert(result.full());
|
||||
}
|
||||
|
||||
IndexParams getParameters() const CV_OVERRIDE
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
//! @cond IGNORED
|
||||
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
#include "matrix.h"
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "general.h"
|
||||
@ -433,7 +432,7 @@ private:
|
||||
if (trees_>0) {
|
||||
searchLevelExact(result, vec, tree_roots_[0], 0.0, epsError);
|
||||
}
|
||||
assert(result.full());
|
||||
CV_Assert(result.full());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -462,7 +461,7 @@ private:
|
||||
|
||||
delete heap;
|
||||
|
||||
assert(result.full());
|
||||
CV_Assert(result.full());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "general.h"
|
||||
@ -214,11 +213,11 @@ public:
|
||||
*/
|
||||
void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params) CV_OVERRIDE
|
||||
{
|
||||
assert(queries.cols == veclen());
|
||||
assert(indices.rows >= queries.rows);
|
||||
assert(dists.rows >= queries.rows);
|
||||
assert(int(indices.cols) >= knn);
|
||||
assert(int(dists.cols) >= knn);
|
||||
CV_Assert(queries.cols == veclen());
|
||||
CV_Assert(indices.rows >= queries.rows);
|
||||
CV_Assert(dists.rows >= queries.rows);
|
||||
CV_Assert(int(indices.cols) >= knn);
|
||||
CV_Assert(int(dists.cols) >= knn);
|
||||
|
||||
KNNSimpleResultSet<DistanceType> resultSet(knn);
|
||||
for (size_t i = 0; i < queries.rows; i++) {
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
@ -152,7 +151,7 @@ public:
|
||||
int n = indices_length;
|
||||
|
||||
int rnd = rand_int(n);
|
||||
assert(rnd >=0 && rnd < n);
|
||||
CV_DbgAssert(rnd >=0 && rnd < n);
|
||||
|
||||
centers[0] = indices[rnd];
|
||||
|
||||
@ -207,7 +206,7 @@ public:
|
||||
|
||||
// Choose one random center and set the closestDistSq values
|
||||
int index = rand_int(n);
|
||||
assert(index >=0 && index < n);
|
||||
CV_DbgAssert(index >=0 && index < n);
|
||||
centers[0] = indices[index];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
@ -502,9 +501,9 @@ public:
|
||||
KMeansNodePtr node = branch.node;
|
||||
findNN(node, result, vec, checks, maxChecks, heap);
|
||||
}
|
||||
assert(result.full());
|
||||
|
||||
delete heap;
|
||||
|
||||
CV_Assert(result.full());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,7 +38,6 @@
|
||||
//! @cond IGNORED
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@ -53,6 +52,11 @@
|
||||
#include "random.h"
|
||||
#include "saving.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4702) //disable unreachable code
|
||||
#endif
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
|
||||
@ -191,11 +195,11 @@ public:
|
||||
*/
|
||||
virtual void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params) CV_OVERRIDE
|
||||
{
|
||||
assert(queries.cols == veclen());
|
||||
assert(indices.rows >= queries.rows);
|
||||
assert(dists.rows >= queries.rows);
|
||||
assert(int(indices.cols) >= knn);
|
||||
assert(int(dists.cols) >= knn);
|
||||
CV_Assert(queries.cols == veclen());
|
||||
CV_Assert(indices.rows >= queries.rows);
|
||||
CV_Assert(dists.rows >= queries.rows);
|
||||
CV_Assert(int(indices.cols) >= knn);
|
||||
CV_Assert(int(dists.cols) >= knn);
|
||||
|
||||
|
||||
KNNUniqueResultSet<DistanceType> resultSet(knn);
|
||||
@ -391,6 +395,10 @@ private:
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif //OPENCV_FLANN_LSH_INDEX_H_
|
||||
|
||||
@ -58,6 +58,12 @@
|
||||
#include "dynamic_bitset.h"
|
||||
#include "matrix.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4702) //disable unreachable code
|
||||
#endif
|
||||
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
|
||||
@ -162,8 +168,7 @@ public:
|
||||
{
|
||||
feature_size_ = feature_size;
|
||||
CV_UNUSED(key_size);
|
||||
std::cerr << "LSH is not implemented for that type" << std::endl;
|
||||
assert(0);
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "LSH is not implemented for that type" );
|
||||
}
|
||||
|
||||
/** Add a feature to the table
|
||||
@ -243,8 +248,7 @@ public:
|
||||
*/
|
||||
size_t getKey(const ElementType* /*feature*/) const
|
||||
{
|
||||
std::cerr << "LSH is not implemented for that type" << std::endl;
|
||||
assert(0);
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "LSH is not implemented for that type" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -510,6 +514,10 @@ inline LshStats LshTable<unsigned char>::getStats() const
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! @endcond
|
||||
|
||||
@ -69,11 +69,11 @@ public:
|
||||
*/
|
||||
virtual void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params)
|
||||
{
|
||||
assert(queries.cols == veclen());
|
||||
assert(indices.rows >= queries.rows);
|
||||
assert(dists.rows >= queries.rows);
|
||||
assert(int(indices.cols) >= knn);
|
||||
assert(int(dists.cols) >= knn);
|
||||
CV_Assert(queries.cols == veclen());
|
||||
CV_Assert(indices.rows >= queries.rows);
|
||||
CV_Assert(dists.rows >= queries.rows);
|
||||
CV_Assert(int(indices.cols) >= knn);
|
||||
CV_Assert(int(dists.cols) >= knn);
|
||||
|
||||
#if 0
|
||||
KNNResultSet<DistanceType> resultSet(knn);
|
||||
|
||||
@ -72,7 +72,7 @@ float optimizeSimplexDownhill(T* points, int n, F func, float* vals = NULL )
|
||||
{
|
||||
const int MAX_ITERATIONS = 10;
|
||||
|
||||
assert(n>0);
|
||||
CV_DbgAssert(n>0);
|
||||
|
||||
T* p_o = new T[n];
|
||||
T* p_r = new T[n];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user