Skip to content

Commit dd1494e

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 5bb45ba + 1bfc75a commit dd1494e

File tree

24 files changed

+985
-226
lines changed

24 files changed

+985
-226
lines changed

3rdparty/protobuf/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ set_target_properties(libprotobuf
153153
ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
154154
)
155155

156+
if(ANDROID)
157+
# https://github.com/opencv/opencv/issues/17282
158+
target_link_libraries(libprotobuf INTERFACE "-landroid" "-llog")
159+
endif()
160+
156161
get_protobuf_version(Protobuf_VERSION "${PROTOBUF_ROOT}/src")
157162
set(Protobuf_VERSION ${Protobuf_VERSION} CACHE INTERNAL "" FORCE)
158163

cmake/OpenCVFindMKL.cmake

Lines changed: 88 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
# installation/package
44
#
55
# Parameters:
6-
# MKL_WITH_TBB
6+
# MKL_ROOT_DIR / ENV{MKLROOT}
7+
# MKL_INCLUDE_DIR
8+
# MKL_LIBRARIES
9+
# MKL_USE_SINGLE_DYNAMIC_LIBRARY - use single dynamic library mkl_rt.lib / libmkl_rt.so
10+
# MKL_WITH_TBB / MKL_WITH_OPENMP
11+
#
12+
# Extra:
13+
# MKL_LIB_FIND_PATHS
714
#
815
# On return this will define:
916
#
@@ -13,12 +20,6 @@
1320
# MKL_LIBRARIES - MKL libraries that are used by OpenCV
1421
#
1522

16-
macro (mkl_find_lib VAR NAME DIRS)
17-
find_path(${VAR} ${NAME} ${DIRS} NO_DEFAULT_PATH)
18-
set(${VAR} ${${VAR}}/${NAME})
19-
unset(${VAR} CACHE)
20-
endmacro()
21-
2223
macro(mkl_fail)
2324
set(HAVE_MKL OFF)
2425
set(MKL_ROOT_DIR "${MKL_ROOT_DIR}" CACHE PATH "Path to MKL directory")
@@ -39,43 +40,50 @@ macro(get_mkl_version VERSION_FILE)
3940
set(MKL_VERSION_STR "${MKL_VERSION_MAJOR}.${MKL_VERSION_MINOR}.${MKL_VERSION_UPDATE}" CACHE STRING "MKL version" FORCE)
4041
endmacro()
4142

43+
OCV_OPTION(MKL_USE_SINGLE_DYNAMIC_LIBRARY "Use MKL Single Dynamic Library thorugh mkl_rt.lib / libmkl_rt.so" OFF)
44+
OCV_OPTION(MKL_WITH_TBB "Use MKL with TBB multithreading" OFF)#ON IF WITH_TBB)
45+
OCV_OPTION(MKL_WITH_OPENMP "Use MKL with OpenMP multithreading" OFF)#ON IF WITH_OPENMP)
4246

