diff --git a/modules/calib3d/include/opencv2/calib3d.hpp b/modules/calib3d/include/opencv2/calib3d.hpp index f0b8beb0d4..cc5fdbfe1c 100644 --- a/modules/calib3d/include/opencv2/calib3d.hpp +++ b/modules/calib3d/include/opencv2/calib3d.hpp @@ -2607,7 +2607,7 @@ final fundamental matrix. It can be set to something like 1-3, depending on the point localization, image resolution, and the image noise. @param confidence Parameter used for the RANSAC and LMedS methods only. It specifies a desirable level of confidence (probability) that the estimated matrix is correct. -@param mask +@param[out] mask optional output mask @param maxIters The maximum number of robust method iterations. The epipolar geometry is described by the following equation: diff --git a/modules/core/include/opencv2/core/eigen.hpp b/modules/core/include/opencv2/core/eigen.hpp index 3f4be931e6..51f41474bd 100644 --- a/modules/core/include/opencv2/core/eigen.hpp +++ b/modules/core/include/opencv2/core/eigen.hpp @@ -58,11 +58,13 @@ #pragma warning( disable: 4244 ) //conversion from '__int64' to 'int', possible loss of data #endif +#if !defined(OPENCV_DISABLE_EIGEN_TENSOR_SUPPORT) #if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 \ && defined(CV_CXX11) && defined(CV_CXX_STD_ARRAY) #include -#define OPENCV_EIGEN_TENSOR_SUPPORT -#endif // EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 +#define OPENCV_EIGEN_TENSOR_SUPPORT 1 +#endif // EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 +#endif // !defined(OPENCV_DISABLE_EIGEN_TENSOR_SUPPORT) namespace cv { diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 6824bb5a41..59544f8458 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -237,12 +237,19 @@ void setSize( Mat& m, int _dims, const int* _sz, const size_t* _steps, bool auto if( _steps ) { - if (_steps[i] % esz1 != 0) + if (i < _dims-1) { - CV_Error(Error::BadStep, "Step must be a multiple of esz1"); - } + if (_steps[i] % esz1 != 0) + { + CV_Error_(Error::BadStep, ("Step %zu for dimension %d must be a multiple of esz1 %zu", _steps[i], i, esz1)); + } - m.step.p[i] = i < _dims-1 ? _steps[i] : esz; + m.step.p[i] = _steps[i]; + } + else + { + m.step.p[i] = esz; + } } else if( autoSteps ) { diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index 09ee3bb6de..b4043b0b63 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -54,7 +54,8 @@ #endif #if defined __linux__ || defined __APPLE__ || defined __GLIBC__ \ - || defined __HAIKU__ || defined __EMSCRIPTEN__ || defined __FreeBSD__ + || defined __HAIKU__ || defined __EMSCRIPTEN__ || defined __FreeBSD__ \ + || defined __OpenBSD__ #include #include #include diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 6c7118f577..578f693dbf 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -2175,4 +2175,32 @@ TEST(Mat, empty_iterator_16855) EXPECT_TRUE(m.begin() == m.end()); } + +TEST(Mat, regression_18473) +{ + std::vector sizes(3); + sizes[0] = 20; + sizes[1] = 50; + sizes[2] = 100; +#if 1 // with the fix + std::vector steps(2); + steps[0] = 50*100*2; + steps[1] = 100*2; +#else // without the fix + std::vector steps(3); + steps[0] = 50*100*2; + steps[1] = 100*2; + steps[2] = 2; +#endif + std::vector data(20*50*100, 0); // 1Mb + data[data.size() - 1] = 5; + + // param steps Array of ndims-1 steps + Mat m(sizes, CV_16SC1, (void*)data.data(), (const size_t*)steps.data()); + + ASSERT_FALSE(m.empty()); + EXPECT_EQ((int)5, (int)m.at(19, 49, 99)); +} + + }} // namespace diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index 1419c05517..f39305eef4 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -3934,11 +3934,16 @@ void Net::connect(String _outPin, String _inPin) Mat Net::forward(const String& outputName) { CV_TRACE_FUNCTION(); + CV_Assert(!empty()); String layerName = outputName; if (layerName.empty()) - layerName = getLayerNames().back(); + { + std::vector layerNames = getLayerNames(); + CV_Assert(!layerNames.empty()); + layerName = layerNames.back(); + } std::vector pins(1, impl->getPinByAlias(layerName)); impl->setUpNet(pins); @@ -3950,11 +3955,17 @@ Mat Net::forward(const String& outputName) AsyncArray Net::forwardAsync(const String& outputName) { CV_TRACE_FUNCTION(); + CV_Assert(!empty()); + #ifdef CV_CXX11 String layerName = outputName; if (layerName.empty()) - layerName = getLayerNames().back(); + { + std::vector layerNames = getLayerNames(); + CV_Assert(!layerNames.empty()); + layerName = layerNames.back(); + } std::vector pins(1, impl->getPinByAlias(layerName)); impl->setUpNet(pins); @@ -3975,11 +3986,16 @@ AsyncArray Net::forwardAsync(const String& outputName) void Net::forward(OutputArrayOfArrays outputBlobs, const String& outputName) { CV_TRACE_FUNCTION(); + CV_Assert(!empty()); String layerName = outputName; if (layerName.empty()) - layerName = getLayerNames().back(); + { + std::vector layerNames = getLayerNames(); + CV_Assert(!layerNames.empty()); + layerName = layerNames.back(); + } std::vector pins(1, impl->getPinByAlias(layerName)); impl->setUpNet(pins); @@ -4571,6 +4587,8 @@ std::vector > Net::getLayerInputs(LayerId layerId) std::vector Net::getLayerNames() const { + CV_TRACE_FUNCTION(); + std::vector res; res.reserve(impl->layers.size()); diff --git a/modules/dnn/test/test_misc.cpp b/modules/dnn/test/test_misc.cpp index b803f782d0..91b008675b 100644 --- a/modules/dnn/test/test_misc.cpp +++ b/modules/dnn/test/test_misc.cpp @@ -99,6 +99,15 @@ TEST(readNet, do_not_call_setInput) // https://github.com/opencv/opencv/issues/ EXPECT_TRUE(res.empty()) << res.size; } +TEST(Net, empty_forward_18392) +{ + cv::dnn::Net net; + Mat image(Size(512, 512), CV_8UC3, Scalar::all(0)); + Mat inputBlob = cv::dnn::blobFromImage(image, 1.0, Size(512, 512), Scalar(0,0,0), true, false); + net.setInput(inputBlob); + EXPECT_ANY_THROW(Mat output = net.forward()); +} + #ifdef HAVE_INF_ENGINE static void test_readNet_IE_do_not_call_setInput(Backend backendId) diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index c9af7c2899..77ca57f48b 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -787,6 +787,7 @@ class JavaWrapperGenerator(object): inCode = True if "" in line: inCode = False + line = line.replace('@result ', '@return ') # @result is valid in Doxygen, but invalid in Javadoc if "@return " in line: returnTag = True diff --git a/modules/videoio/src/cap_dc1394_v2.cpp b/modules/videoio/src/cap_dc1394_v2.cpp index 9564958525..be36645420 100644 --- a/modules/videoio/src/cap_dc1394_v2.cpp +++ b/modules/videoio/src/cap_dc1394_v2.cpp @@ -207,60 +207,57 @@ bool CvCaptureCAM_DC1394_v2_CPP::startCapture() DC1394_ISO_SPEED_3200); } - // should a specific mode be used - if (userMode >= 0) + dc1394video_modes_t videoModes; + dc1394_video_get_supported_modes(dcCam, &videoModes); + // should a specific mode be used + while (userMode >= 0) // 'if' semantic, no real loop here { dc1394video_mode_t wantedMode; - dc1394video_modes_t videoModes; - dc1394_video_get_supported_modes(dcCam, &videoModes); - - //set mode from number, for example the second supported mode, i.e userMode = 1 if (userMode < (int)videoModes.num) { + // set mode from number, for example the second supported mode, i.e userMode = 1 wantedMode = videoModes.modes[userMode]; } - - //set modes directly from DC134 constants (from dc1394video_mode_t) - else if ((userMode >= DC1394_VIDEO_MODE_MIN) && (userMode <= DC1394_VIDEO_MODE_MAX )) + else if ((userMode >= DC1394_VIDEO_MODE_MIN) && (userMode <= DC1394_VIDEO_MODE_MAX)) { + // set modes directly from DC134 constants (from dc1394video_mode_t) + //search for wanted mode, to check if camera supports it int j = 0; - while ((j< (int)videoModes.num) && videoModes.modes[j]!=userMode) + while ((j < (int)videoModes.num) && videoModes.modes[j] != userMode) { j++; } - - if ((int)videoModes.modes[j]==userMode) - { - wantedMode = videoModes.modes[j]; - } - else + if (!(j < (int)videoModes.num)) { userMode = -1; // wanted mode not supported, search for best mode + break; } + + wantedMode = videoModes.modes[j]; } else { - userMode = -1; // wanted mode not supported, search for best mode + userMode = -1; // wanted mode not supported, search for best mode + break; } + //if userMode is available: set it and update size - if (userMode != -1) { code = dc1394_video_set_mode(dcCam, wantedMode); - uint32_t width, height; + uint32_t width = 0, height = 0; dc1394_get_image_size_from_video_mode(dcCam, wantedMode, &width, &height); frameWidth = (int)width; frameHeight = (int)height; } + break; } if (userMode == -1 && (frameWidth > 0 || frameHeight > 0)) { - dc1394video_mode_t bestMode = (dc1394video_mode_t) - 1; - dc1394video_modes_t videoModes; - dc1394_video_get_supported_modes(dcCam, &videoModes); + dc1394video_mode_t bestMode = (dc1394video_mode_t)(-1); for (i = 0; i < (int)videoModes.num; i++) { dc1394video_mode_t mode = videoModes.modes[i];