#include "precomp.hpp"
#include "fisheye.hpp"
+#include <limits>
namespace cv { namespace
{
//-------------------------------Optimization
- for(int iter = 0; ; ++iter)
+ for(int iter = 0; iter <= std::numeric_limits<int>::max(); ++iter)
{
if ((criteria.type == 1 && iter >= criteria.maxCount) ||
(criteria.type == 2 && change <= criteria.epsilon) ||
{
if( this != &parser )
{
+ CV_XADD(&parser.impl->refcount, 1);
if(CV_XADD(&impl->refcount, -1) == 1)
delete impl;
impl = parser.impl;
- CV_XADD(&impl->refcount, 1);
}
return *this;
}
}
_dst.create( dims, size.p, type() );
UMat dst = _dst.getUMat();
-
+ CV_Assert(dst.u != NULL);
size_t i, sz[CV_MAX_DIM] = {0}, dstofs[CV_MAX_DIM], esz = elemSize();
+ CV_Assert(dims >= 0 && dims < CV_MAX_DIM);
for( i = 0; i < (size_t)dims; i++ )
sz[i] = size.p[i];
sz[dims-1] *= esz;
CV_IMPL void
cvSetRemove( CvSet* set, int index )
{
+ CV_Assert(set != NULL);
CvSetElem* elem = cvGetSetElem( set, index );
if( elem )
cvSetRemoveByPtr( set, elem );
int Mat::checkVector(int _elemChannels, int _depth, bool _requireContinuous) const
{
- return (depth() == _depth || _depth <= 0) &&
+ return data && (depth() == _depth || _depth <= 0) &&
(isContinuous() || !_requireContinuous) &&
((dims == 2 && (((rows == 1 || cols == 1) && channels() == _elemChannels) ||
(cols == _elemChannels && channels() == 1))) ||
if( !map_node )
map_node = (CvFileNode*)cvGetSeqElem( fs->roots, k );
-
+ CV_Assert(map_node != NULL);
if( !CV_NODE_IS_MAP(map_node->tag) )
{
if( (!CV_NODE_IS_SEQ(map_node->tag) || map_node->data.seq->total != 0) &&
CvSeqReader reader;
node = (CvFileNode*)cvGetSeqElem( (*fs)->roots, k );
+ CV_Assert(node != NULL);
if( !CV_NODE_IS_MAP( node->tag ))
return 0;
seq = node->data.seq;
Mutex& Mutex::operator = (const Mutex& m)
{
- CV_XADD(&m.impl->refcount, 1);
- if( CV_XADD(&impl->refcount, -1) == 1 )
- delete impl;
- impl = m.impl;
+ if (this != &m)
+ {
+ CV_XADD(&m.impl->refcount, 1);
+ if( CV_XADD(&impl->refcount, -1) == 1 )
+ delete impl;
+ impl = m.impl;
+ }
return *this;
}
ittHandle_name = __itt_string_handle_create(location.name);
ittHandle_filename = __itt_string_handle_create(location.filename);
}
+ else
+ {
+ ittHandle_name = 0;
+ ittHandle_filename = 0;
+ }
#endif
}
// Consecutive calls to __itt_string_handle_create with the same name return the same value.
ittHandle_name = __itt_string_handle_create(arg.name);
}
+ else
+ {
+ ittHandle_name = 0;
+ }
#endif
}
};
struct LayerData
{
- LayerData() {}
+ LayerData() : id(-1), flag(0) {}
LayerData(int _id, const String &_name, const String &_type, LayerParams &_params)
- : id(_id), name(_name), type(_type), params(_params)
+ : id(_id), name(_name), type(_type), params(_params), flag(0)
{
//add logging info
params.name = name;
bool is1x1_;
bool useAVX2;
- ParallelConv() {}
+ ParallelConv()
+ : input_(0), weights_(0), output_(0), ngroups_(0), nstripes_(0),
+ is1x1_(false), useAVX2(false)
+ {}
static void run( const Mat& input, Mat& output, const Mat& weights,
const std::vector<float>& biasvec,
int nstripes;
bool is1x1;
- Col2ImInvoker() {}
+ Col2ImInvoker()
+ : data_col(0), biasvec(0), channels(0), height(0), width(0),
+ kernel_h(0), kernel_w(0), pad_h(0), pad_w(0), stride_h(0), stride_w(0), data_im(0),
+ height_col(0), width_col(0), nstripes(0), is1x1(0)
+ {}
static void run(const float* data_col,
int channels, int height, int width,
}
};
- ElementWiseLayer(const Func &f=Func()) { func = f; }
+ ElementWiseLayer(const Func &f=Func()) : run_parallel(false) { func = f; }
virtual bool supportBackend(int backendId)
{
}
PermuteLayerImpl(const LayerParams ¶ms)
+ : _count(0), _needsPermute(false), _numAxes(0)
{
if (!params.has("order"))
{
- _needsPermute = false;
return;
}
}
PriorBoxLayerImpl(const LayerParams ¶ms)
+ : _boxWidth(0), _boxHeight(0)
{
setParamsFrom(params);
_minSize = getParameter<unsigned>(params, "min_size");
public:
LSTMLayerImpl(const LayerParams& params)
+ : numTimeStamps(0), numSamples(0)
{
setParamsFrom(params);
type = "LSTM";
public:
RNNLayerImpl(const LayerParams& params)
+ : numX(0), numH(0), numO(0), numSamples(0), numTimestamps(0), numSamplesTotal(0), dtype(0)
{
setParamsFrom(params);
type = "RNN";
total += TBRS_BSZ;
p = (char*)THRealloc(p, total);
}
+ if (p == NULL)
+ THError("read error: failed to allocate buffer");
if (fgets(p+pos, total-pos, dfself->handle) == NULL) /* eof? */
{
if(pos == 0L)
return mergeId;
}
else if (module->thName == "ConcatTable") {
- int newId, splitId;
+ int newId = -1, splitId;
LayerParams splitParams;
splitId = net.addLayer(generateLayerName("torchSplit"), "Split", splitParams);
const BriskLongPair* max = longPairs_ + noLongPairs_;
for (BriskLongPair* iter = longPairs_; iter < max; ++iter)
{
+ CV_Assert(iter->i < points_ && iter->j < points_);
t1 = *(_values + iter->i);
t2 = *(_values + iter->j);
const int delta_t = (t1 - t2);
}
IndexHeader header = load_header(fin);
if (header.data_type != Datatype<ElementType>::type()) {
+ fclose(fin);
throw FLANNException("Datatype of saved index is different than of the one to be created.");
}
if ((size_t(header.rows) != dataset.rows)||(size_t(header.cols) != dataset.cols)) {
+ fclose(fin);
throw FLANNException("The index saved belongs to a different dataset");
}
if( pos > trackbar->maxval )
pos = trackbar->maxval;
}
+ else
+ {
+ CV_ERROR( CV_StsNullPtr, "No trackbar found" );
+ }
CV_LOCK_MUTEX();
{
m_start = m_end = m_current = 0;
m_file = 0;
+ m_block_pos = 0;
m_block_size = BS_DEF_BLOCK_SIZE;
m_is_opened = false;
m_allocated = false;
xstep = m_native_depth ? 4 : 1;
+ AutoBuffer<char> copy_buffer;
+
if( !m_native_depth || (!color && m_iscolor ))
{
- buffer = (char *)new float[ m_width * 3 ];
+ copy_buffer.allocate(sizeof(float) * m_width * 3);
+ buffer = copy_buffer;
ystep = 0;
}
else
close();
- if( !m_native_depth || (!color && m_iscolor ))
- {
- delete[] buffer;
- }
-
return result;
}
if (index & 0x10)
{
- index -= 0x10;
+ index &= ~0x10;
hufftbl = &ac_tables[index];
}
else
int prev_s = -1, s, s_end;
int method = _method - 1;
- assert( (unsigned) _method <= CV_CHAIN_APPROX_SIMPLE );
+ CV_DbgAssert( (unsigned) _method <= CV_CHAIN_APPROX_SIMPLE );
/* initialize local state */
CV_INIT_3X3_DELTAS( deltas, step, 1 );
else
{
i3 = i0;
+ CV_Assert(i3 != NULL);
prev_s = s ^ 4;
/* follow border */
while( s < MAX_SIZE - 1 )
{
i4 = i3 + deltas[++s];
+ CV_Assert(i4 != NULL);
if( *i4 != 0 )
break;
}
if( _method != CV_CHAIN_CODE )
cvBoundingRect( contour, 1 );
- assert( (writer.seq->total == 0 && writer.seq->first == 0) ||
+ CV_DbgAssert( (writer.seq->total == 0 && writer.seq->first == 0) ||
writer.seq->total > writer.seq->first->count ||
(writer.seq->first->prev == writer.seq->first &&
writer.seq->first->next == writer.seq->first) );
CV_INIT_3X3_DELTAS( deltas, step, 1 );
memcpy( deltas + 8, deltas, 8 * sizeof( deltas[0] ));
- assert( (*i0 & -2) != 0 );
+ CV_DbgAssert( (*i0 & -2) != 0 );
s_end = s = is_hole ? 0 : 4;
while( *i1 == 0 && s != s_end );
i3 = i0;
+ CV_Assert(i3 != NULL);
/* check single pixel domain */
if( s != s_end )
while( s < MAX_SIZE - 1 )
{
i4 = i3 + deltas[++s];
+ CV_Assert(i4 != NULL);
if( *i4 != 0 )
break;
}
int prev_s = -1, s, s_end;
int method = _method - 1;
- assert( (unsigned) _method <= CV_CHAIN_APPROX_SIMPLE );
- assert( 1 < nbd && nbd < 128 );
+ CV_DbgAssert( (unsigned) _method <= CV_CHAIN_APPROX_SIMPLE );
+ CV_DbgAssert( 1 < nbd && nbd < 128 );
/* initialize local state */
CV_INIT_3X3_DELTAS( deltas, step, 1 );
if( _method != CV_CHAIN_CODE )
((CvContour*)contour)->rect = rect;
- assert( (writer.seq->total == 0 && writer.seq->first == 0) ||
+ CV_DbgAssert( (writer.seq->total == 0 && writer.seq->first == 0) ||
writer.seq->total > writer.seq->first->count ||
(writer.seq->first->prev == writer.seq->first &&
writer.seq->first->next == writer.seq->first) );
const int nbd0 = ccomp_val | new_flag;
const int nbd1 = nbd0 | right_flag;
- assert( (unsigned) _method <= CV_CHAIN_APPROX_SIMPLE );
+ CV_DbgAssert( (unsigned) _method <= CV_CHAIN_APPROX_SIMPLE );
/* initialize local state */
CV_INIT_3X3_DELTAS( deltas, step, 1 );
if( _method != CV_CHAIN_CODE )
((CvContour*)contour)->rect = rect;
- assert( (writer.seq->total == 0 && writer.seq->first == 0) ||
+ CV_DbgAssert( (writer.seq->total == 0 && writer.seq->first == 0) ||
writer.seq->total > writer.seq->first->count ||
(writer.seq->first->prev == writer.seq->first &&
writer.seq->first->next == writer.seq->first) );
}
/* remove the leaving basic variable */
+ CV_Assert(leave_x != NULL);
i = leave_x->i;
j = leave_x->j;
state->is_x[i][j] = 0;
void BaseFilter::reset() {}
FilterEngine::FilterEngine()
+ : srcType(-1), dstType(-1), bufType(-1), maxWidth(0), wholeSize(-1, -1), dx1(0), dx2(0),
+ rowBorderType(BORDER_REPLICATE), columnBorderType(BORDER_REPLICATE),
+ borderElemSize(0), bufStep(0), startY(0), startY0(0), endY(0), rowCount(0), dstY(0)
{
- srcType = dstType = bufType = -1;
- rowBorderType = columnBorderType = BORDER_REPLICATE;
- bufStep = startY = startY0 = endY = rowCount = dstY = 0;
- maxWidth = 0;
-
- wholeSize = Size(-1,-1);
- dx1 = 0;
- borderElemSize = 0;
- dx2 = 0;
}
int _srcType, int _dstType, int _bufType,
int _rowBorderType, int _columnBorderType,
const Scalar& _borderValue )
+ : srcType(-1), dstType(-1), bufType(-1), maxWidth(0), wholeSize(-1, -1), dx1(0), dx2(0),
+ rowBorderType(BORDER_REPLICATE), columnBorderType(BORDER_REPLICATE),
+ borderElemSize(0), bufStep(0), startY(0), startY0(0), endY(0), rowCount(0), dstY(0)
{
- startY0 = 0;
- endY = 0;
- dstY = 0;
- dx2 = 0;
- rowCount = 0;
init(_filter2D, _rowFilter, _columnFilter, _srcType, _dstType, _bufType,
_rowBorderType, _columnBorderType, _borderValue);
}
srcRow.resize(esz*(maxWidth + ksize.width - 1));
if( columnBorderType == BORDER_CONSTANT )
{
+ CV_Assert(constVal != NULL);
constBorderRow.resize(getElemSize(bufType)*(maxWidth + ksize.width - 1 + VEC_ALIGN));
uchar *dst = alignPtr(&constBorderRow[0], VEC_ALIGN), *tdst;
int n = (int)constBorderValue.size(), N;
{
if( rowBorderType == BORDER_CONSTANT )
{
+ CV_Assert(constVal != NULL);
int nr = isSeparable() ? 1 : (int)rows.size();
for( i = 0; i < nr; i++ )
{
}
}
}
+ CV_Assert(leftmost != NULL);
leftmost->taken = true;
// Find rightmost untaken point;
}
}
}
+ CV_Assert(rightmost != NULL);
rightmost->taken = true;
// Find last untaken point;
}
}
}
+ CV_Assert(tailp != NULL);
tailp->taken = true;
double flstep = (min_y->p.y != leftmost->p.y) ?
h_fine[ 16 * (n*(16*c+(x>>4)) + j) + (x & 0xF) ] op
int cn = _dst.channels(), m = _dst.rows, r = (ksize-1)/2;
+ CV_Assert(cn > 0 && cn <= 4);
size_t sstep = _src.step, dstep = _dst.step;
Histogram CV_DECL_ALIGNED(16) H[4];
HT CV_DECL_ALIGNED(16) luc[4][16];
int src_step = (int)_src.step, dst_step = (int)_dst.step;
int cn = _src.channels();
const uchar* src_max = src + size.height*src_step;
+ CV_Assert(cn > 0 && cn <= 4);
#define UPDATE_ACC01( pix, cn, op ) \
{ \
templNorm = std::sqrt(templNorm);
templNorm /= std::sqrt(invArea); // care of accuracy here
+ CV_Assert(sqsum.data != NULL);
q0 = (double*)sqsum.data;
q1 = q0 + templ.cols*cn;
q2 = (double*)(sqsum.data + templ.rows*sqsum.step);
q3 = q2 + templ.cols*cn;
}
+ CV_Assert(sum.data != NULL);
double* p0 = (double*)sum.data;
double* p1 = p0 + templ.cols*cn;
double* p2 = (double*)(sum.data + templ.rows*sum.step);
CV_Error( CV_StsBadArg,
"one of input categorical variable is not an integer" );
+ CV_Assert(cmap != NULL);
while( a < b )
{
c = (a + b) >> 1;
}
};
//new grouping function with using meanshift
-static void groupRectangles_meanshift(std::vector<Rect>& rectList, double detectThreshold, std::vector<double>* foundWeights,
+static void groupRectangles_meanshift(std::vector<Rect>& rectList, double detectThreshold, std::vector<double>& foundWeights,
std::vector<double>& scales, Size winDetSize)
{
int detectionCount = (int)rectList.size();
for (int i=0; i < detectionCount; i++)
{
- hitWeights[i] = (*foundWeights)[i];
+ hitWeights[i] = foundWeights[i];
hitCenter = (rectList[i].tl() + rectList[i].br())*(0.5); //center of rectangles
hits[i] = Point3d(hitCenter.x, hitCenter.y, std::log(scales[i]));
}
rectList.clear();
- if (foundWeights)
- foundWeights->clear();
+ foundWeights.clear();
double logZ = std::log(1.3);
Point3d smothing(8, 16, logZ);
if (resultWeights[i] > detectThreshold)
{
rectList.push_back(resultRect);
- foundWeights->push_back(resultWeights[i]);
+ foundWeights.push_back(resultWeights[i]);
}
}
}
{
CV_INSTRUMENT_REGION()
- groupRectangles_meanshift(rectList, detectThreshold, &foundWeights, foundScales, winDetSize);
+ groupRectangles_meanshift(rectList, detectThreshold, foundWeights, foundScales, winDetSize);
}
}
if(pNxtN != pCurN->pParent)
{
+ CV_Assert(pNxtN != NULL);
pNxtE = pNxtN->pChild;
if(pNxtE && pNxtE->pChild==pCurN) // has connection
{
findLoopFromEnterBV();
// Modify flow values along the loop
cvPEmdEdge pE = NULL;
+ CV_Assert(m_pLeave != NULL);
float minFlow = m_pLeave->flow;
int k;
for(k=0; k<m_iFrom; k++)
{
CV_OCL_RUN(_dst.isUMat(),
ocl_calcBtvRegularization(_src, _dst, btvKernelSize, ubtvWeights))
- (void)ubtvWeights;
-
- typedef void (*func_t)(InputArray _src, OutputArray _dst, int btvKernelSize, const std::vector<float>& btvWeights);
- static const func_t funcs[] =
+ CV_UNUSED(ubtvWeights);
+ if (_src.channels() == 1)
{
- 0, calcBtvRegularizationImpl<float>, 0, calcBtvRegularizationImpl<Point3f>, 0
- };
-
- const func_t func = funcs[_src.channels()];
- CV_Assert(func != 0);
- func(_src, _dst, btvKernelSize, btvWeights);
+ calcBtvRegularizationImpl<float>(_src, _dst, btvKernelSize, btvWeights);
+ }
+ else if (_src.channels() == 3)
+ {
+ calcBtvRegularizationImpl<Point3f>(_src, _dst, btvKernelSize, btvWeights);
+ }
+ else
+ {
+ CV_Error(Error::StsBadArg, "Unsupported number of channels in _src");
+ }
}
class BTVL1_Base : public cv::superres::SuperResolution
void convertToDepth(InputArray src, OutputArray dst, int depth)
{
- CV_Assert( src.depth() <= CV_64F );
+ const int sdepth = src.depth();
+ CV_Assert( sdepth <= CV_64F );
CV_Assert( depth == CV_8U || depth == CV_32F );
- static const double maxVals[] =
+ static const double maxVals[CV_64F + 1] =
{
(double)std::numeric_limits<uchar>::max(),
(double)std::numeric_limits<schar>::max(),
1.0,
};
- const double scale = maxVals[depth] / maxVals[src.depth()];
+ const double scale = maxVals[depth] / maxVals[sdepth];
switch (src.kind())
{
prevDelta = delta;
}
+ CV_Assert(status != NULL);
if( status[ptidx] && err && level == 0 && (flags & OPTFLOW_LK_GET_MIN_EIGENVALS) == 0 )
{
Point2f nextPoint = nextPts[ptidx] - halfWin;
char *at = strchr(name, '%');
if(at)
{
- int dummy;
+ unsigned int dummy;
if(sscanf(at + 1, "%ud", &dummy) != 1)
return 0;
name = strdup(filename);
int size = (int)strlen(filename) + 20;
name = (char *)malloc(size);
+ CV_Assert(name != NULL);
strncpy(name, filename, at - filename);
name[at - filename] = 0;
char *extension;
for(i = 0, extension = at; isdigit(at[i]); i++, extension++)
;
- char places[10];
+ char places[13] = {0};
sprintf(places, "%dd", i);
strcat(name, places);