Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Nov 27, 2020
2 parents 23be514 + 7c78c59 commit 2155296
Show file tree
Hide file tree
Showing 12 changed files with 397 additions and 111 deletions.
5 changes: 4 additions & 1 deletion cmake/OpenCVFindLibsPerf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ endif(WITH_CUDA)

# --- Eigen ---
if(WITH_EIGEN AND NOT HAVE_EIGEN)
if(NOT OPENCV_SKIP_EIGEN_FIND_PACKAGE_CONFIG)
if((OPENCV_FORCE_EIGEN_FIND_PACKAGE_CONFIG
OR NOT (CMAKE_VERSION VERSION_LESS "3.0.0") # Eigen3Targets.cmake required CMake 3.0.0+
) AND NOT OPENCV_SKIP_EIGEN_FIND_PACKAGE_CONFIG
)
find_package(Eigen3 CONFIG QUIET) # Ceres 2.0.0 CMake scripts doesn't work with CMake's FindEigen3.cmake module (due to missing EIGEN3_VERSION_STRING)
endif()
if(NOT Eigen3_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ find the average error, we calculate the arithmetical mean of the errors calcula
calibration images.
@code{.py}
mean_error = 0
for i in xrange(len(objpoints)):
for i in range(len(objpoints)):
imgpoints2, _ = cv.projectPoints(objpoints[i], rvecs[i], tvecs[i], mtx, dist)
error = cv.norm(imgpoints[i], imgpoints2, cv.NORM_L2)/len(imgpoints2)
mean_error += error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ automatically available with the platform (e.g. APPLE GCD) but chances are that
have access to a parallel framework either directly or by enabling the option in CMake and rebuild the library.

The second (weak) precondition is more related to the task you want to achieve as not all computations
are suitable / can be adatapted to be run in a parallel way. To remain simple, tasks that can be split
are suitable / can be adapted to be run in a parallel way. To remain simple, tasks that can be split
into multiple elementary operations with no memory dependency (no possible race condition) are easily
parallelizable. Computer vision processing are often easily parallelizable as most of the time the processing of
one pixel does not depend to the state of other pixels.
Expand Down
3 changes: 1 addition & 2 deletions modules/core/src/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,7 @@ void flip( InputArray _src, OutputArray _dst, int flip_mode )
}

if ((size.width == 1 && flip_mode > 0) ||
(size.height == 1 && flip_mode == 0) ||
(size.height == 1 && size.width == 1 && flip_mode < 0))
(size.height == 1 && flip_mode == 0))
{
return _src.copyTo(_dst);
}
Expand Down
32 changes: 12 additions & 20 deletions modules/core/src/matrix_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ bool _InputArray::isContinuous(int i) const
if( k == STD_ARRAY_MAT )
{
const Mat* vv = (const Mat*)obj;
CV_Assert(i > 0 && i < sz.height);
CV_Assert(i >= 0 && i < sz.height);
return vv[i].isContinuous();
}

Expand Down Expand Up @@ -949,21 +949,21 @@ bool _InputArray::isSubmatrix(int i) const
if( k == STD_VECTOR_MAT )
{
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].isSubmatrix();
}

if( k == STD_ARRAY_MAT )
{
const Mat* vv = (const Mat*)obj;
CV_Assert(i < sz.height);
CV_Assert(i >= 0 && i < sz.height);
return vv[i].isSubmatrix();
}

if( k == STD_VECTOR_UMAT )
{
const std::vector<UMat>& vv = *(const std::vector<UMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].isSubmatrix();
}

Expand Down Expand Up @@ -994,26 +994,22 @@ size_t _InputArray::offset(int i) const
if( k == STD_VECTOR_MAT )
{
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
if( i < 0 )
return 1;
CV_Assert( i < (int)vv.size() );
CV_Assert( i >= 0 && i < (int)vv.size() );

return (size_t)(vv[i].ptr() - vv[i].datastart);
}

if( k == STD_ARRAY_MAT )
{
const Mat* vv = (const Mat*)obj;
if( i < 0 )
return 1;
CV_Assert( i < sz.height );
CV_Assert( i >= 0 && i < sz.height );
return (size_t)(vv[i].ptr() - vv[i].datastart);
}

if( k == STD_VECTOR_UMAT )
{
const std::vector<UMat>& vv = *(const std::vector<UMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].offset;
}

