Skip to content

Commit e5e767a

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 521aac9 + d41b20b commit e5e767a

File tree

13 files changed

+668
-128
lines changed

13 files changed

+668
-128
lines changed

cmake/OpenCVDetectCUDA.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,18 @@ if(CUDA_FOUND)
116116
if(OPENCV_CUDA_DETECTION_NVCC_FLAGS MATCHES "-ccbin")
117117
# already specified by user
118118
elseif(CUDA_HOST_COMPILER AND EXISTS "${CUDA_HOST_COMPILER}")
119-
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${CUDA_HOST_COMPILER}")
119+
get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
120+
# C compiler doesn't work with --run option, forcing C++ compiler instead
121+
if(CUDA_HOST_COMPILER STREQUAL c_compiler_realpath OR CUDA_HOST_COMPILER STREQUAL CMAKE_C_COMPILER)
122+
if(DEFINED CMAKE_CXX_COMPILER)
123+
get_filename_component(cxx_compiler_realpath "${CMAKE_CXX_COMPILER}" REALPATH)
124+
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${cxx_compiler_realpath}")
125+
else()
126+
message(STATUS "CUDA: CMAKE_CXX_COMPILER is not available. You may need to specify CUDA_HOST_COMPILER.")
127+
endif()
128+
else()
129+
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${CUDA_HOST_COMPILER}")
130+
endif()
120131
elseif(WIN32 AND CMAKE_LINKER) # Workaround for VS cl.exe not being in the env. path
121132
get_filename_component(host_compiler_bindir ${CMAKE_LINKER} DIRECTORY)
122133
LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${host_compiler_bindir}")

modules/core/src/trace.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ static int64 getTimestamp()
7272
return (int64)((t - g_zero_timestamp) * tick_to_ns);
7373
}
7474

75-
// TODO lazy configuration flags
76-
static bool param_traceEnable = utils::getConfigurationParameterBool("OPENCV_TRACE", false);
75+
static bool getParameterTraceEnable()
76+
{
77+
static bool param_traceEnable = utils::getConfigurationParameterBool("OPENCV_TRACE", false);
78+
return param_traceEnable;
79+
}
7780

81+
// TODO lazy configuration flags
7882
static int param_maxRegionDepthOpenCV = (int)utils::getConfigurationParameterSizeT("OPENCV_TRACE_DEPTH_OPENCV", 1);
7983
static int param_maxRegionChildrenOpenCV = (int)utils::getConfigurationParameterSizeT("OPENCV_TRACE_MAX_CHILDREN_OPENCV", 1000);
8084
static int param_maxRegionChildren = (int)utils::getConfigurationParameterSizeT("OPENCV_TRACE_MAX_CHILDREN", 10000);
@@ -841,7 +845,7 @@ TraceManager::TraceManager()
841845
CV_LOG("TraceManager ctor: " << (void*)this);
842846

843847
CV_LOG("TraceManager configure()");
844-
activated = param_traceEnable;
848+
activated = getParameterTraceEnable();
845849

846850
if (activated)
847851
trace_storage.reset(new SyncTraceStorage(std::string(param_traceLocation) + ".txt"));

modules/dnn/src/op_inf_engine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,18 +831,18 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::CNNNetwork& net)
831831
CV_LOG_INFO(NULL, "DNN-IE: Can't register OpenCV custom layers extension: " << e.what());
832832
}
833833
#endif
834-
#ifndef _WIN32
835834
// Limit the number of CPU threads.
836835
#if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1)
836+
#ifndef _WIN32
837837
enginePtr->SetConfig({{
838838
InferenceEngine::PluginConfigParams::KEY_CPU_THREADS_NUM, format("%d", getNumThreads()),
839839
}}, 0);
840+
#endif // _WIN32
840841
#else
841842
if (device_name == "CPU")
842843
ie.SetConfig({{
843844
InferenceEngine::PluginConfigParams::KEY_CPU_THREADS_NUM, format("%d", getNumThreads()),
844845
}}, device_name);
845-
#endif
846846
#endif
847847
}
848848
#if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1)