43-
if(NOT DEFINED MKL_USE_MULTITHREAD)
44-
OCV_OPTION(MKL_WITH_TBB "Use MKL with TBB multithreading" OFF)#ON IF WITH_TBB)
45-
OCV_OPTION(MKL_WITH_OPENMP "Use MKL with OpenMP multithreading" OFF)#ON IF WITH_OPENMP)
47+
if(NOT MKL_ROOT_DIR AND DEFINED MKL_INCLUDE_DIR AND EXISTS "${MKL_INCLUDE_DIR}/mkl.h")
48+
file(TO_CMAKE_PATH "${MKL_INCLUDE_DIR}" MKL_INCLUDE_DIR)
49+
get_filename_component(MKL_ROOT_DIR "${MKL_INCLUDE_DIR}/.." ABSOLUTE)
4650
endif()
47-
48-
#check current MKL_ROOT_DIR
49-
if(NOT MKL_ROOT_DIR OR NOT EXISTS "${MKL_ROOT_DIR}/include/mkl.h")
50-
set(mkl_root_paths "${MKL_ROOT_DIR}")
51-
if(DEFINED ENV{MKLROOT})
52-
list(APPEND mkl_root_paths "$ENV{MKLROOT}")
51+
if(NOT MKL_ROOT_DIR)
52+
file(TO_CMAKE_PATH "${MKL_ROOT_DIR}" mkl_root_paths)
53+
if(DEFINED ENV{MKLROOT})
54+
file(TO_CMAKE_PATH "$ENV{MKLROOT}" path)
55+
list(APPEND mkl_root_paths "${path}")
56+
endif()
57+
58+
if(WITH_MKL AND NOT mkl_root_paths)
59+
if(WIN32)
60+
set(ProgramFilesx86 "ProgramFiles(x86)")
61+
file(TO_CMAKE_PATH "$ENV{${ProgramFilesx86}}" path)
62+
list(APPEND mkl_root_paths ${path}/IntelSWTools/compilers_and_libraries/windows/mkl)
5363
endif()
54-
55-
if(WITH_MKL AND NOT mkl_root_paths)
56-
if(WIN32)
57-
set(ProgramFilesx86 "ProgramFiles(x86)")
58-
list(APPEND mkl_root_paths $ENV{${ProgramFilesx86}}/IntelSWTools/compilers_and_libraries/windows/mkl)
59-
endif()
60-
if(UNIX)
61-
list(APPEND mkl_root_paths "/opt/intel/mkl")
62-
endif()
64+
if(UNIX)
65+
list(APPEND mkl_root_paths "/opt/intel/mkl")
6366
endif()
67+
endif()
6468

65-
find_path(MKL_ROOT_DIR include/mkl.h PATHS ${mkl_root_paths})
69+
find_path(MKL_ROOT_DIR include/mkl.h PATHS ${mkl_root_paths})
6670
endif()
6771

68-
set(MKL_INCLUDE_DIRS "${MKL_ROOT_DIR}/include" CACHE PATH "Path to MKL include directory")
72+
if(NOT MKL_ROOT_DIR OR NOT EXISTS "${MKL_ROOT_DIR}/include/mkl.h")
73+
mkl_fail()
74+
endif()
75+
76+
set(MKL_INCLUDE_DIR "${MKL_ROOT_DIR}/include" CACHE PATH "Path to MKL include directory")
6977

7078
if(NOT MKL_ROOT_DIR
7179
OR NOT EXISTS "${MKL_ROOT_DIR}"
72-
OR NOT EXISTS "${MKL_INCLUDE_DIRS}"
73-
OR NOT EXISTS "${MKL_INCLUDE_DIRS}/mkl_version.h"
80+
OR NOT EXISTS "${MKL_INCLUDE_DIR}"
81+
OR NOT EXISTS "${MKL_INCLUDE_DIR}/mkl_version.h"
7482
)
75-
mkl_fail()
83+
mkl_fail()
7684
endif()
7785

78-
get_mkl_version(${MKL_INCLUDE_DIRS}/mkl_version.h)
86+
get_mkl_version(${MKL_INCLUDE_DIR}/mkl_version.h)
7987

8088
#determine arch
8189
if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
@@ -95,52 +103,66 @@ else()
95103
set(MKL_ARCH_SUFFIX "c")
96104
endif()
97105