Expand All @@ -1027,7 +1023,7 @@ size_t _InputArray::offset(int i) const
if (k == STD_VECTOR_CUDA_GPU_MAT)
{
const std::vector<cuda::GpuMat>& vv = *(const std::vector<cuda::GpuMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return (size_t)(vv[i].data - vv[i].datastart);
}

Expand Down Expand Up @@ -1057,25 +1053,21 @@ size_t _InputArray::step(int i) const
if( k == STD_VECTOR_MAT )
{
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
if( i < 0 )
return 1;
CV_Assert( i < (int)vv.size() );
CV_Assert( i >= 0 && i < (int)vv.size() );
return vv[i].step;
}

if( k == STD_ARRAY_MAT )
{
const Mat* vv = (const Mat*)obj;
if( i < 0 )
return 1;
CV_Assert( i < sz.height );
CV_Assert( i >= 0 && i < sz.height );
return vv[i].step;
}

if( k == STD_VECTOR_UMAT )
{
const std::vector<UMat>& vv = *(const std::vector<UMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].step;
}

Expand All @@ -1087,7 +1079,7 @@ size_t _InputArray::step(int i) const
if (k == STD_VECTOR_CUDA_GPU_MAT)
{
const std::vector<cuda::GpuMat>& vv = *(const std::vector<cuda::GpuMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].step;
}

Expand Down
153 changes: 153 additions & 0 deletions modules/core/test/test_mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "opencv2/core/eigen.hpp"
#endif

#include "opencv2/core/cuda.hpp"

namespace opencv_test { namespace {

class Core_ReduceTest : public cvtest::BaseTest
Expand Down Expand Up @@ -1974,6 +1976,157 @@ TEST(Core_InputArray, fetch_MatExpr)
}


#ifdef CV_CXX11
class TestInputArrayRangeChecking {
static const char *kind2str(cv::_InputArray ia)
{
switch (ia.kind())
{
#define C(x) case cv::_InputArray::x: return #x
C(MAT);
C(UMAT);
C(EXPR);
C(MATX);
C(STD_VECTOR);
C(STD_ARRAY);
C(NONE);
C(STD_VECTOR_VECTOR);
C(STD_BOOL_VECTOR);
C(STD_VECTOR_MAT);
C(STD_ARRAY_MAT);
C(STD_VECTOR_UMAT);
C(CUDA_GPU_MAT);
C(STD_VECTOR_CUDA_GPU_MAT);
#undef C
default:
return "<unsupported>";
}
}

static void banner(cv::_InputArray ia, const char *label, const char *name)
{
std::cout << std::endl
<< label << " = " << name << ", Kind: " << kind2str(ia)
<< std::endl;
}

template<typename I, typename F>
static void testA(I ia, F f, const char *mfname)
{
banner(ia, "f", mfname);
EXPECT_THROW(f(ia, -1), cv::Exception)
<< "f(ia, " << -1 << ") should throw cv::Exception";
for (int i = 0; i < int(ia.size()); i++)
{
EXPECT_NO_THROW(f(ia, i))
<< "f(ia, " << i << ") should not throw an exception";
}
EXPECT_THROW(f(ia, int(ia.size())), cv::Exception)
<< "f(ia, " << ia.size() << ") should throw cv::Exception";
}

template<typename I, typename F>
static void testB(I ia, F f, const char *mfname)
{
banner(ia, "f", mfname);
EXPECT_THROW(f(ia, -1), cv::Exception)
<< "f(ia, " << -1 << ") should throw cv::Exception";
for (int i = 0; i < int(ia.size()); i++)
{
EXPECT_NO_THROW(f(ia, i))
<< "f(ia, " << i << ") should not throw an exception";
}
EXPECT_THROW(f(ia, int(ia.size())), cv::Exception)
<< "f(ia, " << ia.size() << ") should throw cv::Exception";
}

static void test_isContinuous()
{
auto f = [](cv::_InputArray ia, int i) { (void)ia.isContinuous(i); };

cv::Mat M;
cv::UMat uM;

std::vector<cv::Mat> vec = {M, M};
std::array<cv::Mat, 2> arr = {M, M};
std::vector<cv::UMat> uvec = {uM, uM};

testA(vec, f, "isContinuous");
testA(arr, f, "isContinuous");
testA(uvec, f, "isContinuous");
}

static void test_isSubmatrix()
{
auto f = [](cv::_InputArray ia, int i) { (void)ia.isSubmatrix(i); };

cv::Mat M;
cv::UMat uM;

std::vector<cv::Mat> vec = {M, M};
std::array<cv::Mat, 2> arr = {M, M};
std::vector<cv::UMat> uvec = {uM, uM};

testA(vec, f, "isSubmatrix");
testA(arr, f, "isSubmatrix");
testA(uvec, f, "isSubmatrix");
}

static void test_offset()
{
auto f = [](cv::_InputArray ia, int i) { return ia.offset(i); };

cv::Mat M;
cv::UMat uM;
cv::cuda::GpuMat gM;

std::vector<cv::Mat> vec = {M, M};
std::array<cv::Mat, 2> arr = {M, M};
std::vector<cv::UMat> uvec = {uM, uM};
std::vector<cv::cuda::GpuMat> gvec = {gM, gM};

testB(vec, f, "offset");
testB(arr, f, "offset");
testB(uvec, f, "offset");
testB(gvec, f, "offset");
}

static void test_step()
{
auto f = [](cv::_InputArray ia, int i) { return ia.step(i); };

cv::Mat M;
cv::UMat uM;
cv::cuda::GpuMat gM;

std::vector<cv::Mat> vec = {M, M};
std::array<cv::Mat, 2> arr = {M, M};
std::vector<cv::UMat> uvec = {uM, uM};
std::vector<cv::cuda::GpuMat> gvec = {gM, gM};

testB(vec, f, "step");
testB(arr, f, "step");
testB(uvec, f, "step");
testB(gvec, f, "step");
}

public:
static void run()
{
test_isContinuous();
test_isSubmatrix();
test_offset();
test_step();
}
};

TEST(Core_InputArray, range_checking)
{
TestInputArrayRangeChecking::run();
}
#endif


TEST(Core_Vectors, issue_13078)
{
float floats_[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
Expand Down
2 changes: 0 additions & 2 deletions modules/dnn/include/opencv2/dnn/all_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ CV__DNN_INLINE_NS_BEGIN
int type;
std::vector<size_t> kernel_size, strides;
std::vector<size_t> pads_begin, pads_end;
CV_DEPRECATED_EXTERNAL Size kernel, stride, pad;
CV_DEPRECATED_EXTERNAL int pad_l, pad_t, pad_r, pad_b;
bool globalPooling; //!< Flag is true if at least one of the axes is global pooled.
std::vector<bool> isGlobalPooling;
bool computeMaxIdx;
Expand Down
Loading

0 comments on commit 2155296

Please sign in to comment.