modules/features2d/src/blobdetector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
257257
{
258258
std::vector < Point > hull;
259259
convexHull(contours[contourIdx], hull);
260-
double area = contourArea(contours[contourIdx]);
260+
double area = moms.m00;
261261
double hullArea = contourArea(hull);
262262
if (fabs(hullArea) < DBL_EPSILON)
263263
continue;

modules/features2d/src/matchers.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,20 @@ void DescriptorMatcher::checkMasks( InputArrayOfArrays _masks, int queryDescript
625625
if( isMaskSupported() && !masks.empty() )
626626
{
627627
// Check masks
628-
size_t imageCount = std::max(trainDescCollection.size(), utrainDescCollection.size() );
628+
const size_t imageCount = std::max(trainDescCollection.size(), utrainDescCollection.size() );
629629
CV_Assert( masks.size() == imageCount );
630630
for( size_t i = 0; i < imageCount; i++ )
631631
{
632-
if( !masks[i].empty() && (!trainDescCollection[i].empty() || !utrainDescCollection[i].empty() ) )
632+
if (masks[i].empty())
633+
continue;
634+
const bool hasTrainDesc = !trainDescCollection.empty() && !trainDescCollection[i].empty();
635+
const bool hasUTrainDesc = !utrainDescCollection.empty() && !utrainDescCollection[i].empty();
636+
if (hasTrainDesc || hasUTrainDesc)
633637
{
634-
int rows = trainDescCollection[i].empty() ? utrainDescCollection[i].rows : trainDescCollection[i].rows;
635-
CV_Assert( masks[i].rows == queryDescriptorsCount &&
636-
masks[i].cols == rows && masks[i].type() == CV_8UC1);
638+
const int rows = hasTrainDesc ? trainDescCollection[i].rows : utrainDescCollection[i].rows;
639+
CV_Assert(masks[i].type() == CV_8UC1
640+
&& masks[i].rows == queryDescriptorsCount
641+
&& masks[i].cols == rows);
637642
}
638643
}
639644
}

modules/features2d/src/sift.simd.hpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373

7474
#include <opencv2/core/hal/hal.hpp>
7575
#include "opencv2/core/hal/intrin.hpp"
76+
#include <opencv2/core/utils/buffer_area.private.hpp>
7677

7778
namespace cv {
7879

@@ -167,23 +168,17 @@ float calcOrientationHist(
167168
int i, j, k, len = (radius*2+1)*(radius*2+1);
168169

169170
float expf_scale = -1.f/(2.f * sigma * sigma);
170-
#if CV_SIMD
171-
AutoBuffer<float> bufX(len + v_float32::nlanes);
172-
AutoBuffer<float> bufY(len + v_float32::nlanes);
173-
AutoBuffer<float> bufO(len + v_float32::nlanes);
174-
AutoBuffer<float> bufW(len + v_float32::nlanes);
175-
AutoBuffer<float> bufT(n+4 + v_float32::nlanes);
176-
float *X = alignPtr(bufX.data(), CV_SIMD_WIDTH);
177-
float *Y = alignPtr(bufY.data(), CV_SIMD_WIDTH);
178-
float *Mag = X;
179-
float *Ori = alignPtr(bufO.data(), CV_SIMD_WIDTH);
180-
float *W = alignPtr(bufW.data(), CV_SIMD_WIDTH);
181-
float *temphist = alignPtr(bufT.data(), CV_SIMD_WIDTH)+2;
182-
#else
183-
AutoBuffer<float> buf(len*4 + n+4);
184-
float *X = buf.data(), *Y = X + len, *Mag = X, *Ori = Y + len, *W = Ori + len;
185-
float* temphist = W + len + 2;
186-
#endif
171+
172+
cv::utils::BufferArea area;
173+
float *X = 0, *Y = 0, *Mag, *Ori = 0, *W = 0, *temphist = 0;
174+
area.allocate(X, len, CV_SIMD_WIDTH);
175+
area.allocate(Y, len, CV_SIMD_WIDTH);
176+
area.allocate(Ori, len, CV_SIMD_WIDTH);
177+
area.allocate(W, len, CV_SIMD_WIDTH);
178+
area.allocate(temphist, n+4, CV_SIMD_WIDTH);
179+
area.commit();
180+
temphist += 2;
181+
Mag = X;
187182

188183
for( i = 0; i < n; i++ )
189184
temphist[i] = 0.f;
@@ -656,7 +651,7 @@ void calcSIFTDescriptor(
656651
v_float32 v_rco011 = v_rc01*obin, v_rco010 = v_rc01 - v_rco011;
657652
v_float32 v_rco001 = v_rc00*obin, v_rco000 = v_rc00 - v_rco001;
658653

659-
v_int32 idx = v_fma(v_fma(r0+__1, __d_plus_2, c0+__1), __n_plus_2, o0);
654+
v_int32 idx = v_muladd(v_muladd(r0+__1, __d_plus_2, c0+__1), __n_plus_2, o0);
660655
v_store_aligned(idx_buf, idx);
661656

662657
v_store_aligned(rco_buf, v_rco000);

modules/features2d/test/test_matchers_algorithmic.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ TEST(Features2d_DMatch, issue_11855)
603603
1, 1, 1);
604604
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 1,
605605
0, 0, 0);
606-
607606
Ptr<BFMatcher> bf = BFMatcher::create(NORM_HAMMING, true);
608607
vector<vector<DMatch> > match;
609608
bf->knnMatch(sources, targets, match, 1, noArray(), true);
@@ -615,4 +614,18 @@ TEST(Features2d_DMatch, issue_11855)
615614
EXPECT_EQ(0.0f, match[0][0].distance);
616615
}
617616

617+
TEST(Features2d_DMatch, issue_17771)
618+
{
619+
Mat sources = (Mat_<uchar>(2, 3) << 1, 1, 0,
620+
1, 1, 1);
621+
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 1,
622+
0, 0, 0);
623+
UMat usources = sources.getUMat(ACCESS_READ);
624+
UMat utargets = targets.getUMat(ACCESS_READ);
625+
vector<vector<DMatch> > match;
626+
Ptr<BFMatcher> ubf = BFMatcher::create(NORM_HAMMING);
627+
Mat mask = (Mat_<uchar>(2, 2) << 1, 0, 0, 1);
628+
EXPECT_NO_THROW(ubf->knnMatch(usources, utargets, match, 1, mask, true));
629+
}
630+
618631
}} // namespace