98-
if(MKL_VERSION_STR VERSION_GREATER "11.3.0" OR MKL_VERSION_STR VERSION_EQUAL "11.3.0")
99-
set(mkl_lib_find_paths
100-
${MKL_ROOT_DIR}/lib)
101-
foreach(MKL_ARCH ${MKL_ARCH_LIST})
102-
list(APPEND mkl_lib_find_paths
103-
${MKL_ROOT_DIR}/lib/${MKL_ARCH}
104-
${MKL_ROOT_DIR}/../tbb/lib/${MKL_ARCH}
105-
${MKL_ROOT_DIR}/${MKL_ARCH})
106-
endforeach()
107-
108-
set(mkl_lib_list "mkl_intel_${MKL_ARCH_SUFFIX}")
109-
110-
if(MKL_WITH_TBB)
111-
list(APPEND mkl_lib_list mkl_tbb_thread tbb)
112-
elseif(MKL_WITH_OPENMP)
113-
if(MSVC)
114-
list(APPEND mkl_lib_list mkl_intel_thread libiomp5md)
115-
else()
116-
list(APPEND mkl_lib_list mkl_gnu_thread)
117-
endif()
106+
set(mkl_lib_find_paths ${MKL_LIB_FIND_PATHS} ${MKL_ROOT_DIR}/lib)
107+
foreach(MKL_ARCH ${MKL_ARCH_LIST})
108+
list(APPEND mkl_lib_find_paths
109+
${MKL_ROOT_DIR}/lib/${MKL_ARCH}
110+
${MKL_ROOT_DIR}/${MKL_ARCH}
111+
)
112+
endforeach()
113+
114+
if(MKL_USE_SINGLE_DYNAMIC_LIBRARY AND NOT (MKL_VERSION_STR VERSION_LESS "10.3.0"))
115+
116+
# https://software.intel.com/content/www/us/en/develop/articles/a-new-linking-model-single-dynamic-library-mkl_rt-since-intel-mkl-103.html
117+
set(mkl_lib_list "mkl_rt")
118+
119+
elseif(NOT (MKL_VERSION_STR VERSION_LESS "11.3.0"))
120+
121+
foreach(MKL_ARCH ${MKL_ARCH_LIST})
122+
list(APPEND mkl_lib_find_paths
123+
${MKL_ROOT_DIR}/../tbb/lib/${MKL_ARCH}
124+
)
125+
endforeach()
126+
127+
set(mkl_lib_list "mkl_intel_${MKL_ARCH_SUFFIX}")
128+
129+
if(MKL_WITH_TBB)
130+
list(APPEND mkl_lib_list mkl_tbb_thread tbb)
131+
elseif(MKL_WITH_OPENMP)
132+
if(MSVC)
133+
list(APPEND mkl_lib_list mkl_intel_thread libiomp5md)
118134
else()
119-
list(APPEND mkl_lib_list mkl_sequential)
135+
list(APPEND mkl_lib_list mkl_gnu_thread)
120136
endif()
137+
else()
138+
list(APPEND mkl_lib_list mkl_sequential)
139+
endif()
121140

122-
list(APPEND mkl_lib_list mkl_core)
141+
list(APPEND mkl_lib_list mkl_core)
123142
else()
124-
message(STATUS "MKL version ${MKL_VERSION_STR} is not supported")
125-
mkl_fail()
143+
message(STATUS "MKL version ${MKL_VERSION_STR} is not supported")
144+
mkl_fail()
126145
endif()
127146

128-
set(MKL_LIBRARIES "")
129-
foreach(lib ${mkl_lib_list})
130-
find_library(${lib} NAMES ${lib} ${lib}_dll HINTS ${mkl_lib_find_paths})
131-
mark_as_advanced(${lib})
132-
if(NOT ${lib})
133-
mkl_fail()
147+
if(NOT MKL_LIBRARIES)
148+
set(MKL_LIBRARIES "")
149+
foreach(lib ${mkl_lib_list})
150+
set(lib_var_name MKL_LIBRARY_${lib})
151+
find_library(${lib_var_name} NAMES ${lib} ${lib}_dll HINTS ${mkl_lib_find_paths})
152+
mark_as_advanced(${lib_var_name})
153+
if(NOT ${lib_var_name})
154+
mkl_fail()
134155
endif()
135-
list(APPEND MKL_LIBRARIES ${${lib}})
136-
endforeach()
156+
list(APPEND MKL_LIBRARIES ${${lib_var_name}})
157+
endforeach()
158+
endif()
137159

138160
message(STATUS "Found MKL ${MKL_VERSION_STR} at: ${MKL_ROOT_DIR}")
139161
set(HAVE_MKL ON)
140162
set(MKL_ROOT_DIR "${MKL_ROOT_DIR}" CACHE PATH "Path to MKL directory")
141-
set(MKL_INCLUDE_DIRS "${MKL_INCLUDE_DIRS}" CACHE PATH "Path to MKL include directory")
142-
set(MKL_LIBRARIES "${MKL_LIBRARIES}" CACHE STRING "MKL libraries")
143-
if(UNIX AND NOT MKL_LIBRARIES_DONT_HACK)
163+
set(MKL_INCLUDE_DIRS "${MKL_INCLUDE_DIR}")
164+
set(MKL_LIBRARIES "${MKL_LIBRARIES}")
165+
if(UNIX AND NOT MKL_USE_SINGLE_DYNAMIC_LIBRARY AND NOT MKL_LIBRARIES_DONT_HACK)
144166
#it's ugly but helps to avoid cyclic lib problem
145167
set(MKL_LIBRARIES ${MKL_LIBRARIES} ${MKL_LIBRARIES} ${MKL_LIBRARIES} "-lpthread" "-lm" "-ldl")
146168
endif()

