Skip to content

Commit 624d532

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents c51f5e8 + 9b4adc9 commit 624d532

File tree

26 files changed

+420
-253
lines changed

26 files changed

+420
-253
lines changed

cmake/OpenCVDetectInferenceEngine.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ endif()
129129

130130
if(INF_ENGINE_TARGET)
131131
if(NOT INF_ENGINE_RELEASE)
132-
message(WARNING "InferenceEngine version has not been set, 2021.1 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
132+
message(WARNING "InferenceEngine version has not been set, 2021.2 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
133133
endif()
134-
set(INF_ENGINE_RELEASE "2021010000" CACHE STRING "Force IE version, should be in form YYYYAABBCC (e.g. 2020.1.0.2 -> 2020010002)")
134+
set(INF_ENGINE_RELEASE "2021020000" CACHE STRING "Force IE version, should be in form YYYYAABBCC (e.g. 2020.1.0.2 -> 2020010002)")
135135
set_target_properties(${INF_ENGINE_TARGET} PROPERTIES
136136
INTERFACE_COMPILE_DEFINITIONS "HAVE_INF_ENGINE=1;INF_ENGINE_RELEASE=${INF_ENGINE_RELEASE}"
137137
)

doc/js_tutorials/js_setup/js_usage/js_usage.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Using OpenCV.js {#tutorial_js_usage}
44
Steps
55
-----
66

7-
In this tutorial, you will learn how to include and start to use `opencv.js` inside a web page. You can get a copy of `opencv.js` from `opencv-{VERSION_NUMBER}-docs.zip` in each [release](https://github.com/opencv/opencv/releases), or simply download the prebuilt script from the online documentations at "https://docs.opencv.org/{VERISON_NUMBER}/opencv.js" (For example, [https://docs.opencv.org/3.4.0/opencv.js](https://docs.opencv.org/3.4.0/opencv.js). Use `master` if you want the latest build). You can also build your own copy by following the tutorial on Build Opencv.js.
7+
In this tutorial, you will learn how to include and start to use `opencv.js` inside a web page. You can get a copy of `opencv.js` from `opencv-{VERSION_NUMBER}-docs.zip` in each [release](https://github.com/opencv/opencv/releases), or simply download the prebuilt script from the online documentations at "https://docs.opencv.org/{VERSION_NUMBER}/opencv.js" (For example, [https://docs.opencv.org/3.4.0/opencv.js](https://docs.opencv.org/3.4.0/opencv.js). Use `master` if you want the latest build). You can also build your own copy by following the tutorial on Build Opencv.js.
88

99
### Create a web page
1010

modules/calib3d/include/opencv2/calib3d.hpp

Lines changed: 112 additions & 111 deletions
Large diffs are not rendered by default.

modules/calib3d/test/test_fisheye.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ TEST_F(fisheyeTest, EstimateUncertainties)
492492

493493
TEST_F(fisheyeTest, stereoRectify)
494494
{
495+
// For consistency purposes
496+
CV_StaticAssert(
497+
static_cast<int>(cv::CALIB_ZERO_DISPARITY) == static_cast<int>(cv::fisheye::CALIB_ZERO_DISPARITY),
498+
"For the purpose of continuity the following should be true: cv::CALIB_ZERO_DISPARITY == cv::fisheye::CALIB_ZERO_DISPARITY"
499+
);
500+
495501
const std::string folder =combine(datasets_repository_path, "calib-3_stereo_from_JY");
496502

497503
cv::Size calibration_size = this->imageSize, requested_size = calibration_size;
@@ -504,7 +510,7 @@ TEST_F(fisheyeTest, stereoRectify)
504510
double balance = 0.0, fov_scale = 1.1;
505511
cv::Mat R1, R2, P1, P2, Q;
506512
cv::fisheye::stereoRectify(K1, D1, K2, D2, calibration_size, theR, theT, R1, R2, P1, P2, Q,
507-
cv::CALIB_ZERO_DISPARITY, requested_size, balance, fov_scale);
513+
cv::fisheye::CALIB_ZERO_DISPARITY, requested_size, balance, fov_scale);
508514

509515
// Collected with these CMake flags: -DWITH_IPP=OFF -DCV_ENABLE_INTRINSICS=OFF -DCV_DISABLE_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Debug
510516
cv::Matx33d R1_ref(

modules/core/include/opencv2/core/ocl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,12 @@ class CV_EXPORTS PlatformInfo
626626

627627
String name() const;
628628
String vendor() const;
629+
630+
/// See CL_PLATFORM_VERSION
629631
String version() const;
632+
int versionMajor() const;
633+
int versionMinor() const;
634+
630635
int deviceNumber() const;
631636
void getDevice(Device& device, int d) const;
632637

modules/core/src/convert.dispatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static bool ocl_convertFp16( InputArray _src, OutputArray _dst, int sdepth, int
154154
sdepth == CV_32F ? "half" : "float",
155155
rowsPerWI,
156156
sdepth == CV_32F ? " -D FLOAT_TO_HALF " : "");
157-
ocl::Kernel k("convertFp16", ocl::core::halfconvert_oclsrc, build_opt);
157+
ocl::Kernel k(sdepth == CV_32F ? "convertFp16_FP32_to_FP16" : "convertFp16_FP16_to_FP32", ocl::core::halfconvert_oclsrc, build_opt);
158158
if (k.empty())
159159
return false;
160160

modules/core/src/ocl.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,25 +1499,27 @@ Platform& Platform::getDefault()
14991499

15001500
/////////////////////////////////////// Device ////////////////////////////////////////////
15011501

1502-
// deviceVersion has format
1502+
// Version has format:
15031503
// OpenCL<space><major_version.minor_version><space><vendor-specific information>
15041504
// by specification
15051505
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html
15061506
// http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clGetDeviceInfo.html
1507-
static void parseDeviceVersion(const String &deviceVersion, int &major, int &minor)
1507+
// https://www.khronos.org/registry/OpenCL/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html
1508+
// https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/clGetPlatformInfo.html
1509+
static void parseOpenCLVersion(const String &version, int &major, int &minor)
15081510
{
15091511
major = minor = 0;
1510-
if (10 >= deviceVersion.length())
1512+
if (10 >= version.length())
15111513
return;
1512-
const char *pstr = deviceVersion.c_str();
1514+
const char *pstr = version.c_str();
15131515
if (0 != strncmp(pstr, "OpenCL ", 7))
15141516
return;
1515-
size_t ppos = deviceVersion.find('.', 7);
1517+
size_t ppos = version.find('.', 7);
15161518
if (String::npos == ppos)
15171519
return;
1518-
String temp = deviceVersion.substr(7, ppos - 7);
1520+
String temp = version.substr(7, ppos - 7);
15191521
major = atoi(temp.c_str());
1520-
temp = deviceVersion.substr(ppos + 1);
1522+
temp = version.substr(ppos + 1);
15211523
minor = atoi(temp.c_str());
15221524
}
15231525

@@ -1555,7 +1557,7 @@ struct Device::Impl
15551557
addressBits_ = getProp<cl_uint, int>(CL_DEVICE_ADDRESS_BITS);
15561558

15571559
String deviceVersion_ = getStrProp(CL_DEVICE_VERSION);
1558-
parseDeviceVersion(deviceVersion_, deviceVersionMajor_, deviceVersionMinor_);
1560+
parseOpenCLVersion(deviceVersion_, deviceVersionMajor_, deviceVersionMinor_);
15591561

15601562
size_t pos = 0;
15611563
while (pos < extensions_.size())
@@ -3529,6 +3531,15 @@ bool Kernel::empty() const
35293531
return ptr() == 0;
35303532
}
35313533

3534+
static cv::String dumpValue(size_t sz, const void* p)
3535+
{
3536+
if (sz == 4)
3537+
return cv::format("%d / %uu / 0x%08x / %g", *(int*)p, *(int*)p, *(int*)p, *(float*)p);
3538+
if (sz == 8)
3539+
return cv::format("%lld / %lluu / 0x%16llx / %g", *(long long*)p, *(long long*)p, *(long long*)p, *(double*)p);
3540+
return cv::format("%p", p);
3541+
}
3542+
35323543
int Kernel::set(int i, const void* value, size_t sz)
35333544
{
35343545
if (!p || !p->handle)
@@ -3539,7 +3550,7 @@ int Kernel::set(int i, const void* value, size_t sz)
35393550
p->cleanupUMats();
35403551

35413552
cl_int retval = clSetKernelArg(p->handle, (cl_uint)i, sz, value);
3542-
CV_OCL_DBG_CHECK_RESULT(retval, cv::format("clSetKernelArg('%s', arg_index=%d, size=%d, value=%p)", p->name.c_str(), (int)i, (int)sz, (void*)value).c_str());
3553+
CV_OCL_DBG_CHECK_RESULT(retval, cv::format("clSetKernelArg('%s', arg_index=%d, size=%d, value=%s)", p->name.c_str(), (int)i, (int)sz, dumpValue(sz, value).c_str()).c_str());
35433554
if (retval != CL_SUCCESS)
35443555
return -1;
35453556
return i+1;
@@ -6566,6 +6577,9 @@ struct PlatformInfo::Impl
65666577
refcount = 1;
65676578
handle = *(cl_platform_id*)id;
65686579
getDevices(devices, handle);
6580+
6581+
version_ = getStrProp(CL_PLATFORM_VERSION);
6582+
parseOpenCLVersion(version_, versionMajor_, versionMinor_);
65696583
}
65706584

65716585
String getStrProp(cl_platform_info prop) const
@@ -6579,6 +6593,10 @@ struct PlatformInfo::Impl
65796593
IMPLEMENT_REFCOUNTABLE();
65806594
std::vector<cl_device_id> devices;
65816595
cl_platform_id handle;
6596+
6597+
String version_;
6598+
int versionMajor_;
6599+
int versionMinor_;
65826600
};
65836601

65846602
PlatformInfo::PlatformInfo()
@@ -6641,7 +6659,19 @@ String PlatformInfo::vendor() const
66416659

66426660
String PlatformInfo::version() const
66436661
{
6644-
return p ? p->getStrProp(CL_PLATFORM_VERSION) : String();
6662+
return p ? p->version_ : String();
6663+
}
6664+
6665+
int PlatformInfo::versionMajor() const
6666+
{
6667+
CV_Assert(p);
6668+
return p->versionMajor_;
6669+
}
6670+
6671+
int PlatformInfo::versionMinor() const
6672+
{
6673+
CV_Assert(p);
6674+
return p->versionMinor_;
66456675
}
66466676

66476677
static void getPlatforms(std::vector<cl_platform_id>& platforms)

modules/core/src/opencl/halfconvert.cl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,17 @@
4747
#endif
4848
#endif
4949

50-
__kernel void convertFp16(__global const uchar * srcptr, int src_step, int src_offset,
51-
__global uchar * dstptr, int dst_step, int dst_offset, int dst_rows, int dst_cols)
50+
__kernel void
51+
#ifdef FLOAT_TO_HALF
52+
convertFp16_FP32_to_FP16
53+
#else
54+
convertFp16_FP16_to_FP32
55+
#endif
56+
(
57+
__global const uchar * srcptr, int src_step, int src_offset,
58+
__global uchar * dstptr, int dst_step, int dst_offset,
59+
int dst_rows, int dst_cols
60+
)
5261
{
5362
int x = get_global_id(0);
5463
int y0 = get_global_id(1) * rowsPerWI;

modules/core/src/opengl.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,7 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala
15751575
// CL-GL Interoperability
15761576

15771577
#ifdef HAVE_OPENCL
1578+
# include "opencv2/core/opencl/runtime/opencl_core.hpp"
15781579
# include "opencv2/core/opencl/runtime/opencl_gl.hpp"
15791580
# ifdef cl_khr_gl_sharing
15801581
# define HAVE_OPENCL_OPENGL_SHARING
@@ -1595,6 +1596,34 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala
15951596

15961597
namespace cv { namespace ogl {
15971598

1599+
#if defined(HAVE_OPENCL) && defined(HAVE_OPENGL) && defined(HAVE_OPENCL_OPENGL_SHARING)
1600+
// Check to avoid crash in OpenCL runtime: https://github.com/opencv/opencv/issues/5209
1601+
static void checkOpenCLVersion()
1602+
{
1603+
using namespace cv::ocl;
1604+
const Device& device = Device::getDefault();
1605+
//CV_Assert(!device.empty());
1606+
cl_device_id dev = (cl_device_id)device.ptr();
1607+
CV_Assert(dev);
1608+
1609+
cl_platform_id platform_id = 0;
1610+
size_t sz = 0;
1611+
1612+
cl_int status = clGetDeviceInfo(dev, CL_DEVICE_PLATFORM, sizeof(platform_id), &platform_id, &sz);
1613+
CV_Assert(status == CL_SUCCESS && sz == sizeof(cl_platform_id));
1614+
CV_Assert(platform_id);
1615+
1616+
PlatformInfo pi(&platform_id);
1617+
int versionMajor = pi.versionMajor();
1618+
int versionMinor = pi.versionMinor();
1619+
if (versionMajor < 1 || (versionMajor == 1 && versionMinor <= 1))
1620+
CV_Error_(cv::Error::OpenCLApiCallError,
1621+
("OpenCL: clCreateFromGLTexture requires OpenCL 1.2+ version: %d.%d - %s (%s)",
1622+
versionMajor, versionMinor, pi.name().c_str(), pi.version().c_str())
1623+
);
1624+
}
1625+
#endif
1626+
15981627
namespace ocl {
15991628

16001629
Context& initializeContextFromGL()
@@ -1719,6 +1748,8 @@ void convertToGLTexture2D(InputArray src, Texture2D& texture)
17191748
Context& ctx = Context::getDefault();
17201749
cl_context context = (cl_context)ctx.ptr();
17211750

1751+
checkOpenCLVersion(); // clCreateFromGLTexture requires OpenCL 1.2
1752+
17221753
UMat u = src.getUMat();
17231754

17241755
// TODO Add support for roi
@@ -1777,6 +1808,8 @@ void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst)
17771808
Context& ctx = Context::getDefault();
17781809
cl_context context = (cl_context)ctx.ptr();
17791810

1811+
checkOpenCLVersion(); // clCreateFromGLTexture requires OpenCL 1.2
1812+
17801813
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!
17811814
dst.create(texture.size(), textureType);
17821815
UMat u = dst.getUMat();

modules/core/test/test_misc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ TEST(Core_OutputArrayCreate, _13772)
189189
TEST(Core_String, find_last_of__with__empty_string)
190190
{
191191
cv::String s;
192-
size_t p = s.find_last_of("q", 0);
192+
size_t p = s.find_last_of('q', 0);
193193
// npos is not exported: EXPECT_EQ(cv::String::npos, p);
194194
EXPECT_EQ(std::string::npos, p);
195195
}

0 commit comments

Comments
 (0)