modules/flann/include/opencv2/flann.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class Index_
536536
@param features The points to be clustered. The matrix must have elements of type
537537
Distance::ElementType.
538538
@param centers The centers of the clusters obtained. The matrix must have type
539-
Distance::ResultType. The number of rows in this matrix represents the number of clusters desired,
539+
Distance::CentersType. The number of rows in this matrix represents the number of clusters desired,
540540
however, because of the way the cut in the hierarchical tree is chosen, the number of clusters
541541
computed will be the highest number of the form (branching-1)\*k+1 that's lower than the number of
542542
clusters desired, where branching is the tree's branching factor (see description of the
@@ -553,15 +553,15 @@ int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::K
553553
Distance d = Distance())
554554
{
555555
typedef typename Distance::ElementType ElementType;
556-
typedef typename Distance::ResultType DistanceType;
556+
typedef typename Distance::CentersType CentersType;
557557

558558
CV_Assert(features.type() == CvType<ElementType>::type());
559559
CV_Assert(features.isContinuous());
560560
::cvflann::Matrix<ElementType> m_features((ElementType*)features.ptr<ElementType>(0), features.rows, features.cols);
561561

562-
CV_Assert(centers.type() == CvType<DistanceType>::type());
562+
CV_Assert(centers.type() == CvType<CentersType>::type());
563563
CV_Assert(centers.isContinuous());
564-
::cvflann::Matrix<DistanceType> m_centers((DistanceType*)centers.ptr<DistanceType>(0), centers.rows, centers.cols);
564+
::cvflann::Matrix<CentersType> m_centers((CentersType*)centers.ptr<CentersType>(0), centers.rows, centers.cols);
565565

566566
return ::cvflann::hierarchicalClustering<Distance>(m_features, m_centers, params, d);
567567
}

modules/flann/include/opencv2/flann/all_indices.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ struct index_creator<False,False,Distance>
130130
case FLANN_INDEX_LINEAR:
131131
nnIndex = new LinearIndex<Distance>(dataset, params, distance);
132132
break;
133+
case FLANN_INDEX_KMEANS:
134+
nnIndex = new KMeansIndex<Distance>(dataset, params, distance);
135+
break;
133136
case FLANN_INDEX_HIERARCHICAL:
134137
nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance);
135138
break;

0 commit comments

Comments
 (0)