modules/calib3d/include/opencv2/calib3d.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,7 @@ typedef CirclesGridFinderParameters CirclesGridFinderParameters2;
16701670
- **CALIB_CB_CLUSTERING** uses a special algorithm for grid detection. It is more robust to
16711671
perspective distortions but much more sensitive to background clutter.
16721672
@param blobDetector feature detector that finds blobs like dark circles on light background.
1673+
If `blobDetector` is NULL then `image` represents Point2f array of candidates.
16731674
@param parameters struct for finding circles in a grid pattern.
16741675
16751676
The function attempts to determine whether the input image contains a grid of circles. If it is, the

modules/calib3d/src/calibinit.cpp

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,13 +2178,6 @@ void drawChessboardCorners( InputOutputArray image, Size patternSize,
21782178
}
21792179
}
21802180

2181-
static int quiet_error(int /*status*/, const char* /*func_name*/,
2182-
const char* /*err_msg*/, const char* /*file_name*/,
2183-
int /*line*/, void* /*userdata*/)
2184-
{
2185-
return 0;
2186-
}
2187-
21882181
bool findCirclesGrid( InputArray _image, Size patternSize,
21892182
OutputArray _centers, int flags, const Ptr<FeatureDetector> &blobDetector,
21902183
const CirclesGridFinderParameters& parameters_)
@@ -2197,15 +2190,22 @@ bool findCirclesGrid( InputArray _image, Size patternSize,
21972190
bool isSymmetricGrid = (flags & CALIB_CB_SYMMETRIC_GRID ) ? true : false;
21982191
CV_Assert(isAsymmetricGrid ^ isSymmetricGrid);
21992192

2200-
Mat image = _image.getMat();
22012193
std::vector<Point2f> centers;
22022194

2203-
std::vector<KeyPoint> keypoints;
2204-
blobDetector->detect(image, keypoints);
22052195
std::vector<Point2f> points;
2206-
for (size_t i = 0; i < keypoints.size(); i++)
2196+
if (blobDetector)
2197+
{
2198+
std::vector<KeyPoint> keypoints;
2199+
blobDetector->detect(_image, keypoints);
2200+
for (size_t i = 0; i < keypoints.size(); i++)
2201+
{
2202+
points.push_back(keypoints[i].pt);
2203+
}
2204+
}
2205+
else
22072206
{
2208-
points.push_back (keypoints[i].pt);
2207+
CV_CheckTypeEQ(_image.type(), CV_32FC2, "blobDetector must be provided or image must contains Point2f array (std::vector<Point2f>) with candidates");
2208+
_image.copyTo(points);
22092209
}
22102210

22112211
if(flags & CALIB_CB_ASYMMETRIC_GRID)
@@ -2221,64 +2221,59 @@ bool findCirclesGrid( InputArray _image, Size patternSize,
22212221
return !centers.empty();
22222222
}
22232223

2224+
bool isValid = false;
22242225
const int attempts = 2;
22252226
const size_t minHomographyPoints = 4;
22262227
Mat H;
22272228
for (int i = 0; i < attempts; i++)
22282229
{
2229-
centers.clear();
2230-
CirclesGridFinder boxFinder(patternSize, points, parameters);
2231-
bool isFound = false;
2232-
#define BE_QUIET 1
2233-
#if BE_QUIET
2234-
void* oldCbkData;
2235-
ErrorCallback oldCbk = redirectError(quiet_error, 0, &oldCbkData); // FIXIT not thread safe
2236-
#endif
2237-
try
2238-
{
2239-
isFound = boxFinder.findHoles();
2240-
}
2241-
catch (const cv::Exception &)
2242-
{
2243-
2244-
}
2245-
#if BE_QUIET
2246-
redirectError(oldCbk, oldCbkData);
2247-
#endif
2248-
if (isFound)
2249-
{
2250-
switch(parameters.gridType)
2230+
centers.clear();
2231+
CirclesGridFinder boxFinder(patternSize, points, parameters);
2232+
try
22512233
{
2252-
case CirclesGridFinderParameters::SYMMETRIC_GRID:
2253-
boxFinder.getHoles(centers);
2254-
break;
2255-
case CirclesGridFinderParameters::ASYMMETRIC_GRID:
2256-
boxFinder.getAsymmetricHoles(centers);
2257-
break;
2258-
default:
2259-
CV_Error(Error::StsBadArg, "Unknown pattern type");
2234+
bool isFound = boxFinder.findHoles();
2235+
if (isFound)
2236+
{
2237+
switch(parameters.gridType)
2238+
{
2239+
case CirclesGridFinderParameters::SYMMETRIC_GRID:
2240+
boxFinder.getHoles(centers);
2241+
break;
2242+
case CirclesGridFinderParameters::ASYMMETRIC_GRID:
2243+
boxFinder.getAsymmetricHoles(centers);
2244+
break;
2245+
default:
2246+
CV_Error(Error::StsBadArg, "Unknown pattern type");
2247+
}
2248+
2249+
isValid = true;
2250+
break; // done, return result
2251+
}
2252+
}
2253+
catch (const cv::Exception& e)
2254+
{
2255+
CV_UNUSED(e);
2256+
CV_LOG_DEBUG(NULL, "findCirclesGrid2: attempt=" << i << ": " << e.what());
2257+
// nothing, next attempt
22602258
}
22612259

2262-
if (i != 0)
2260+
boxFinder.getHoles(centers);
2261+
if (i != attempts - 1)
22632262
{
2264-
Mat orgPointsMat;
2265-
transform(centers, orgPointsMat, H.inv());
2266-
convertPointsFromHomogeneous(orgPointsMat, centers);
2263+
if (centers.size() < minHomographyPoints)
2264+
break;
2265+
H = CirclesGridFinder::rectifyGrid(boxFinder.getDetectedGridSize(), centers, points, points);
22672266
}
2268-
Mat(centers).copyTo(_centers);
2269-
return true;
2270-
}
2271-
2272-
boxFinder.getHoles(centers);
2273-
if (i != attempts - 1)
2274-
{
2275-
if (centers.size() < minHomographyPoints)
2276-
break;
2277-
H = CirclesGridFinder::rectifyGrid(boxFinder.getDetectedGridSize(), centers, points, points);
2278-
}
2267+
}
2268+
2269+
if (!H.empty()) // undone rectification
2270+
{
2271+
Mat orgPointsMat;
2272+
transform(centers, orgPointsMat, H.inv());
2273+
convertPointsFromHomogeneous(orgPointsMat, centers);
22792274
}
22802275
Mat(centers).copyTo(_centers);
2281-
return false;
2276+
return isValid;
22822277
}
22832278

22842279
bool findCirclesGrid(InputArray _image, Size patternSize,

modules/calib3d/src/circlesgrid.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ size_t CirclesGridFinder::getFirstCorner(std::vector<Point> &largeCornerIndices,
16141614
int cornerIdx = 0;
16151615
bool waitOutsider = true;
16161616

1617-
for(;;)
1617+
for (size_t i = 0; i < cornersCount * 2; ++i)
16181618
{
16191619
if (waitOutsider)
16201620
{
@@ -1624,11 +1624,11 @@ size_t CirclesGridFinder::getFirstCorner(std::vector<Point> &largeCornerIndices,
16241624
else
16251625
{
16261626
if (isInsider[(cornerIdx + 1) % cornersCount])
1627-
break;
1627+
return cornerIdx;
16281628
}
16291629

16301630
cornerIdx = (cornerIdx + 1) % cornersCount;
16311631
}
16321632

1633-
return cornerIdx;
1633+
CV_Error(Error::StsNoConv, "isInsider array has the same values");
16341634
}

0 commit comments

Comments
 (0)