Skip to content

Commit

Permalink
Merge pull request opencv#18243 from alalek:static_code_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Sep 2, 2020
2 parents 6426101 + 71f665b commit 5ae9892
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 42 deletions.
5 changes: 5 additions & 0 deletions modules/calib3d/src/calibinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ int ChessBoardDetector::orderFoundConnectedQuads(std::vector<ChessBoardQuad*>& q

for (int i = 0; i < 4; i++)
{
CV_DbgAssert(q);
ChessBoardQuad *neighbor = q->neighbors[i];
switch(i) // adjust col, row for this quad
{ // start at top left, go clockwise
Expand Down Expand Up @@ -1271,6 +1272,7 @@ int ChessBoardDetector::cleanFoundConnectedQuads(std::vector<ChessBoardQuad*>& q
for (int i = 0; i < quad_count; ++i)
{
ChessBoardQuad *q = quad_group[i];
CV_DbgAssert(q);
for (int j = 0; j < 4; ++j)
{
if (q->neighbors[j] == q0)
Expand Down Expand Up @@ -1328,6 +1330,7 @@ void ChessBoardDetector::findConnectedQuads(std::vector<ChessBoardQuad*>& out_gr
stack.pop();
for (int k = 0; k < 4; k++ )
{
CV_DbgAssert(q);
ChessBoardQuad *neighbor = q->neighbors[k];
if (neighbor && neighbor->count > 0 && neighbor->group_idx < 0 )
{
Expand Down Expand Up @@ -1716,6 +1719,7 @@ void ChessBoardDetector::findQuadNeighbors()
int k = 0;
for (; k < 4; k++ )
{
CV_DbgAssert(q);
if (!q->neighbors[k])
{
if (normL2Sqr<float>(closest_corner.pt - q->corners[k]->pt) < min_dist)
Expand Down Expand Up @@ -2090,6 +2094,7 @@ void drawChessboardCorners( InputOutputArray image, Size patternSize,
return;
Mat corners = _corners.getMat();
const Point2f* corners_data = corners.ptr<Point2f>(0);
CV_DbgAssert(corners_data);
int nelems = corners.checkVector(2, CV_32F, true);
CV_Assert(nelems >= 0);

Expand Down
14 changes: 10 additions & 4 deletions modules/calib3d/src/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,9 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,

int i, count;
double a[9], ar[9]={1,0,0,0,1,0,0,0,1}, R[9];
double MM[9], U[9], V[9], W[3];
double MM[9] = { 0 }, U[9] = { 0 }, V[9] = { 0 }, W[3] = { 0 };
cv::Scalar Mc;
double param[6];
double param[6] = { 0 };
CvMat matA = cvMat( 3, 3, CV_64F, a );
CvMat _Ar = cvMat( 3, 3, CV_64F, ar );
CvMat matR = cvMat( 3, 3, CV_64F, R );
Expand Down Expand Up @@ -1274,8 +1274,9 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints,
CvMat matH = cvMat( 3, 3, CV_64F, H );
CvMat _f = cvMat( 2, 1, CV_64F, f );

assert( CV_MAT_TYPE(npoints->type) == CV_32SC1 &&
CV_IS_MAT_CONT(npoints->type) );
CV_Assert(npoints);
CV_Assert(CV_MAT_TYPE(npoints->type) == CV_32SC1);
CV_Assert(CV_IS_MAT_CONT(npoints->type));
nimages = npoints->rows + npoints->cols - 1;

if( (CV_MAT_TYPE(objectPoints->type) != CV_32FC3 &&
Expand All @@ -1296,6 +1297,9 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints,
// extract vanishing points in order to obtain initial value for the focal length
for( i = 0, pos = 0; i < nimages; i++, pos += ni )
{
CV_DbgAssert(npoints->data.i);
CV_DbgAssert(matA && matA->data.db);
CV_DbgAssert(_b && _b->data.db);
double* Ap = matA->data.db + i*4;
double* bp = _b->data.db + i*2;
ni = npoints->data.i[i];
Expand All @@ -1306,6 +1310,7 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints,
cvGetCols( imagePoints, &_m, pos, pos + ni );

cvFindHomography( &matM, &_m, &matH );
CV_DbgAssert(_allH && _allH->data.db);
memcpy( _allH->data.db + i*9, H, sizeof(H) );

H[0] -= H[6]*a[2]; H[1] -= H[7]*a[2]; H[2] -= H[8]*a[2];
Expand Down Expand Up @@ -4145,6 +4150,7 @@ static void adjust3rdMatrix(InputArrayOfArrays _imgpt1_0,

double y1_ = 0, y2_ = 0, y1y1_ = 0, y1y2_ = 0;
size_t n = imgpt1.size();
CV_DbgAssert(n > 0);

for( size_t i = 0; i < n; i++ )
{
Expand Down
1 change: 1 addition & 0 deletions modules/calib3d/src/fundam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ cv::Mat cv::findFundamentalMat( InputArray points1, InputArray points2,
OutputArray mask, const UsacParams &params) {
Ptr<usac::Model> model;
setParameters(model, usac::EstimationMethod::Fundamental, params, mask.needed());
CV_Assert(model);
Ptr<usac::RansacOutput> ransac_output;
if (usac::run(model, points1, points2, model->getRandomGeneratorState(),
ransac_output, noArray(), noArray(), noArray(), noArray())) {
Expand Down
54 changes: 43 additions & 11 deletions modules/calib3d/src/usac/estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,14 @@ class ReprojectedErrorSymmetricImpl : public ReprojectionErrorSymmetric {
float minv11, minv12, minv13, minv21, minv22, minv23, minv31, minv32, minv33;
std::vector<float> errors;
public:
explicit ReprojectedErrorSymmetricImpl (const Mat &points_) :
points_mat(&points_), points ((float *) points_.data), errors(points_.rows) {}
explicit ReprojectedErrorSymmetricImpl (const Mat &points_)
: points_mat(&points_), points ((float *) points_.data)
, m11(0), m12(0), m13(0), m21(0), m22(0), m23(0), m31(0), m32(0), m33(0)
, minv11(0), minv12(0), minv13(0), minv21(0), minv22(0), minv23(0), minv31(0), minv32(0), minv33(0)
, errors(points_.rows)
{
CV_DbgAssert(points);
}

inline void setModelParameters (const Mat &model) override {
const auto * const m = (double *) model.data;
Expand Down Expand Up @@ -298,7 +304,12 @@ class ReprojectedErrorForwardImpl : public ReprojectionErrorForward {
std::vector<float> errors;
public:
explicit ReprojectedErrorForwardImpl (const Mat &points_)
: points_mat(&points_), points ((float *)points_.data), errors(points_.rows) {}
: points_mat(&points_), points ((float *)points_.data)
, m11(0), m12(0), m13(0), m21(0), m22(0), m23(0), m31(0), m32(0), m33(0)
, errors(points_.rows)
{
CV_DbgAssert(points);
}

inline void setModelParameters (const Mat &model) override {
const auto * const m = (double *) model.data;
Expand Down Expand Up @@ -342,8 +353,13 @@ class SampsonErrorImpl : public SampsonError {
float m11, m12, m13, m21, m22, m23, m31, m32, m33;
std::vector<float> errors;
public:
explicit SampsonErrorImpl (const Mat &points_) :
points_mat(&points_), points ((float *) points_.data), errors(points_.rows) {}
explicit SampsonErrorImpl (const Mat &points_)
: points_mat(&points_), points ((float *) points_.data)
, m11(0), m12(0), m13(0), m21(0), m22(0), m23(0), m31(0), m32(0), m33(0)
, errors(points_.rows)
{
CV_DbgAssert(points);
}

inline void setModelParameters (const Mat &model) override {
const auto * const m = (double *) model.data;
Expand Down Expand Up @@ -404,8 +420,13 @@ class SymmetricGeometricDistanceImpl : public SymmetricGeometricDistance {
float m11, m12, m13, m21, m22, m23, m31, m32, m33;
std::vector<float> errors;
public:
explicit SymmetricGeometricDistanceImpl (const Mat &points_) :
points_mat(&points_), points ((float *) points_.data), errors(points_.rows) {}
explicit SymmetricGeometricDistanceImpl (const Mat &points_)
: points_mat(&points_), points ((float *) points_.data)
, m11(0), m12(0), m13(0), m21(0), m22(0), m23(0), m31(0), m32(0), m33(0)
, errors(points_.rows)
{
CV_DbgAssert(points);
}

inline void setModelParameters (const Mat &model) override {
const auto * const m = (double *) model.data;
Expand Down Expand Up @@ -458,8 +479,14 @@ class ReprojectionErrorPmatrixImpl : public ReprojectionErrorPmatrix {
float p11, p12, p13, p14, p21, p22, p23, p24, p31, p32, p33, p34;
std::vector<float> errors;
public:
explicit ReprojectionErrorPmatrixImpl (const Mat &points_) :
points_mat(&points_), points ((float *) points_.data), errors(points_.rows) {}
explicit ReprojectionErrorPmatrixImpl (const Mat &points_)
: points_mat(&points_), points ((float *) points_.data)
, p11(0), p12(0), p13(0), p14(0), p21(0), p22(0), p23(0), p24(0), p31(0), p32(0), p33(0), p34(0)
, errors(points_.rows)
{
CV_DbgAssert(points);
}


inline void setModelParameters (const Mat &model) override {
const auto * const p = (double *) model.data;
Expand Down Expand Up @@ -512,8 +539,13 @@ class ReprojectedDistanceAffineImpl : public ReprojectionErrorAffine {
float m11, m12, m13, m21, m22, m23;
std::vector<float> errors;
public:
explicit ReprojectedDistanceAffineImpl (const Mat &points_) :
points_mat(&points_), points ((float*)points_.data), errors(points_.rows) {}
explicit ReprojectedDistanceAffineImpl (const Mat &points_)
: points_mat(&points_), points ((float *) points_.data)
, m11(0), m12(0), m13(0), m21(0), m22(0), m23(0)
, errors(points_.rows)
{
CV_DbgAssert(points);
}

inline void setModelParameters (const Mat &model) override {
const auto * const m = (double *) model.data;
Expand Down
9 changes: 6 additions & 3 deletions modules/calib3d/src/usac/fundamental_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class FundamentalMinimalSolver7ptsImpl: public FundamentalMinimalSolver7pts {
}

// OpenCV:
double c[4], r[3];
double t0, t1, t2;
double c[4] = { 0 }, r[3] = { 0 };
double t0 = 0, t1 = 0, t2 = 0;
Mat_<double> coeffs (1, 4, c);
Mat_<double> roots (1, 3, r);

Expand Down Expand Up @@ -158,7 +158,10 @@ class FundamentalMinimalSolver8ptsImpl : public FundamentalMinimalSolver8pts {
const float * const points;
public:
explicit FundamentalMinimalSolver8ptsImpl (const Mat &points_) :
points_mat (&points_), points ((float*) points_.data) {}
points_mat (&points_), points ((float*) points_.data)
{
CV_DbgAssert(points);
}

int estimate (const std::vector<int> &sample, std::vector<Mat> &models) const override {
const int m = 8, n = 9; // rows, cols
Expand Down
8 changes: 5 additions & 3 deletions modules/calib3d/src/usac/local_optimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ class InnerIterativeLocalOptimizationImpl : public InnerIterativeLocalOptimizati
const Ptr<RandomGenerator> &lo_sampler_, int pts_size,
double threshold_, bool is_iterative_, int lo_iter_sample_size_,
int lo_inner_iterations_=10, int lo_iter_max_iterations_=5,
double threshold_multiplier_=4) : estimator (estimator_), quality (quality_),
lo_sampler (lo_sampler_) {

double threshold_multiplier_=4)
: estimator (estimator_), quality (quality_), lo_sampler (lo_sampler_)
, lo_iter_sample_size(0)
, new_threshold(0), threshold_step(0)
{
lo_inner_max_iterations = lo_inner_iterations_;
lo_iter_max_iterations = lo_iter_max_iterations_;

Expand Down
8 changes: 5 additions & 3 deletions modules/calib3d/src/usac/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ namespace cv { namespace usac {
class UniformSamplerImpl : public UniformSampler {
private:
std::vector<int> points_random_pool;
int sample_size, random_pool_size, points_size = 0;
int sample_size, points_size = 0;
RNG rng;
public:

UniformSamplerImpl (int state, int sample_size_, int points_size_) : rng(state) {
UniformSamplerImpl (int state, int sample_size_, int points_size_)
: rng(state)
{
sample_size = sample_size_;
setPointsSize (points_size_);
}
void setNewPointsSize (int points_size_) override {
setPointsSize(points_size_);
}
void generateSample (std::vector<int> &sample) override {
random_pool_size = points_size; // random points of entire range
int random_pool_size = points_size; // random points of entire range
for (int i = 0; i < sample_size; i++) {
// get random point index
const int array_random_index = rng.uniform(0, random_pool_size);
Expand Down
3 changes: 3 additions & 0 deletions modules/dnn/src/layers/convolution_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,8 @@ class ConvolutionLayerImpl CV_FINAL : public BaseConvolutionLayerImpl
std::vector<size_t> dims = ieInpNode->get_shape();
CV_Assert(dims.size() == 4 || dims.size() == 5);
std::shared_ptr<ngraph::Node> ieWeights = nodes.size() > 1 ? nodes[1].dynamicCast<InfEngineNgraphNode>()->node : nullptr;
if (nodes.size() > 1)
CV_Assert(ieWeights); // dynamic_cast should not fail
const int inpCn = dims[1];
const int inpGroupCn = nodes.size() > 1 ? ieWeights->get_shape()[1] : blobs[0].size[1];
const int group = inpCn / inpGroupCn;
Expand Down Expand Up @@ -859,6 +861,7 @@ class ConvolutionLayerImpl CV_FINAL : public BaseConvolutionLayerImpl
ParallelConv()
: input_(0), weights_(0), output_(0), ngroups_(0), nstripes_(0),
biasvec_(0), reluslope_(0), activ_(0), is1x1_(false), useAVX(false), useAVX2(false), useAVX512(false)
, blk_size_cn(0)
{}

static void run( const Mat& input, Mat& output, const Mat& weights,
Expand Down
2 changes: 1 addition & 1 deletion modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class OCL4DNNInnerProduct
UMat& top_data);
private:
OCL4DNNInnerProductConfig config_;
int32_t axis_;
//int32_t axis_;
int32_t num_output_;
int32_t M_;
int32_t N_;
Expand Down
5 changes: 4 additions & 1 deletion modules/flann/include/opencv2/flann/result_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class KNNResultSet : public ResultSet<DistanceType>
DistanceType worst_distance_;

public:
KNNResultSet(int capacity_) : capacity(capacity_), count(0)
KNNResultSet(int capacity_)
: indices(NULL), dists(NULL), capacity(capacity_), count(0), worst_distance_(0)
{
}

Expand All @@ -186,6 +187,8 @@ class KNNResultSet : public ResultSet<DistanceType>

void addPoint(DistanceType dist, int index) CV_OVERRIDE
{
CV_DbgAssert(indices);
CV_DbgAssert(dists);
if (dist >= worst_distance_) return;
int i;
for (i = count; i > 0; --i) {
Expand Down
1 change: 1 addition & 0 deletions modules/flann/include/opencv2/flann/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class StartStopTimer
* Constructor.
*/
StartStopTimer()
: startTime(0)
{
reset();
}
Expand Down
Loading

0 comments on commit 5ae9892

Please sign in to comment.